Files
deepseek-harness/packages/host/plugin-inventory/tests/inventory.spec.ts
T
turtle1999 2abb542a22 Adapt current consumers to nontransactional Cordis Loader
Move exact user-patch watching into app boot and audit activation explicitly.
Wait for CLI fallback HMR and preset subtrees. Join the first fiber-disposal
result in the directory chooser and browser package runner. Keep async
update errors observable without restoring generic Loader rollback.

Restore the current workspace-link and Schemastery manifests and their gate.
Preserve unconditional patch-input cloning, awaited Include initialization,
and durable teardown writes. Update diagnostics, snapshots, bilingual docs,
and the exhaustive vendor divergence ledger.

Validation: focused Loader, watcher, preset, inventory, and cleanup tests;
100% watcher coverage; 32 Web preset cases; real CLI webhook model session;
SDK smokes; 13 headless expected cases; 3 recorded-session replays; build,
typecheck, lint contracts, and all 34 doc-sync gates.

A full Node 24/Python 3.12 Vitest run had 21806 passes and two failures:
a baseline-reproduced experimental CSS import failure and a Python probe
timeout that passed alone. The default Node 26/Python 3.9 run additionally
exposed unsupported Python and FileHandle-GC host failures.
2026-09-09 17:33:32 +08:00

127 lines
4.2 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest'
import { Context, FiberState, type Plugin } from '@deepseek-ai/cordis'
import Loader from '@deepseek-ai/cordis-plugin-loader'
import { remoteMethods } from '@deepseek-ai/dsh-typert-protocol'
import type { AgentPresets } from '@deepseek-ai/dsh-agent-presets'
import PluginInventoryGateway 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
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' } },
])
})
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 = await inventory.list()
// No agent-preset roster is composed, so the snapshot carries no presets.
expect(snapshot.agentPresets).toBeUndefined()
expect(snapshot.entries).toHaveLength(3)
expect(snapshot.entries).toEqual(expect.arrayContaining([
{
entryId: activeId,
moduleName: 'cordis:active',
enabled: true,
fiberPhase: 'active',
},
{
entryId: pendingId,
moduleName: 'cordis:pending',
enabled: true,
fiberPhase: 'pending',
},
{
entryId: disabledId,
moduleName: 'cordis:not-installed',
enabled: false,
fiberPhase: null,
},
]))
await ctx.loader.update(activeId, { disabled: true })
expect((await inventory.list()).entries.find(entry => entry.entryId === activeId)).toEqual({
entryId: activeId,
moduleName: 'cordis:active',
enabled: false,
fiberPhase: null,
})
ctx.loader.remove(pendingId)
expect((await inventory.list()).entries.some(entry => entry.entryId === pendingId)).toBe(false)
})
it('carries each composed preset with root-fiber states mapped to phases', async () => {
const { ctx, inventory } = await harness()
ctx.provide('agentPresets', {
compositionInventory: async () => [
{
id: 'standard',
trust: 'system',
name: '标准模式',
isDefault: true,
rows: [
{ entryId: 'alpha', moduleName: 'pkg-alpha', enabled: true, fiberState: FiberState.ACTIVE },
{ entryId: null, moduleName: 'pkg-file', enabled: 'conditional', condition: 'x' },
],
},
{ id: 'damaged', trust: 'user', isDefault: false, broken: 'the composition file is missing', rows: [] },
],
} as Partial<AgentPresets> as never)
const snapshot = await inventory.list()
expect(snapshot.agentPresets).toEqual([
{
id: 'standard',
trust: 'system',
name: '标准模式',
isDefault: true,
rows: [
{ entryId: 'alpha', moduleName: 'pkg-alpha', enabled: true, fiberPhase: 'active' },
{ entryId: null, moduleName: 'pkg-file', enabled: 'conditional', condition: 'x', fiberPhase: null },
],
},
{ id: 'damaged', trust: 'user', isDefault: false, broken: 'the composition file is missing', rows: [] },
])
})
})