test: cover non-thinking embedded replay tool results

This commit is contained in:
Shakker
2026-04-12 07:11:27 +01:00
committed by Shakker
parent 44afe200e6
commit b6faa69451

View File

@@ -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<FakeWrappedStream>;
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) => {