Skip to content

Commit 121c1fb

Browse files
authored
test(bridge): pin legacy shell-name normalization on the SSE path (#2524)
#2493 fixed the 502 that bridgeToResponsesSSE emitted when a routed model echoed exec_command instead of the declared exec, but tested it through the guard helper rather than the bridge path where the failure occurs. Four cases on the bridge itself: both legacy names normalize, a genuinely undeclared tool still fails the turn, and a catalog that declares exec_command itself is never rewritten. Verified load-bearing: 2 of the 4 fail against dev before #2493 landed.
1 parent 224f23d commit 121c1fb

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { bridgeToResponsesSSE } from "../src/bridge";
3+
import type { AdapterEvent } from "../src/types";
4+
5+
async function drain(stream: ReadableStream<Uint8Array>): Promise<string> {
6+
const reader = stream.getReader();
7+
const decoder = new TextDecoder();
8+
let out = "";
9+
for (;;) {
10+
const { done, value } = await reader.read();
11+
if (done) break;
12+
out += decoder.decode(value, { stream: true });
13+
}
14+
return out;
15+
}
16+
17+
async function* toolTurn(name: string): AsyncGenerator<AdapterEvent> {
18+
yield { type: "tool_call_start", id: "call-1", name } as AdapterEvent;
19+
yield { type: "tool_call_delta", id: "call-1", delta: '{"cmd":"ls"}' } as AdapterEvent;
20+
yield { type: "tool_call_end", id: "call-1" } as AdapterEvent;
21+
yield { type: "done" } as AdapterEvent;
22+
}
23+
24+
// #2493: Codex 0.149 declares the shell tool as `exec`, whose own description names the
25+
// nested `tools.exec_command(...)` helper. Routed models echo the helper name back, and the
26+
// undeclared-tool guard turned that into a 502 mid-turn. These pin the SSE path the guard
27+
// actually runs on, which the review flagged as untested.
28+
describe("bridge normalizes legacy shell names against the declared catalog (#2493)", () => {
29+
test("exec_command is delivered as the declared exec instead of failing the turn", async () => {
30+
const sse = await drain(bridgeToResponsesSSE(
31+
toolTurn("exec_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000,
32+
{ declaredToolNames: new Set(["exec"]) },
33+
));
34+
expect(sse).not.toContain("undeclared client tool");
35+
expect(sse).toContain('"name":"exec"');
36+
});
37+
38+
test("shell_command normalizes the same way", async () => {
39+
const sse = await drain(bridgeToResponsesSSE(
40+
toolTurn("shell_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000,
41+
{ declaredToolNames: new Set(["exec"]) },
42+
));
43+
expect(sse).not.toContain("undeclared client tool");
44+
expect(sse).toContain('"name":"exec"');
45+
});
46+
47+
test("a genuinely undeclared tool still fails the turn", async () => {
48+
const sse = await drain(bridgeToResponsesSSE(
49+
toolTurn("apply_patch"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000,
50+
{ declaredToolNames: new Set(["exec"]) },
51+
));
52+
expect(sse).toContain("undeclared client tool");
53+
});
54+
55+
test("a catalog that declares exec_command itself is never rewritten", async () => {
56+
const sse = await drain(bridgeToResponsesSSE(
57+
toolTurn("exec_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000,
58+
{ declaredToolNames: new Set(["exec", "exec_command"]) },
59+
));
60+
expect(sse).not.toContain("undeclared client tool");
61+
expect(sse).toContain('"name":"exec_command"');
62+
});
63+
});

0 commit comments

Comments
 (0)