fix(evidence): preserve call coverage in function comparisons

Treat missing, partial, unknown, and unresolved call coverage as insufficient for call-set equality. Combine IDA caller/callee coverage without losing either explanation and recheck source coverage when verifying historical comparisons.

Scope generated function-comparison unknowns with optional typed comparison/dimension facts, preserving legacy IDs and revision digests when absent. Keep unrelated dimensions conclusive, explicit dependencies applicable, and ambiguous function identity unknown. A confirmed change for matched functions remains a failure even if calls are incomplete.

Validation: function/reconstruction/residual-unknown and bundle tests, recorded IDA protocol regression, public MCP comparison/verification, and advertised SDK JSON Schema checks. Real IDA provider execution was not verified.

Fixes #2222
This commit is contained in:
morluto
2026-10-13 04:12:34 +08:00
parent c89972c877
commit 049132ab43
17 changed files with 871 additions and 63 deletions
+116
View File
@@ -11,6 +11,7 @@ import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js";
import { jsonValueSchema } from "./jsonValue.js";
import { compareFunctions } from "./functionComparison.js";
import type { RelationshipCoverage } from "./relationshipCoverage.js";
const procedure = (address: string, name: string) => ({
address,
name,
@@ -96,6 +97,7 @@ const observe = (
digit: string,
value: ReturnType<typeof dossier>,
providerId = "rea-workflow",
relationshipCoverage: RelationshipCoverage | null = { status: "complete" },
): Evidence =>
createEvidence(
{
@@ -112,6 +114,7 @@ const observe = (
result: jsonValueSchema.parse(value),
confidence: "derived",
authority: "shipped-artifact",
...(relationshipCoverage === null ? {} : { relationshipCoverage }),
},
);
@@ -187,6 +190,100 @@ describe("function comparison normalized identity", () => {
});
});
describe("function call relationship coverage", () => {
const coverageCases: {
readonly label: string;
readonly coverage: RelationshipCoverage | null;
readonly limitation: string;
}[] = [
{
label: "missing",
coverage: null,
limitation: "Provider did not report relationship coverage.",
},
{
label: "partial",
coverage: {
status: "partial",
limitations: ["Call graph stopped at the read limit."],
},
limitation: "Call graph stopped at the read limit.",
},
];
it.each(coverageCases)(
"keeps equal empty calls unknown for $label coverage",
({ coverage, limitation }) => {
const left = observe("a", dossier("return 0;", "0x1000"));
const right = observe(
"b",
dossier("return 0;", "0x2000"),
"rea-workflow",
coverage,
);
const result = compareFunctions(left, right);
const calls = result.dimensions.find(
({ dimension }) => dimension === "calls",
);
expect(calls).toMatchObject({
status: "unknown",
conclusion_kind: "unresolved_branch",
left_count: 0,
right_count: 0,
limitations: [`Right: ${limitation}`],
});
expect(result.status).toBe("unknown");
},
);
it("retains complete observations with execution diagnostics as comparable", () => {
const coverage = {
status: "complete" as const,
diagnostics: ["Provider reported a non-call xref warning."],
};
const left = observe(
"c",
dossier("return 0;", "0x1000"),
"rea-workflow",
coverage,
);
const right = observe(
"d",
dossier("return 0;", "0x2000"),
"rea-workflow",
coverage,
);
expect(
compareFunctions(left, right).dimensions.find(
({ dimension }) => dimension === "calls",
),
).toMatchObject({ status: "unchanged", left_count: 0, right_count: 0 });
});
it("keeps unresolved call sites unknown despite complete resolved-set coverage", () => {
const left = observe("e", dossier("return 0;", "0x1000"));
const rightDossier = functionDossierSchema.parse({
...dossier("return 0;", "0x2000"),
unresolved_calls: [
{
address: "0x2010",
reason: "Indirect dispatch target could not be resolved.",
},
],
});
const right = observe("f", rightDossier);
expect(
compareFunctions(left, right).dimensions.find(
({ dimension }) => dimension === "calls",
),
).toMatchObject({
status: "unknown",
limitations: [
"Right: Unresolved call at 0x2010: Indirect dispatch target could not be resolved.",
],
});
});
});
describe("function collection collation ties", () => {
const composed = procedure("0x2000", "caf\u00e9");
const decomposed = procedure("0x3000", "cafe\u0301");
@@ -342,6 +439,7 @@ describe("function comparison ordering controls", () => {
result: jsonValueSchema.parse(result),
confidence: "derived",
authority: "shipped-artifact",
relationshipCoverage: { status: "complete" },
},
);
const left = controlled("0x1000", false);
@@ -525,7 +623,9 @@ describe("function comparison", () => {
limitations: [expect.stringContaining("did not expose reference kinds")],
});
});
});
describe("function comparison identity and malformed CFG", () => {
it("does not promote address-derived names through equal signatures", () => {
const autoDossier = (base: "0x1000" | "0x2000") =>
functionDossierSchema.parse({
@@ -546,6 +646,22 @@ describe("function comparison", () => {
comparison.dimensions.find(({ dimension }) => dimension === "identity"),
).toMatchObject({ status: "unknown" });
expect(comparison.status).toBe("unknown");
const changedText = compareFunctions(
observe("b", autoDossier("0x1000")),
observe(
"c",
functionDossierSchema.parse({
...autoDossier("0x2000"),
pseudocode: "return 1;",
}),
),
);
expect(changedText.dimensions).toEqual(
expect.arrayContaining([
expect.objectContaining({ dimension: "pseudocode", status: "changed" }),
]),
);
expect(changedText.status).toBe("unknown");
});
it("rejects invalid CFG normalization and preserves newline differences", () => {