P1 review finding: extractMeta timed only the literal's vm evaluation;
materializing the RESULT then read properties ordinarily on the HOST
stack, so a meta literal smuggling a getter (get name() { while(true){} })
could wedge the host outside any timeout — defeating the exact spin
isolation the worker thread exists for.
Rather than harden the evaluator (descriptor walks, AST validation),
delete the mechanism: the workflow's identity now reaches the seam as a
plain JSON field (WorkflowStartRequest.meta), carried by the tool as a
schema-validated `meta` object parameter the model fills directly. The
engine only shape-validates data (validateMeta, every violation named)
and pre-parses the body; the scanner, the vm evaluation, and the
host-side materialization are gone, and with them the hole. A body
still opening with a Claude Code-style `export const meta` statement
gets a pointed SCRIPT_PARSE message (the likeliest authoring slip; a
CC script's body stays drop-in, only its meta header moves into the
parameter). syncTimeoutMs now governs exactly one thing: the initial
synchronous slice inside the worker.
The RFC's decision section is rewritten in place (implemented-RFC
rule); the embedded-meta format moves to alternatives-considered with
the hole as the reason. Tool description, presentation (title now reads
meta.name directly — the textual sniff is gone), seam vocabulary docs,
and catalogs follow.
92 lines
4.0 KiB
TypeScript
92 lines
4.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { Context } from 'cordis'
|
|
import LlmService from '@deepseek-ai/dsh-llm'
|
|
import SessionStore from '@deepseek-ai/dsh-session'
|
|
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
import ToolRegistry from '@deepseek-ai/dsh-tools'
|
|
import AgentRegistry, { AgentId } from '@deepseek-ai/dsh-agent'
|
|
import AgentLoop from '@deepseek-ai/dsh-agent-loop'
|
|
import * as Invariants from '@deepseek-ai/dsh-invariants'
|
|
import SubagentService from '@deepseek-ai/dsh-subagent'
|
|
import * as spawn from '@deepseek-ai/dsh-subagent-spawn'
|
|
import { STRUCTURED_OUTPUT_TOOL } from '@deepseek-ai/dsh-subagent-inprocess'
|
|
import { MockAdapter, textResponse, toolCallResponse } from '../../../core/agent-loop/tests/mock-adapter.ts'
|
|
import WorkerWorkflowEngine from '../src/index.ts'
|
|
|
|
type Script = ConstructorParameters<typeof MockAdapter>[0]
|
|
|
|
/**
|
|
* The whole in-process stack, keyless, with the script in a REAL worker
|
|
* thread: the engine drives the REAL spawn backend (with its
|
|
* structured runtime) on a real agent loop; the scripted mock MODEL is the
|
|
* only mocked boundary. This is the guard the unit suites structurally
|
|
* cannot give — the MessageChannel suite fakes the host, and the host suite
|
|
* stubs the subagent seam.
|
|
*/
|
|
async function setup(script: Script) {
|
|
const ctx = new Context()
|
|
const adapter = new MockAdapter(script)
|
|
await ctx.plugin(LlmService)
|
|
await ctx.plugin(SessionStore)
|
|
await ctx.plugin(SystemPrompt)
|
|
await ctx.plugin(ToolRegistry)
|
|
await ctx.plugin(AgentRegistry)
|
|
await ctx.plugin(Invariants)
|
|
await ctx.plugin(AgentLoop, { agents: [] })
|
|
await ctx.plugin(SubagentService)
|
|
await ctx.plugin(spawn, { providerName: 'spawn' })
|
|
await ctx.plugin(WorkerWorkflowEngine, {})
|
|
ctx.llm.registerAdapter(['mock'], adapter)
|
|
const parent = ctx.agentLoop.create(AgentId('parent'), { model: 'mock' })
|
|
return { ctx, parent, adapter }
|
|
}
|
|
|
|
describe('dsh-workflow-workerthread over the real in-process stack', () => {
|
|
it('runs a two-stage workflow: a plain child, then a schema child through the structured runtime', async () => {
|
|
const { ctx, parent } = await setup([
|
|
textResponse('the file list is a.ts'),
|
|
toolCallResponse('c1', STRUCTURED_OUTPUT_TOOL, { verdict: 'real', confidence: 0.9 }),
|
|
])
|
|
const childIds: string[] = []
|
|
ctx.on('workflow/agent-start', (_info, agent) => { childIds.push(agent.childId) })
|
|
const run = ctx.workflows.start({
|
|
meta: { name: 'integration', description: 'plain + structured children' },
|
|
script: `phase('Read')
|
|
const prose = await agent('read the repo')
|
|
phase('Judge')
|
|
const judged = await agent('judge: ' + prose, {
|
|
schema: { type: 'object', properties: { verdict: { type: 'string', enum: ['real', 'bogus'] }, confidence: { type: 'number' } }, required: ['verdict'] },
|
|
})
|
|
return { prose, verdict: judged.verdict, confidence: judged.confidence }`,
|
|
parent,
|
|
})
|
|
const result = await run.result
|
|
expect(result.stopReason).toBe('completed')
|
|
expect(result.value).toEqual({ prose: 'the file list is a.ts', verdict: 'real', confidence: 0.9 })
|
|
expect(result.agentsStarted).toBe(2)
|
|
await run.dispose()
|
|
// Both children were disposed to quiescence — no live child agents remain.
|
|
expect(childIds.length).toBe(2)
|
|
for (const childId of childIds) {
|
|
expect(ctx.agents.get(AgentId(childId))).toBeUndefined()
|
|
}
|
|
})
|
|
|
|
it('a child that fails against its schema (nudges exhausted) reaches the script as null', async () => {
|
|
const { ctx, parent } = await setup([
|
|
textResponse('prose only'),
|
|
textResponse('still prose after the nudge'),
|
|
])
|
|
const run = ctx.workflows.start({
|
|
meta: { name: 'null-path', description: 'schema failure maps to null' },
|
|
script: `const judged = await agent('judge it', { schema: { type: 'object', properties: { v: { type: 'string' } } } })
|
|
return { got: judged === null ? 'null' : 'value' }`,
|
|
parent,
|
|
})
|
|
const result = await run.result
|
|
expect(result.stopReason).toBe('completed')
|
|
expect(result.value).toEqual({ got: 'null' })
|
|
await run.dispose()
|
|
})
|
|
})
|