Files
deepseek-harness/packages/subagent/tool-subagent/tests/scripted-provider.spec.ts
T
imccyu ec601ca13d build(vendor): rescope the vendored Cordis packages into @deepseek-ai
Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it
prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`,
`verify-translation-pairing --write` for the touched bilingual pairs,
`gen-doc-graphs`, and one typert snapshot whose ids embed character offsets.
`pnpm run rescope-vendor --check` verifies the result.

Renames nine vendored packages (cordis, cosmokit, schemastery and the six
@cordisjs plugins) and every reference that resolves them: manifest names and
dependency keys, module specifiers including declare-module merges, cordis.yml
plugin names, tsconfig paths, every Markdown fence, and `docs/` prose.
Directory names, upstream versions, and dependency ranges are unchanged, so
vendor/README.md still reads as an upstream snapshot; its manifest table gains
an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed
at each fork's origin.

The tutorial tier follows the rename end to end: its yaml fences named plugins
the Loader can no longer resolve, its `ts ignore-check` fences disagreed with
the compiled fences beside them, and its prose quoted both. The contracts that
told readers to keep upstream names — the root convention and the vendoring
cookbook's tree comment and manifest invariant — now say to rescope instead.

Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle
purity gate now names the vendored libraries a browser bundle inlines, and the
files where a bare `cordis` is an agent-preset id keep that product data.
2026-08-10 22:04:13 +08:00

99 lines
4.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { Context } from '@deepseek-ai/cordis'
import { type Agent } from '@deepseek-ai/dsh-agent'
import SubagentService, { type SubagentStartRequest } from '@deepseek-ai/dsh-subagent'
import { SessionId } from '@deepseek-ai/dsh-session'
import * as scripted from './scripted-provider.ts'
/** A minimal parent; the scripted provider only reads its id. */
function fakeParent(id = 'parent-1'): Agent {
return { id: SessionId(id) } as unknown as Agent
}
function baseRequest(over: Partial<SubagentStartRequest> = {}): SubagentStartRequest {
return {
prompt: [{ type: 'text', text: 'task' }],
parent: fakeParent(),
signal: new AbortController().signal,
...over,
}
}
async function mount(config: Partial<scripted.Config> = {}): Promise<Context> {
const ctx = new Context()
await ctx.plugin(SubagentService)
await scripted.mountScriptedProvider(ctx, { name: 'mock', ...config })
return ctx
}
describe('scripted subagent provider fixture', () => {
it('registers through the real service and returns the scripted reply', async () => {
const ctx = await mount({ reply: 'hello from fixture' })
expect(ctx.subagents.list()).toEqual(['mock'])
const run = await ctx.subagents.start('mock', baseRequest())
await expect(run.result).resolves.toEqual({
output: [{ type: 'text', text: 'hello from fixture' }],
structured: undefined,
stopReason: 'completed',
})
await run.dispose()
})
it('registers under a configurable name', async () => {
const ctx = await mount({ name: 'spawn' })
expect(ctx.subagents.list()).toEqual(['spawn'])
})
it('returns configured and default structured results', async () => {
const configured = await mount({ reply: 'r', structured: { answer: 42 } })
const schema = { type: 'object' as const, properties: { answer: { type: 'number' as const } } }
const configuredRun = await configured.subagents.start('mock', baseRequest({ outputSchema: schema }))
await expect(configuredRun.result).resolves.toMatchObject({ structured: { answer: 42 } })
const fallback = await mount({ reply: 'fallback reply' })
const fallbackRun = await fallback.subagents.start('mock', baseRequest({ outputSchema: schema }))
await expect(fallbackRun.result).resolves.toMatchObject({ structured: { reply: 'fallback reply' } })
})
it('omits structured output when no schema is requested', async () => {
const ctx = await mount({ capabilities: { outputSchema: false } })
const run = await ctx.subagents.start('mock', baseRequest())
expect(await run.result).not.toHaveProperty('structured')
})
it('honors configured and cancellation stop reasons', async () => {
const refused = await mount({ stopReason: 'refusal' })
const refusedRun = await refused.subagents.start('mock', baseRequest())
await expect(refusedRun.result).resolves.toMatchObject({ stopReason: 'refusal' })
const cancelled = await mount()
const controller = new AbortController()
const cancelledRun = await cancelled.subagents.start('mock', baseRequest({ signal: controller.signal }))
controller.abort()
await expect(cancelledRun.result).resolves.toMatchObject({ stopReason: 'aborted' })
})
it('rejects cancellation before or during asynchronous publication', async () => {
const ctx = await mount()
const alreadyAborted = new AbortController()
alreadyAborted.abort()
await expect(ctx.subagents.start('mock', baseRequest({ signal: alreadyAborted.signal })))
.rejects.toThrow('scripted subagent start aborted before publication')
const handoff = new AbortController()
const pending = ctx.subagents.start('mock', baseRequest({ signal: handoff.signal }))
handoff.abort()
await expect(pending).rejects.toThrow('scripted subagent start aborted before publication')
})
it('unregisters with its owning fixture fiber', async () => {
const ctx = new Context()
await ctx.plugin(SubagentService)
const fiber = await scripted.mountScriptedProvider(ctx, { name: 'mock' })
expect(ctx.subagents.list()).toEqual(['mock'])
await fiber.dispose()
expect(ctx.subagents.list()).toEqual([])
})
})