test: cover the dispatch-log seam's contained-failure and decline arms
CI's full-tree coverage flagged three untaken paths this PR introduced: - shapeDispatchLog's catch (a throwing tools/code-dispatch-log listener must be contained — the settle event logs the unshaped content); - the spill listener's flatten-decline arm (non-text sub-result content passes through unchanged); - the generated scope-key extractor row for tools/code-dispatch-log (registered in the scope invariant matrix like the other tools events).
This commit is contained in:
@@ -63,6 +63,7 @@ describe('scoped-dispatch invariants', () => {
|
|||||||
['approval/request', [{ agent, toolName: 'echo' }, () => Promise.resolve('unavailable')]],
|
['approval/request', [{ agent, toolName: 'echo' }, () => Promise.resolve('unavailable')]],
|
||||||
['goal/changed', [agent, { operation: 'create', ref: { id: 'goal-a', revision: 1 } }]],
|
['goal/changed', [agent, { operation: 'create', ref: { id: 'goal-a', revision: 1 } }]],
|
||||||
['system-prompt/assemble', [[], { scope: agent }]],
|
['system-prompt/assemble', [[], { scope: agent }]],
|
||||||
|
['tools/code-dispatch-log', [{ exec: { callId: 'c', name: 't', arguments: {} }, agent, subCallId: 'c:code:1', name: 't', isError: false, content: [] }, () => Promise.resolve([])]],
|
||||||
['tools/execute', [{ callId: 'c', name: 't', arguments: {}, agent }, () => Promise.resolve({ content: [], isError: false })]],
|
['tools/execute', [{ callId: 'c', name: 't', arguments: {}, agent }, () => Promise.resolve({ content: [], isError: false })]],
|
||||||
['tools/post-execute', [{ callId: 'c', name: 't', arguments: {}, agent }, { content: [], isError: false }, () => Promise.resolve({ kind: 'accept' })]],
|
['tools/post-execute', [{ callId: 'c', name: 't', arguments: {}, agent }, { content: [], isError: false }, () => Promise.resolve({ kind: 'accept' })]],
|
||||||
['tools/pre-execute', [{ callId: 'c', name: 't', arguments: {}, agent }, () => Promise.resolve({ kind: 'allow' })]],
|
['tools/pre-execute', [{ callId: 'c', name: 't', arguments: {}, agent }, () => Promise.resolve({ kind: 'allow' })]],
|
||||||
|
|||||||
@@ -694,6 +694,21 @@ describe('the run_code dispatch bridge', () => {
|
|||||||
expect(result.content[0]).toEqual({ type: 'text', text: 'caught: deliberate failure' })
|
expect(result.content[0]).toEqual({ type: 'text', text: 'caught: deliberate failure' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('a throwing tools/code-dispatch-log listener is contained: the unshaped content is logged', async () => {
|
||||||
|
const { ctx, runtime } = await setup({ mode: 'code' })
|
||||||
|
registerEcho(ctx)
|
||||||
|
ctx.on('tools/code-dispatch-log', () => { throw new Error('shaper exploded') })
|
||||||
|
const { agent, events } = fakeAgent()
|
||||||
|
runtime.behavior = async (request) => {
|
||||||
|
const value = await request.bindings[0]!.functions.echo!({ value: 'x' })
|
||||||
|
return { logs: [], value: value as string }
|
||||||
|
}
|
||||||
|
const result = await runCode(ctx, 'program', { agent })
|
||||||
|
expect(result.isError).toBe(false)
|
||||||
|
const settle = events.find(event => event.type === 'tool/code-dispatch')
|
||||||
|
expect(settle?.data).toMatchObject({ name: 'echo', isError: false, content: [{ type: 'text', text: 'echo:x' }] })
|
||||||
|
})
|
||||||
|
|
||||||
it('a throwing tools/pre-execute listener settles the sub-call without post-execute', async () => {
|
it('a throwing tools/pre-execute listener settles the sub-call without post-execute', async () => {
|
||||||
const { ctx, runtime } = await setup({ mode: 'code' })
|
const { ctx, runtime } = await setup({ mode: 'code' })
|
||||||
const calls = registerEcho(ctx)
|
const calls = registerEcho(ctx)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|||||||
import { SessionId } from '@deepseek-ai/dsh-session'
|
import { SessionId } from '@deepseek-ai/dsh-session'
|
||||||
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
||||||
import ToolRegistry, { defineContentToolFixture } from '@deepseek-ai/dsh-tools'
|
import ToolRegistry, { defineContentToolFixture } from '@deepseek-ai/dsh-tools'
|
||||||
|
import type { ToolDefinition } from '@deepseek-ai/dsh-tools'
|
||||||
import type { PostToolDecision, ToolExecution, ToolExecutionToken } from '@deepseek-ai/dsh-tools'
|
import type { PostToolDecision, ToolExecution, ToolExecutionToken } from '@deepseek-ai/dsh-tools'
|
||||||
import { SpillLocator, SpillStore } from '@deepseek-ai/dsh-spill'
|
import { SpillLocator, SpillStore } from '@deepseek-ai/dsh-spill'
|
||||||
import type { SaveTextSpill, SpillRef } from '@deepseek-ai/dsh-spill'
|
import type { SaveTextSpill, SpillRef } from '@deepseek-ai/dsh-spill'
|
||||||
@@ -232,7 +233,7 @@ describe('read skip', () => {
|
|||||||
|
|
||||||
describe('the durable dispatch-log arm', () => {
|
describe('the durable dispatch-log arm', () => {
|
||||||
/** Boot code mode + the policy + the worker runtime; run one program via the real bridge. */
|
/** Boot code mode + the policy + the worker runtime; run one program via the real bridge. */
|
||||||
async function runCodeWith(program: string, maxInlineBytes: number) {
|
async function runCodeWith(program: string, maxInlineBytes: number, extraTools: ToolDefinition[] = []) {
|
||||||
const ctx = new Context()
|
const ctx = new Context()
|
||||||
await ctx.plugin(SystemPrompt)
|
await ctx.plugin(SystemPrompt)
|
||||||
await ctx.plugin(ToolRegistry, { mode: 'code' })
|
await ctx.plugin(ToolRegistry, { mode: 'code' })
|
||||||
@@ -248,6 +249,7 @@ describe('the durable dispatch-log arm', () => {
|
|||||||
}
|
}
|
||||||
ctx.tools.register(textTool('huge_read', 'H'.repeat(2_000)))
|
ctx.tools.register(textTool('huge_read', 'H'.repeat(2_000)))
|
||||||
ctx.tools.register(textTool('small_read', 'tiny'))
|
ctx.tools.register(textTool('small_read', 'tiny'))
|
||||||
|
for (const tool of extraTools) ctx.tools.register(tool)
|
||||||
const result = await ctx.tools.execute({
|
const result = await ctx.tools.execute({
|
||||||
signal: testToolSignal,
|
signal: testToolSignal,
|
||||||
callId: CallId('parent-1'),
|
callId: CallId('parent-1'),
|
||||||
@@ -281,6 +283,21 @@ describe('the durable dispatch-log arm', () => {
|
|||||||
expect(save?.content).toBe('H'.repeat(2_000))
|
expect(save?.content).toBe('H'.repeat(2_000))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('leaves a non-text sub-result log unchanged (flatten declines)', async () => {
|
||||||
|
const { events, spill } = await runCodeWith(
|
||||||
|
'return await tools.mixed_read({})', 5, [defineContentToolFixture({
|
||||||
|
name: 'mixed_read',
|
||||||
|
description: 'mixed_read',
|
||||||
|
parameters: {},
|
||||||
|
async execute(): Promise<ContentBlock[]> {
|
||||||
|
return [{ type: 'text', text: 'x'.repeat(100) }, { type: 'reasoning', text: 'why' }]
|
||||||
|
},
|
||||||
|
})])
|
||||||
|
const settle = events.find(event => event.type === 'tool/code-dispatch')
|
||||||
|
expect((settle!.data as { content: unknown[] }).content).toHaveLength(2)
|
||||||
|
expect(spill.saves.filter(entry => entry.source.label === 'dispatch')).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
it('leaves a within-cap sub-result log untouched and saves nothing for it', async () => {
|
it('leaves a within-cap sub-result log untouched and saves nothing for it', async () => {
|
||||||
const { events, spill } = await runCodeWith(
|
const { events, spill } = await runCodeWith(
|
||||||
'return await tools.small_read({})', 200)
|
'return await tools.small_read({})', 200)
|
||||||
|
|||||||
Reference in New Issue
Block a user