Repository navigation
test(bridge): pin legacy shell-name normalization on the SSE path #2524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { bridgeToResponsesSSE } from "../src/bridge"; | ||
| import type { AdapterEvent } from "../src/types"; | ||
|
|
||
| async function drain(stream: ReadableStream<Uint8Array>): Promise<string> { | ||
| const reader = stream.getReader(); | ||
| const decoder = new TextDecoder(); | ||
| let out = ""; | ||
| for (;;) { | ||
| const { done, value } = await reader.read(); | ||
| if (done) break; | ||
| out += decoder.decode(value, { stream: true }); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| async function* toolTurn(name: string): AsyncGenerator<AdapterEvent> { | ||
| yield { type: "tool_call_start", id: "call-1", name } as AdapterEvent; | ||
| yield { type: "tool_call_delta", id: "call-1", delta: '{"cmd":"ls"}' } as AdapterEvent; | ||
| yield { type: "tool_call_end", id: "call-1" } as AdapterEvent; | ||
| yield { type: "done" } as AdapterEvent; | ||
| } | ||
|
|
||
| // #2493: Codex 0.149 declares the shell tool as `exec`, whose own description names the | ||
| // nested `tools.exec_command(...)` helper. Routed models echo the helper name back, and the | ||
| // undeclared-tool guard turned that into a 502 mid-turn. These pin the SSE path the guard | ||
| // actually runs on, which the review flagged as untested. | ||
| describe("bridge normalizes legacy shell names against the declared catalog (#2493)", () => { | ||
| test("exec_command is delivered as the declared exec instead of failing the turn", async () => { | ||
| const sse = await drain(bridgeToResponsesSSE( | ||
| toolTurn("exec_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000, | ||
| { declaredToolNames: new Set(["exec"]) }, | ||
| )); | ||
| expect(sse).not.toContain("undeclared client tool"); | ||
| expect(sse).toContain('"name":"exec"'); | ||
| }); | ||
|
|
||
| test("shell_command normalizes the same way", async () => { | ||
| const sse = await drain(bridgeToResponsesSSE( | ||
| toolTurn("shell_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000, | ||
| { declaredToolNames: new Set(["exec"]) }, | ||
| )); | ||
| expect(sse).not.toContain("undeclared client tool"); | ||
| expect(sse).toContain('"name":"exec"'); | ||
| }); | ||
|
|
||
| test("a genuinely undeclared tool still fails the turn", async () => { | ||
| const sse = await drain(bridgeToResponsesSSE( | ||
| toolTurn("apply_patch"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000, | ||
| { declaredToolNames: new Set(["exec"]) }, | ||
| )); | ||
| expect(sse).toContain("undeclared client tool"); | ||
| }); | ||
|
|
||
| test("a catalog that declares exec_command itself is never rewritten", async () => { | ||
| const sse = await drain(bridgeToResponsesSSE( | ||
| toolTurn("exec_command"), "deepseek-x", undefined, undefined, undefined, undefined, 50_000, | ||
| { declaredToolNames: new Set(["exec", "exec_command"]) }, | ||
| )); | ||
| expect(sse).not.toContain("undeclared client tool"); | ||
| expect(sse).toContain('"name":"exec_command"'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AdapterEventdefines this payload asarguments, notdelta; the forced cast hides that mismatch. For every accepted tool name,bridgeToResponsesSSEtherefore readsevent.argumentsasundefined,Buffer.byteLengththrows, and the bridge emitsresponse.failedafter already emitting the output item's normalized name. The current assertions consequently pass even though the simulated turn fails, so these tests do not provide the claimed SSE regression coverage. Use theargumentsfield without casts and assert that aresponse.completedframe—and noresponse.failedframe—is emitted.Useful? React with 👍 / 👎.