Repository navigation
fix(ida): retain selected endpoint on connection failures #7894
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
+314
−4
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
fix(ida): retain selected endpoint on connection failures
- Loading branch information
commit 080250d9bcc4f60fd1944f93e999d37420de9390
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
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
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,89 @@ | ||
| import { once } from "node:events"; | ||
| import { writeFile } from "node:fs/promises"; | ||
| import { createServer } from "node:http"; | ||
| import { expect } from "vitest"; | ||
|
|
||
| import { elf } from "../../../src/domain/binaryTarget.fixture.js"; | ||
| import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js"; | ||
| import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; | ||
| import { workspaceCliTest as test } from "../../support/cli/workspaceCliFixture.js"; | ||
|
|
||
| test("preserves the selected IDA endpoint on a real HTTP failure", async ({ | ||
| cli, | ||
| workspace, | ||
| }) => { | ||
| const server = createServer((_request, response) => { | ||
| response.writeHead(404, { "content-type": "text/plain" }); | ||
| response.end("fixture-ida-not-found"); | ||
| }); | ||
| server.listen(0, "127.0.0.1"); | ||
| await once(server, "listening"); | ||
| let closed = false; | ||
| try { | ||
| const address = server.address(); | ||
| if (address === null || typeof address === "string") | ||
| throw new Error("Missing loopback listener address"); | ||
| const endpoint = `HTTP://127.0.0.1:0${address.port}/mcp?cursor=kept`; | ||
| const target = workspace.path("target.elf"); | ||
| const registration = workspace.path("ida.json"); | ||
| await writeFile(target, elf(2, 1, 62)); | ||
| await writeFile( | ||
| registration, | ||
| JSON.stringify({ | ||
| url: endpoint, | ||
| headers: { Authorization: "Bearer fixture-secret" }, | ||
| }), | ||
| ); | ||
| const result = await cli.run({ | ||
| arguments: ["analyze", target, "--provider", "ida", "--json"], | ||
| environment: { REA_IDA_MCP_CONFIG: registration }, | ||
| }); | ||
| expect(result.exitCode, result.stderr).toBe(1); | ||
| expect(result.json).toMatchObject({ | ||
| code: "execution_failure", | ||
| details: { diagnostics: { endpoint } }, | ||
| }); | ||
| expect(JSON.stringify(result.json)).toContain("fixture-ida-not-found"); | ||
| expect(JSON.stringify(result.json)).not.toContain("fixture-secret"); | ||
| const { call } = await connectLocalToolsMcp({ | ||
| REA_IDA_MCP_CONFIG: registration, | ||
| }); | ||
| const opened = await call("open_binary", { | ||
| path: target, | ||
| provider_id: "ida", | ||
| }); | ||
| if (opened.isError) throw new Error(JSON.stringify(opened)); | ||
| const failure = parseMcpToolError(await call("list_procedures", {})); | ||
| expect(failure.error).toMatchObject({ | ||
| code: "execution_failure", | ||
| details: { diagnostics: { endpoint } }, | ||
| }); | ||
| expect(JSON.stringify(failure)).not.toContain("fixture-secret"); | ||
| server.closeAllConnections(); | ||
| await new Promise<void>((resolve, reject) => | ||
| server.close((error) => (error ? reject(error) : resolve())), | ||
| ); | ||
| closed = true; | ||
| const stopped = await cli.run({ | ||
| arguments: ["analyze", target, "--provider", "ida", "--json"], | ||
| environment: { REA_IDA_MCP_CONFIG: registration }, | ||
| }); | ||
| expect(stopped.exitCode, stopped.stderr).toBe(1); | ||
| expect(stopped.json).toMatchObject({ | ||
| code: "execution_failure", | ||
| details: { | ||
| diagnostics: { | ||
| endpoint, | ||
| reason: expect.stringContaining("fetch failed"), | ||
| }, | ||
| }, | ||
| }); | ||
| } finally { | ||
| if (!closed) { | ||
| server.closeAllConnections(); | ||
| await new Promise<void>((resolve, reject) => | ||
| server.close((error) => (error ? reject(error) : resolve())), | ||
| ); | ||
| } | ||
| } | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.