From 6d0a7c12e12dcd160ec6a5d6e5be2a012a49ebea Mon Sep 17 00:00:00 2001 From: Chinesezjc Date: Tue, 11 Aug 2026 11:10:24 +0800 Subject: [PATCH] test(tools): add coverage for collapsed model-direct call under code mode Add two executor-level tests covering the previously uncovered branches in createExecution: - collapsed call (non-aborted signal) returns UNKNOWN_TOOL - collapsed call (pre-aborted signal) returns ABORTED_BEFORE_DISPATCH --- packages/core/tools/tests/code-mode.spec.ts | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/core/tools/tests/code-mode.spec.ts b/packages/core/tools/tests/code-mode.spec.ts index 596f3f630a..0b9eb16ef1 100644 --- a/packages/core/tools/tests/code-mode.spec.ts +++ b/packages/core/tools/tests/code-mode.spec.ts @@ -1561,6 +1561,40 @@ describe('the run_code dispatch bridge', () => { const assembly = await ctx.systemPrompt.assemble() expect(assembly.sections.some(section => section.name === 'tools:sdk')).toBe(false) }) + it('denies a model-direct native-tool call under code mode as UNKNOWN_TOOL', async () => { + const ctx = new Context() + await ctx.plugin(SystemPrompt, {}) + const registry = new ToolRegistry(ctx, { mode: 'code' }) + registerEcho(ctx, 'write') + const result = await registry.execute({ + signal: testToolSignal, + callId: CallId('call-1'), + name: 'write', + arguments: { text: 'hello' }, + }) + expect(result.isError).toBe(true) + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- error is a union type + expect((result.error as any).code).toBe('UNKNOWN_TOOL') + }) + + it('routes a pre-aborted collapsed call through ABORTED_BEFORE_DISPATCH', async () => { + const ctx = new Context() + await ctx.plugin(SystemPrompt, {}) + const registry = new ToolRegistry(ctx, { mode: 'code' }) + registerEcho(ctx, 'write') + const aborted = new AbortController() + aborted.abort() + const result = await registry.execute({ + signal: aborted.signal, + callId: CallId('call-1'), + name: 'write', + arguments: { text: 'hello' }, + }) + expect(result.isError).toBe(true) + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- error is a union type + expect((result.error as any).code).toBe(TOOL_ABORTED_BEFORE_DISPATCH) + }) + }) /**