fix(ida): report a procedure IDA cannot resolve as invalid input (#1785)

* test(ida): expect a missing procedure to be reported as invalid input

* test(ida): name the invalid_request code and its category for a missing procedure

* fix(ida): report a procedure IDA cannot resolve as invalid input

* test(ida): pin the missing-procedure issue shape and the lookups that stay unreadable

* fix(ida): treat a lookup answer for another query as a producer fault

* test(ida): expect an argument-independent issue path and pin legacy error replies and escaping

* fix(ida): report a missing procedure without naming an argument path

* test(ida): expect provider-derived selectors to stay producer faults in composed workflows

* fix(ida): keep provider-derived procedure selectors out of the caller's input errors

* test(ida): cover session forwarding, parameter hygiene and structured derived-node errors

* docs(ida): describe when procedure resolution blames the caller
This commit is contained in:
Mykola Dementiev
2026-10-11 22:52:16 +08:00
committed by GitHub
parent 554cb45f7f
commit d3e9ee5505
15 changed files with 753 additions and 21 deletions
@@ -0,0 +1,131 @@
import { rm } from "node:fs/promises";
import { afterEach, describe, expect, it } from "vitest";
import { EnhancedTools } from "../../../../src/application/EnhancedTools.js";
import { IdaSessionClient } from "../../../../src/ida/IdaSessionClient.js";
import type { JsonValue } from "../../../../src/domain/jsonValue.js";
import { createIdaTarget, RecordingIdaMcp } from "../../../fixtures/idaMcp.js";
const roots: string[] = [];
afterEach(async () => {
for (const root of roots.splice(0))
await rm(root, { recursive: true, force: true });
});
const entry = { addr: "0x1000", name: "main", size: "0x20" };
/** Headless session where `main` resolves, its external callee 0x2000 is not a function, and `nosuch` is unknown. */
const session = async () => {
const { root, target } = await createIdaTarget();
roots.push(root);
const producer = new RecordingIdaMcp(target, "headless");
producer.overrideCall = (name, args): JsonValue | undefined => {
if (name !== "lookup_funcs") return undefined;
const queries = args.queries;
const query = Array.isArray(queries) ? String(queries[0]) : "";
if (query === "main" || query === "0x1000")
return [{ query, fn: entry, error: null }];
return [
{
query,
fn: null,
error: query === "nosuch" ? "Not found" : "Not a function",
},
];
};
const client = new IdaSessionClient(
{
command: "fixture",
args: [],
env: {},
mode: "headless",
timeoutMs: 1000,
workspaceRoot: root,
},
target,
producer,
);
return { client, tools: new EnhancedTools(client) };
};
describe("provider-derived selectors in IDA composed workflows", () => {
it("records an external callee IDA cannot resolve as a producer fault in the call graph", async () => {
const { client, tools } = await session();
try {
const result = await tools.execute("get_call_graph", { address: "main" });
if (!result.ok) throw result.error;
expect(
result.value,
"the resolved root stays ok and only the derived node carries the producer fault",
).toMatchObject({
"0": [{ address: "0x1000", status: "ok" }],
"1": [
{
address: "0x2000",
status: "error",
error: { code: "unreadable_output" },
},
],
});
} finally {
expect((await client.close()).ok).toBe(true);
}
});
it("records the same node as a producer fault in the call path", async () => {
const { client, tools } = await session();
try {
const result = await tools.execute("trace_call_path", { start: "main" });
if (!result.ok) throw result.error;
expect(
result.value,
"the failure belongs to the derived address and is not blamed on the caller",
).toMatchObject({
failures: [{ address: "0x2000", error: { code: "unreadable_output" } }],
});
} finally {
expect((await client.close()).ok).toBe(true);
}
});
it("keeps the caller's own unknown selector an invalid request in each workflow", async () => {
const { client, tools } = await session();
try {
const graph = await tools.execute("get_call_graph", {
address: "nosuch",
});
const trace = await tools.execute("trace_call_path", { start: "nosuch" });
const batch = await tools.execute("batch_decompile", {
addresses: ["nosuch"],
});
if (graph.ok || trace.ok) throw new Error("expected invalid requests");
expect(graph.error._tag, "graph start is caller input").toBe(
"AnalysisInputError",
);
expect(trace.error._tag, "trace start is caller input").toBe(
"AnalysisInputError",
);
if (!batch.ok) throw batch.error;
expect(
batch.value,
"the unresolved batch item and its fallback retry are both caller input",
).toMatchObject({
items: [
{
address: "nosuch",
procedure: {
status: "unknown",
error: { code: "invalid_request" },
},
status: "error",
error: { code: "invalid_request" },
},
],
});
} finally {
expect((await client.close()).ok).toBe(true);
}
});
});
@@ -1114,3 +1114,41 @@ describe("no replacement start", () => {
expect(session.status()).toMatchObject({ open: false });
});
});
describe("selector origin forwarding", () => {
it("forwards the per-call selector origin to the provider client on both execution paths", async () => {
const [first] = await createBinarySessionTargets();
const seen: unknown[] = [];
const session = createTestBinarySession(() => ({
execute: (_operation, _parameters, options) => {
seen.push(options?.selectorOrigin);
return Promise.resolve(ok(null));
},
close: () => Promise.resolve(resultOk(null)),
}));
expect((await session.open(first)).ok, "the target opens").toBe(true);
seen.length = 0;
await session.execute(
"address_name",
{ address: "0x1000" },
{ selectorOrigin: "provider" },
);
await session.withAdmittedAnalysis(
"binary_overview",
undefined,
(analysis) =>
analysis.execute(
"address_name",
{ address: "0x2000" },
{ selectorOrigin: "provider" },
),
);
await session.execute("address_name", { address: "0x3000" });
expect(
seen,
"direct and admitted calls forward the origin; an unmarked call carries none",
).toEqual(["provider", "provider", undefined]);
});
});