a8ec40ad34
The plugin-list tab rendered one flat list of every Loader entry — no separate "system plugins" section — with each card showing its real enabled state and an enable/disable button (a required plugin shows only a read-only note). The enable/disable guard flipped from default-protect to default-open: only the small REQUIRED_PLUGINS core (entry tree, Remote RPC spine, session/agent spines) is protected from being disabled, so the shipped plugins are actually toggleable. Tests, host READMEs, and the enable-disable agent note track the new grouping and guard. Co-Authored-By: Claude <noreply@anthropic.com>
121 lines
4.2 KiB
TypeScript
121 lines
4.2 KiB
TypeScript
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, { type PluginEntryId } from '../src/index.ts'
|
|
|
|
const contexts: Context[] = []
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(contexts.splice(0).map(ctx => ctx.fiber.dispose()))
|
|
})
|
|
|
|
const activePlugin: Plugin.Function = () => {}
|
|
const pendingPlugin: Plugin.Object = {
|
|
inject: ['neverReady'],
|
|
apply() {},
|
|
}
|
|
|
|
async function harness(): Promise<{
|
|
ctx: Context
|
|
inventory: PluginInventoryGateway
|
|
}> {
|
|
const ctx = new Context()
|
|
contexts.push(ctx)
|
|
await ctx.plugin(Loader)
|
|
ctx.loader.builtins.active = activePlugin
|
|
ctx.loader.builtins.pending = pendingPlugin
|
|
// `cordis:` builtins the toggle tests create; they resolve without a package install.
|
|
ctx.loader.builtins['user-toggleable'] = activePlugin
|
|
ctx.loader.builtins['required'] = activePlugin
|
|
await ctx.plugin(PluginInventoryGateway)
|
|
const inventory = ctx.get('pluginInventory') as PluginInventoryGateway
|
|
return { ctx, inventory }
|
|
}
|
|
|
|
describe('PluginInventoryGateway', () => {
|
|
it('publishes one direct list method under the pluginInventory namespace', async () => {
|
|
const { inventory } = await harness()
|
|
expect(inventory.typertRemote).toMatchObject({
|
|
serviceKey: 'pluginInventory',
|
|
namespace: 'pluginInventory',
|
|
})
|
|
expect(remoteMethods(inventory)).toEqual([
|
|
{ method: 'list', invocation: { kind: 'direct' } },
|
|
{ method: 'setEnabled', invocation: { kind: 'direct' } },
|
|
])
|
|
})
|
|
|
|
it('setEnabled toggles a user-toggleable Loader entry live', async () => {
|
|
const { ctx, inventory } = await harness()
|
|
const id = await ctx.loader.create({ name: 'cordis:user-toggleable' }) as PluginEntryId
|
|
await inventory.setEnabled(id, false)
|
|
expect(inventory.list().entries.find(entry => entry.entryId === id)).toEqual({
|
|
entryId: id,
|
|
moduleName: 'cordis:user-toggleable',
|
|
enabled: false,
|
|
protected: false,
|
|
fiberPhase: null,
|
|
})
|
|
await inventory.setEnabled(id, true)
|
|
expect(inventory.list().entries.find(entry => entry.entryId === id)?.enabled).toBe(true)
|
|
})
|
|
|
|
it('setEnabled refuses a required plugin', async () => {
|
|
const { ctx, inventory } = await harness()
|
|
const id = await ctx.loader.create({ name: 'cordis:required' }) as PluginEntryId
|
|
expect(inventory.list().entries.find(entry => entry.entryId === id)?.protected).toBe(true)
|
|
await expect(inventory.setEnabled(id, false)).rejects.toThrow(/required by the application/)
|
|
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' })
|
|
const pendingId = await ctx.loader.create({ name: 'cordis:pending' })
|
|
const disabledId = await ctx.loader.create({
|
|
name: 'cordis:not-installed',
|
|
disabled: true,
|
|
})
|
|
await ctx.loader.create({ name: 'cordis:active', group: true })
|
|
|
|
const snapshot = inventory.list()
|
|
expect(snapshot.entries).toHaveLength(3)
|
|
expect(snapshot.entries).toEqual(expect.arrayContaining([
|
|
{
|
|
entryId: activeId,
|
|
moduleName: 'cordis:active',
|
|
enabled: true,
|
|
protected: false,
|
|
fiberPhase: 'active',
|
|
},
|
|
{
|
|
entryId: pendingId,
|
|
moduleName: 'cordis:pending',
|
|
enabled: true,
|
|
protected: false,
|
|
fiberPhase: 'pending',
|
|
},
|
|
{
|
|
entryId: disabledId,
|
|
moduleName: 'cordis:not-installed',
|
|
enabled: false,
|
|
protected: false,
|
|
fiberPhase: null,
|
|
},
|
|
]))
|
|
|
|
await ctx.loader.update(activeId, { disabled: true })
|
|
expect(inventory.list().entries.find(entry => entry.entryId === activeId)).toEqual({
|
|
entryId: activeId,
|
|
moduleName: 'cordis:active',
|
|
enabled: false,
|
|
protected: false,
|
|
fiberPhase: null,
|
|
})
|
|
|
|
await ctx.loader.remove(pendingId)
|
|
expect(inventory.list().entries.some(entry => entry.entryId === pendingId)).toBe(false)
|
|
})
|
|
})
|