From b6faa6945123a41d4ef7daa0865b1087441ad343 Mon Sep 17 00:00:00 2001 From: Shakker Date: Sun, 12 Apr 2026 07:11:27 +0100 Subject: [PATCH] test: cover non-thinking embedded replay tool results --- .../pi-embedded-runner/run/attempt.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/agents/pi-embedded-runner/run/attempt.test.ts b/src/agents/pi-embedded-runner/run/attempt.test.ts index a1660f35e8c..cb758a260d6 100644 --- a/src/agents/pi-embedded-runner/run/attempt.test.ts +++ b/src/agents/pi-embedded-runner/run/attempt.test.ts @@ -1784,6 +1784,48 @@ describe("wrapStreamFnSanitizeMalformedToolCalls", () => { ]); }); + it("preserves embedded Anthropic user tool_result blocks for non-thinking turns even when immutable replay is enabled", async () => { + const messages = [ + { + role: "assistant", + content: [{ type: "toolUse", id: "call_1", name: "read", input: { path: "." } }], + }, + { + role: "user", + content: [ + { + type: "toolResult", + toolUseId: "call_1", + content: [{ type: "text", text: "kept result" }], + }, + { type: "text", text: "retry" }, + ], + }, + ]; + const baseFn = vi.fn((_model, _context) => + createFakeStream({ events: [], resultMessage: { role: "assistant", content: [] } }), + ); + + const wrapped = wrapStreamFnSanitizeMalformedToolCalls(baseFn as never, new Set(["read"]), { + validateGeminiTurns: false, + validateAnthropicTurns: true, + preserveSignatures: true, + dropThinkingBlocks: false, + }); + const stream = wrapped( + { api: "anthropic-messages" } as never, + { messages } as never, + {} as never, + ) as FakeWrappedStream | Promise; + await Promise.resolve(stream); + + expect(baseFn).toHaveBeenCalledTimes(1); + const seenContext = baseFn.mock.calls[0]?.[1] as { + messages: Array<{ role?: string; content?: unknown[] }>; + }; + expect(seenContext.messages).toEqual(messages); + }); + it.each(["toolCall", "functionCall"] as const)( "preserves matching Anthropic user tool_result blocks after %s replay turns", async (toolCallType) => {