From c5dff80c94bf2ce47aec3516bf95e4cc42b78753 Mon Sep 17 00:00:00 2001 From: creatixchu Date: Thu, 24 Sep 2026 22:47:59 +0800 Subject: [PATCH] test(ptc): give tool bridge fixtures owned agent contexts --- packages/core/tools/tests/ptc.spec.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/tools/tests/ptc.spec.ts b/packages/core/tools/tests/ptc.spec.ts index 479740cbea..8dfe2c79a0 100644 --- a/packages/core/tools/tests/ptc.spec.ts +++ b/packages/core/tools/tests/ptc.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from 'vitest' +import { describe, expect, it, onTestFinished, vi } from 'vitest' import { Context } from '@deepseek-ai/cordis' import { createUserMessage, ToolCallId } from '@deepseek-ai/dsh-llm' import type { ContextFormed } from '@deepseek-ai/dsh-llm' @@ -76,7 +76,7 @@ async function setup(options: SetupOptions = {}) { /** Mint an agent scope configured like production that can register scoped tool policy. */ async function mintAgentScope(ctx: Context, name = 'scoped'): Promise<{ scope: Scope; agent: Agent }> { - const agent = { id: SessionId(name), session: { header: {}, append: () => {} } } as unknown as Agent + const agent = { ctx, id: SessionId(name), session: { header: {}, append: () => {} } } as unknown as Agent let scope!: Scope await ctx.plugin(Object.assign((inner: Context) => { scope = createScope(inner, agent) }, { inject: ['tools', 'systemPrompt'] })) @@ -105,7 +105,10 @@ function registerEcho(ctx: Context, name = 'echo'): unknown[] { /** A structural fake of the owning agent: captures session appends. */ function fakeAgent(): { agent: Agent; events: { type: string; data: unknown }[] } { const events: { type: string; data: unknown }[] = [] + const ctx = new Context() + onTestFinished(async () => { await ctx.fiber.dispose() }) const agent = { + ctx, session: { header: { cwd: '/workspace' }, append: (type: string, data: unknown) => { events.push({ type, data }) }, @@ -1727,7 +1730,7 @@ describe('the run_code dispatch bridge', () => { }, })) const session = Session.create(SessionId('deep-code-arguments')) - const agent = { session } as Agent + const agent = { ctx, session } as Agent runtime.behavior = async (request) => { let nested: JsonValue = 'leaf' for (let index = 0; index < depth; index++) nested = [nested] @@ -2202,7 +2205,7 @@ describe('per-program execution controls', () => { }) const session = Session.create(SessionId('program-controls')) session.append('turn/start', { turn: 1 }) - const agent = { session } as unknown as Agent + const agent = { ctx: state.ctx, session } as unknown as Agent const execute = (args: Record, signal = testToolSignal) => state.tools.execute({ callId: ToolCallId('program-controls'), name: RUN_CODE_NAME, arguments: { code: 'program', description: 'Test execution controls', ...args }, agent, signal,