Skip to content

Commit 72b9f71

Browse files
vincentkocsteipete
authored andcommitted
fix(qa): keep Anthropic mock tool ids replay-stable
Punchcard-Session: frost-orchard-lantern-ze
1 parent 276e557 commit 72b9f71

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎extensions/qa-lab/src/providers/mock-openai/mock-anthropic-wire.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function adaptAnthropicToolCallIds(events: StreamEvent[]): StreamEvent[]
169169
if (existing) {
170170
return existing;
171171
}
172-
const adapted = `toolu_${createHash("sha256").update(id).digest("hex").slice(0, 48)}`;
172+
const adapted = `toolu${createHash("sha256").update(id).digest("hex").slice(0, 35)}`;
173173
adaptedIds.set(id, adapted);
174174
return adapted;
175175
};

‎extensions/qa-lab/src/providers/mock-openai/server.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6647,7 +6647,7 @@ Update and merge these partial structured summaries.`,
66476647
const toolUseBlock = body.content.find((block) => block.type === "tool_use") as
66486648
| { id: string; name: string; input: Record<string, unknown> }
66496649
| undefined;
6650-
expect(toolUseBlock?.id).toMatch(/^toolu_[A-Za-z0-9_]+$/);
6650+
expect(toolUseBlock?.id).toMatch(/^toolu[a-f0-9]{35}$/);
66516651
expect(toolUseBlock?.id.length).toBeLessThanOrEqual(64);
66526652
expect(toolUseBlock?.name).toBe("read");
66536653
expect(toolUseBlock?.input).toEqual({ path: "repo/docs/help/testing.md" });
@@ -6665,6 +6665,7 @@ Update and merge these partial structured summaries.`,
66656665
it("preserves already-native Anthropic tool IDs while adapting shared generated IDs", () => {
66666666
const nativeId = "toolu_native_123";
66676667
const generatedId = "call_mock_read_generated_1";
6668+
const secondGeneratedId = "call_mock_read_generated_2";
66686669
const events: StreamEvent[] = [
66696670
{
66706671
type: "response.output_item.added",
@@ -6690,6 +6691,7 @@ Update and merge these partial structured summaries.`,
66906691
output: [
66916692
{ type: "function_call", name: "read", call_id: nativeId, arguments: "{}" },
66926693
{ type: "function_call", name: "read", call_id: generatedId, arguments: "{}" },
6694+
{ type: "function_call", name: "read", call_id: secondGeneratedId, arguments: "{}" },
66936695
],
66946696
usage: { input_tokens: 1, output_tokens: 1, total_tokens: 2 },
66956697
},
@@ -6730,9 +6732,13 @@ Update and merge these partial structured summaries.`,
67306732
});
67316733

67326734
expect(callIds.filter((id) => id === nativeId)).toHaveLength(3);
6733-
expect(new Set(adaptedGeneratedIds).size).toBe(1);
6735+
expect(adaptedGeneratedIds.slice(0, 3)).toEqual(
6736+
Array.from({ length: 3 }, () => "toolu51ca7fb8ca8ab1910ae2815b4e69a38ac71"),
6737+
);
6738+
expect(adaptedGeneratedIds[3]).toMatch(/^toolu[a-f0-9]{35}$/);
6739+
expect(adaptedGeneratedIds[3]).not.toBe(adaptedGeneratedIds[0]);
67346740
expect(repeatedGeneratedIds).toEqual(adaptedGeneratedIds);
6735-
expect(adaptedGeneratedIds[0]).toMatch(/^toolu_[A-Za-z0-9_]+$/);
6741+
expect(adaptedGeneratedIds[0]).toMatch(/^toolu[a-f0-9]{35}$/);
67366742
expect(adaptedGeneratedIds[0]?.length).toBeLessThanOrEqual(64);
67376743
});
67386744

@@ -6790,7 +6796,7 @@ Update and merge these partial structured summaries.`,
67906796
if (!toolUse || typeof toolUse.id !== "string" || typeof toolUse.name !== "string") {
67916797
throw new Error("Expected Anthropic tool_use block");
67926798
}
6793-
expect(toolUse.id).toMatch(/^toolu_[A-Za-z0-9_]+$/);
6799+
expect(toolUse.id).toMatch(/^toolu[a-f0-9]{35}$/);
67946800
expect(toolUse.id.length).toBeLessThanOrEqual(64);
67956801
emittedToolUseIds.push(toolUse.id);
67966802
return toolUse;
@@ -7838,7 +7844,7 @@ Update and merge these partial structured summaries.`,
78387844
toolUseStart?.content_block,
78397845
"Anthropic SSE tool_use content block",
78407846
);
7841-
expect(toolUse.id).toMatch(/^toolu_[A-Za-z0-9_]+$/);
7847+
expect(toolUse.id).toMatch(/^toolu[a-f0-9]{35}$/);
78427848
expect(String(toolUse.id).length).toBeLessThanOrEqual(64);
78437849
const debug = requireRecord(await getJson(server, "/debug/last-request"), "debug request");
78447850
expect(debug.plannedToolCallId).toBe(toolUse.id);

0 commit comments

Comments
 (0)