From 1bfc66da33e5b2483c07726c2108bb89f9830c2f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 3 May 2026 16:34:42 +0100 Subject: [PATCH] test: avoid codex app-server factory race --- .../codex/src/app-server/run-attempt.test.ts | 37 ++++++++----------- .../codex/src/app-server/run-attempt.ts | 1 + 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/extensions/codex/src/app-server/run-attempt.test.ts b/extensions/codex/src/app-server/run-attempt.test.ts index 34aadb4d2ad..e8c5c1c1cd8 100644 --- a/extensions/codex/src/app-server/run-attempt.test.ts +++ b/extensions/codex/src/app-server/run-attempt.test.ts @@ -441,34 +441,27 @@ describe("runCodexAppServerAttempt", () => { }); it("forces the message dynamic tool for message-tool-only source replies", async () => { - const harness = createStartedThreadHarness(); - const params = createParams( - path.join(tempDir, "session.jsonl"), - path.join(tempDir, "workspace"), - ); + const workspaceDir = path.join(tempDir, "workspace"); + const params = createParams(path.join(tempDir, "session.jsonl"), workspaceDir); params.disableTools = false; params.config = { tools: { profile: "coding" } }; params.sourceReplyDeliveryMode = "message_tool_only"; params.messageProvider = "whatsapp"; - params.timeoutMs = 60_000; - const run = runCodexAppServerAttempt(params, { turnCompletionIdleTimeoutMs: 5 }); - await harness.waitForMethod("thread/start"); - await harness.waitForMethod("turn/start"); - - const startRequest = harness.requests.find((request) => request.method === "thread/start"); - const dynamicToolNames = ( - (startRequest?.params as { dynamicTools?: Array<{ name: string }> } | undefined) - ?.dynamicTools ?? [] - ).map((tool) => tool.name); - expect(dynamicToolNames).toContain("message"); - - await new Promise((resolve) => setImmediate(resolve)); - await harness.completeTurn({ threadId: "thread-1", turnId: "turn-1" }); - await expect(run).resolves.toMatchObject({ - timedOut: false, - aborted: false, + const dynamicTools = await __testing.buildDynamicTools({ + params, + resolvedWorkspace: workspaceDir, + effectiveWorkspace: workspaceDir, + sandboxSessionKey: params.sessionKey, + sandbox: undefined, + runAbortController: new AbortController(), + sessionAgentId: "main", + pluginConfig: {}, + onYieldDetected: () => undefined, }); + const dynamicToolNames = dynamicTools.map((tool) => tool.name); + + expect(dynamicToolNames).toContain("message"); }); it("returns a failed dynamic tool response when an app-server tool call exceeds the deadline", async () => { diff --git a/extensions/codex/src/app-server/run-attempt.ts b/extensions/codex/src/app-server/run-attempt.ts index bdb2a167487..6e737f437fc 100644 --- a/extensions/codex/src/app-server/run-attempt.ts +++ b/extensions/codex/src/app-server/run-attempt.ts @@ -1812,6 +1812,7 @@ export const __testing = { CODEX_TURN_TERMINAL_IDLE_TIMEOUT_MS, buildCodexNativeHookRelayId, applyCodexDynamicToolProfile, + buildDynamicTools, filterToolsForVisionInputs, handleDynamicToolCallWithTimeout, ...createCodexAppServerClientFactoryTestHooks((factory) => {