fix(comparison): recheck historical calls-only changes (#2223)

* fix(comparison): preserve incomplete function call evidence

Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty.

Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls.

* fix(comparison): recheck historical calls-only changes

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Lucien
2026-10-13 23:30:31 +08:00
committed by GitHub
co-authored by morluto
parent 3c39a3f536
commit 688defca0f
3 changed files with 154 additions and 12 deletions
@@ -53,6 +53,7 @@ const source = (
digit: string,
observation: Partial<EvidenceObservation> = {},
hasSubject = true,
hasCoverage = true,
): Evidence =>
createEvidence(
hasSubject
@@ -69,7 +70,9 @@ const source = (
result: dossier,
confidence: "derived",
authority: "shipped-artifact",
relationshipCoverage: { status: "complete" },
...(hasCoverage
? { relationshipCoverage: { status: "complete" as const } }
: {}),
...observation,
},
);
@@ -197,6 +200,118 @@ describe("function reconstruction source parameters", () => {
});
});
describe("historical calls-only reconstruction changes", () => {
it.each(["missing", "unknown", "partial", "unresolved"] as const)(
"keeps historical calls-only changes unknown with %s call coverage",
(coverage) => {
const changedDossier = functionDossierSchema.parse({
...functionDossierSchema.parse(dossier),
callees: [
{
address: "0x2000",
name: "puts",
classification: null,
body: { available: false, reason: "External function." },
},
],
});
const complete = source("8", {
result: jsonValueSchema.parse(changedDossier),
});
const incomplete = source(
"9",
{
result: jsonValueSchema.parse({
...changedDossier,
...(coverage === "unresolved"
? {
unresolved_calls: [
{
address: "0x1004",
reason: "Computed target unresolved.",
},
],
}
: {}),
}),
...(coverage === "missing"
? {}
: {
relationshipCoverage:
coverage === "unknown"
? { status: "unknown", reason: "Call graph unavailable." }
: coverage === "partial"
? {
status: "partial",
limitations: ["Additional edges omitted."],
}
: { status: "complete" },
}),
},
true,
coverage !== "missing",
);
const historicalResult = compareFunctions(left, complete);
expect(historicalResult).toMatchObject({
status: "changed",
summary: { changed: 1 },
});
expect(historicalResult.changes).toMatchObject([
{ dimension: "calls", status: "changed" },
]);
const completeComparison = comparison(
{
left_evidence_id: left.evidence_id,
right_evidence_id: complete.evidence_id,
},
{},
[left, complete],
{},
historicalResult,
);
expect(
admittedVerification(completeComparison, [left, complete], "overall")()
.status,
).toBe("fail");
const evidence = comparison(
{
left_evidence_id: left.evidence_id,
right_evidence_id: incomplete.evidence_id,
},
{},
[left, incomplete],
{},
historicalResult,
);
const before = JSON.stringify(evidence);
for (const dimension of ["calls", "overall"] as const) {
expect(
admittedVerification(evidence, [left, incomplete], dimension)(),
).toMatchObject({
status: "unknown",
summary: { total: 1, passed: 0, failed: 0, unknown: 1 },
claims: {
items: [
expect.objectContaining({
status: "unknown",
observed_status: "changed",
limitations: expect.arrayContaining([
expect.stringContaining(`Source ${incomplete.evidence_id}:`),
]),
}),
],
},
});
}
expect(
admittedVerification(evidence, [left, incomplete], "pseudocode")()
.status,
).toBe("pass");
expect(JSON.stringify(evidence)).toBe(before);
},
);
});
describe("function reconstruction call coverage", () => {
it("rechecks old unchanged comparisons without affecting unrelated finite dimensions", () => {
const incomplete = source("7", {