fix(analysis): preserve relationship coverage across evidence and replay

Separate observed relationship coverage from general provider caveats. Authenticate and replay coverage without changing legacy Evidence IDs; expose unknown and capped relationship sets through CLI/MCP graphs and traces.

Validated focused domain, snapshot, IDA/Ghidra boundary, MCP, schema, package and static checks. Provider fixtures establish contract behavior; licensed engine behavior was not reverified.
This commit is contained in:
morluto
2026-10-12 05:57:35 +08:00
parent f1924cf9c1
commit 9c8511409c
24 changed files with 469 additions and 55 deletions
@@ -189,7 +189,7 @@ const fixturePort = (): AnalysisOperationPort => ({
case "analyze_function":
return Promise.resolve(targetObservation(functionDossier));
default:
return Promise.resolve(ok(null));
throw new Error(`Unexpected analysis operation: ${name}`);
}
},
});
@@ -288,10 +288,36 @@ describe("enhanced MCP tools", () => {
failed: 0,
});
expect(results[3]).toEqual({
"0": [{ address: "0x1", status: "ok", calls: ["0x2", "0x3"] }],
"0": [
{
address: "0x1",
status: "ok",
calls: ["0x2", "0x3"],
relationship_coverage: {
status: "unknown",
reason: "Provider did not report relationship coverage.",
},
},
],
"1": [
{ address: "0x2", status: "ok", calls: ["0x1"] },
{ address: "0x3", status: "ok", calls: [] },
{
address: "0x2",
status: "ok",
calls: ["0x1"],
relationship_coverage: {
status: "unknown",
reason: "Provider did not report relationship coverage.",
},
},
{
address: "0x3",
status: "ok",
calls: [],
relationship_coverage: {
status: "unknown",
reason: "Provider did not report relationship coverage.",
},
},
],
});
expect(results[4]).toMatchObject({
@@ -354,7 +380,7 @@ describe("enhanced MCP tools", () => {
{ address: "0x1", depth: 0 },
{ address: "0x2", depth: 1 },
],
truncated: false,
truncated: true,
});
expect(results[11]).toMatchObject({
start: "missing-selector",
@@ -7,6 +7,7 @@ import {
AnalysisCapabilityUnavailableError,
AnalysisOutputError,
} from "../../../src/domain/analysisErrorCore.js";
import type { RelationshipCoverage } from "../../../src/domain/relationshipCoverage.js";
import { err, ok as resultOk } from "../../../src/domain/result.js";
import { closeEnhancedToolResources, connect } from "./enhancedToolsHarness.js";
@@ -17,12 +18,16 @@ afterEach(closeEnhancedToolResources);
const relationshipExecution = (
result: unknown,
limitations: readonly string[] = [],
relationshipCoverage?: RelationshipCoverage,
) =>
resultOk(
createAnalysisExecution(
result,
{ id: "fixture", name: "Fixture analysis provider", version: "1" },
{ limitations },
{
limitations,
...(relationshipCoverage === undefined ? {} : { relationshipCoverage }),
},
),
);
@@ -38,6 +43,9 @@ describe("enhanced MCP tools", () => {
return relationshipExecution(
arguments_.procedure === "0x1" ? ["0x2"] : [],
arguments_.procedure === "0x1" ? [limitation] : [],
arguments_.procedure === "0x1"
? { status: "partial", limitations: [limitation] }
: { status: "complete" },
);
},
});
@@ -54,6 +62,10 @@ describe("enhanced MCP tools", () => {
status: "ok",
calls: ["0x2"],
limitations: [limitation],
relationship_coverage: {
status: "partial",
limitations: [limitation],
},
},
],
},
@@ -77,6 +89,49 @@ describe("enhanced MCP tools", () => {
});
});
it("keeps generic provider caveats visible without truncating complete relationships", async () => {
const caveat = "Decompiler output may omit indirect calls.";
const client = await connect({
execute: async (name, arguments_) => {
if (name === "procedure_address")
return relationshipExecution(String(arguments_.procedure));
if (name !== "procedure_callees")
throw new Error(`Unexpected operation: ${name}`);
return relationshipExecution([], [caveat], { status: "complete" });
},
});
const graph = await client.callTool({
name: "get_call_graph",
arguments: { address: "0x1", direction: "forward" },
});
expect(graph.structuredContent).toMatchObject({
normalized_result: {
"0": [
{
limitations: [caveat],
relationship_coverage: { status: "complete" },
},
],
},
});
const trace = await client.callTool({
name: "trace_call_path",
arguments: { start: "0x1", goal: "0x2" },
});
expect(trace.structuredContent).toMatchObject({
normalized_result: {
truncated: false,
residual_unknowns: [],
limitations: expect.arrayContaining([expect.stringContaining(caveat)]),
relationship_coverage: { "0x1": { status: "complete" } },
},
});
});
});
describe("enhanced MCP batches", () => {
it("returns every batch item in caller order with its own result", async () => {
const addresses = Array.from(
{ length: 37 },
@@ -122,13 +122,16 @@ it("traverses every ARM64 callee in a call path without a goal and records no fa
{ source_address: "0x1000", target_address: "0x3000" },
],
failures: [],
truncated: true,
truncated: false,
limitations: expect.arrayContaining([
"This relationship read does not establish calls to targets IDA does not recognize as functions; imports and other non-function call targets remain unknown.",
]),
residual_unknowns: expect.arrayContaining([
expect.stringContaining("Call relationships for 0x1000 are limited:"),
]),
residual_unknowns: [],
relationship_coverage: {
"0x1000": { status: "complete" },
"0x2000": { status: "complete" },
"0x3000": { status: "complete" },
},
});
expect(
requestedRoots(producer),
@@ -203,7 +206,9 @@ it("preserves missing callgraph coverage through direct, graph, and trace workfl
expect.stringContaining("callgraph was unavailable"),
]),
residual_unknowns: expect.arrayContaining([
expect.stringContaining("Call relationships for 0x1000 are limited:"),
expect.stringContaining(
"Call relationship coverage is unknown for 0x1000:",
),
]),
});
expect(