feat(plugin-inventory): add setEnabled Remote that toggles and persists a plugin

pluginInventory/setEnabled calls ctx.loader.update({disabled}) for a live
effect and writes an explicit disabled override into the profile's user
patch layer so the choice survives a restart. The patch row id is the bare
entry options.id, not the group-prefixed tree id.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Pine
2026-08-14 13:53:24 +08:00
parent 18457f57b9
commit 3e0eca752c
5 changed files with 127 additions and 1 deletions
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from 'vitest'
import { Context, type Plugin } from '@deepseek-ai/cordis'
import Loader from '@deepseek-ai/cordis-plugin-loader'
import { remoteMethods } from '@deepseek-ai/dsh-typert-protocol'
import PluginInventoryGateway from '../src/index.ts'
import PluginInventoryGateway, { type PluginEntryId } from '../src/index.ts'
const contexts: Context[] = []
@@ -39,9 +39,24 @@ describe('PluginInventoryGateway', () => {
})
expect(remoteMethods(inventory)).toEqual([
{ method: 'list', invocation: { kind: 'direct' } },
{ method: 'setEnabled', invocation: { kind: 'direct' } },
])
})
it('setEnabled toggles the Loader entry live', async () => {
const { ctx, inventory } = await harness()
const id = await ctx.loader.create({ name: 'cordis:active' }) as PluginEntryId
await inventory.setEnabled(id, false)
expect(inventory.list().entries.find(entry => entry.entryId === id)).toEqual({
entryId: id,
moduleName: 'cordis:active',
enabled: false,
fiberPhase: null,
})
await inventory.setEnabled(id, true)
expect(inventory.list().entries.find(entry => entry.entryId === id)?.enabled).toBe(true)
})
it('projects current non-group Loader entries without a second cache', async () => {
const { ctx, inventory } = await harness()
const activeId = await ctx.loader.create({ name: 'cordis:active' })
@@ -0,0 +1,38 @@
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { persistPluginDisabled } from '../src/persist.ts'
/** A scratch profile dir with a given starting patch. */
function profile(initial: string): string {
const dir = mkdtempSync(join(tmpdir(), 'dsh-plugin-persist-'))
writeFileSync(join(dir, 'cordis.patch.yml'), initial)
return dir
}
describe('persistPluginDisabled', () => {
it('appends a disabled override to an empty patch', () => {
const dir = profile('[]\n')
persistPluginDisabled(dir, 'image-recognition-http', true)
const text = readFileSync(join(dir, 'cordis.patch.yml'), 'utf8')
expect(text).toContain('image-recognition-http')
expect(text).toContain('disabled: true')
})
it('writes disabled: false to override a bundle-default disable', () => {
const dir = profile('- id: tool-web\n disabled: true\n')
persistPluginDisabled(dir, 'tool-web', false)
const text = readFileSync(join(dir, 'cordis.patch.yml'), 'utf8')
expect(text).toContain('tool-web')
expect(text).toContain('disabled: false')
})
it('replaces an existing override for the same row instead of duplicating', () => {
const dir = profile('- id: image-recognition-http\n disabled: true\n')
persistPluginDisabled(dir, 'image-recognition-http', false)
const text = readFileSync(join(dir, 'cordis.patch.yml'), 'utf8')
expect(text.match(/image-recognition-http/g)).toHaveLength(1)
expect(text).not.toContain('disabled: true')
})
})