test(ida): consolidate native result precedence checks (#12999)

This commit is contained in:
morluto authored and GitHub committed 2026-11-21 05:14:50 +00:00
1 parent 37467640cb
commit 8ce837662b
2 files changed
+26 -40

No files matched your search

+25 -8
View File
@@ -44,7 +44,10 @@ describe("upstream IDA tool result decoding", () => {
).toEqual({ evidence });
expect(
decodeIdaToolResult(
{ content: [{ type: "text", text: JSON.stringify({ evidence }) }] },
{
content: [{ type: "text", text: JSON.stringify({ evidence }) }],
structuredContent: { result: [], _output_truncated: true },
},
"native",
redact,
),
@@ -105,13 +108,11 @@ describe("upstream IDA tool result decoding", () => {
}),
).toEqual([{ address: "0x1000" }]);
});
it.each([
["truncated JSON", '{"code": "int main('],
["ordinary text", "int main(void);"],
])("rejects %s text", (_label, text) => {
expect(
() => decodeIdaToolResult({ content: [{ type: "text", text }] }),
"malformed JSON is never decoded as an ordinary string",
it("rejects truncated JSON text without a structured result", () => {
expect(() =>
decodeIdaToolResult({
content: [{ type: "text", text: '{"code": "int main(' }],
}),
).toThrow("IDA MCP returned malformed JSON text.");
});
it("preserves upstream failures and rejects truncated previews that still satisfy item schemas", () => {
@@ -795,6 +796,22 @@ it("keeps error, truncation and native-text precedence ahead of structured JSON
"native",
),
).toEqual({ complete: true });
const preview = {
content: [],
structuredContent: { result: [{ observed: true }] },
};
expect(() => decodeIdaToolResult(preview, "native")).toThrow(
"omitted its complete JSON text result",
);
expect(() =>
decodeIdaToolResult(
{
...preview,
content: [{ type: "text", text: "broken JSON" }],
},
"native",
),
).toThrow("returned malformed JSON text");
});
it("requires a valid content array even when IDA supplies structured evidence", () => {
+1 -32
View File
@@ -11,10 +11,7 @@ import {
AnalysisInputError,
AnalysisProtocolError,
} from "../domain/analysisErrorCore.js";
import {
decodeIdaToolResult,
type IdaMcpConnection,
} from "./IdaMcpConnection.js";
import type { IdaMcpConnection } from "./IdaMcpConnection.js";
import { parseConfig } from "../config/parseConfig.js";
import { UNCLASSIFIED_CALL_SITE_LIMITATION } from "./IdaCallGraph.js";
import { IdaProvider } from "./IdaProvider.js";
@@ -311,34 +308,6 @@ describe("IDA selected registration factories", () => {
});
});
describe("native IDA complete result decoding", () => {
it("uses complete native JSON text instead of a shortened structured preview", () => {
const complete = [
{
data: [{ addr: "0x1000", name: "main", size: "0x20" }],
next_offset: null,
},
];
const response = {
content: [{ type: "text", text: JSON.stringify(complete) }],
structuredContent: { result: [], _output_truncated: true },
};
expect(decodeIdaToolResult(response, "native")).toEqual(complete);
expect(() =>
decodeIdaToolResult({ ...response, content: [] }, "native"),
).toThrow("complete JSON");
expect(() =>
decodeIdaToolResult(
{ ...response, content: [{ type: "text", text: "broken JSON" }] },
"native",
),
).toThrow();
expect(() =>
decodeIdaToolResult({ ...response, isError: true }, "native"),
).toThrow("tool failed");
});
});
describe("native IDA provider observations", () => {
it.each([false, true])(
"keeps unknown callers in dossier coverage when callee truncation is %s",