diff --git a/src/ida/IdaMcpConnection.test.ts b/src/ida/IdaMcpConnection.test.ts index b2ac2d166d..ca5d155d28 100644 --- a/src/ida/IdaMcpConnection.test.ts +++ b/src/ida/IdaMcpConnection.test.ts @@ -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", () => { diff --git a/src/ida/IdaNativeProtocol.test.ts b/src/ida/IdaNativeProtocol.test.ts index 9f5983ef59..c85ae025a6 100644 --- a/src/ida/IdaNativeProtocol.test.ts +++ b/src/ida/IdaNativeProtocol.test.ts @@ -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",