fix(functions): preserve proven referenced string membership changes (#13421)

This commit is contained in:
morluto authored and GitHub committed 2026-11-22 13:19:31 +00:00
1 parent 6a20a88e81
commit afbbfff561
6 files changed
+108 -87

No files matched your search

+64 -74
View File
@@ -516,31 +516,6 @@ describe("function call relationship coverage", () => {
},
);
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(
functionSnapshotFixture(left),
functionSnapshotFixture(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({
@@ -911,7 +886,18 @@ describe("function comparison unresolved text", () => {
);
expect(
comparison.dimensions.find(({ dimension }) => dimension === "pseudocode"),
).toMatchObject({ status: "unknown", left_count: 11, right_count: 11 });
).toMatchObject({
status: "unknown",
left_count: 11,
right_count: 11,
left_digest: null,
right_digest: null,
text_delta: null,
});
expect(comparison.changes.map(({ dimension }) => dimension)).toEqual([
"pseudocode",
"assembly",
]);
expect(comparison.summary).toEqual({
unchanged: 6,
changed: 0,
@@ -927,35 +913,58 @@ describe("function comparison unresolved text", () => {
});
describe("function comparison", () => {
it("retains complete call coverage diagnostics without blocking observed-set equality", () => {
const diagnostic = "Indirect calls remain unresolved.";
const left = observe("a", dossier("return 0;", "0x1000"), "rea-workflow", {
status: "complete",
diagnostics: [diagnostic],
discovery: {
callers: { status: "complete" },
callees: { status: "complete" },
},
});
const right = observe("b", dossier("return 0;", "0x2000"), "rea-workflow", {
status: "complete",
diagnostics: [diagnostic],
discovery: {
callers: { status: "complete" },
callees: { status: "complete" },
},
});
const comparison = compareFunctions(
functionSnapshotFixture(left),
functionSnapshotFixture(right),
);
expect(
comparison.dimensions.find(({ dimension }) => dimension === "calls"),
).toMatchObject({
status: "unchanged",
limitations: [`Left: ${diagnostic}`, `Right: ${diagnostic}`],
});
});
it.each(["legacy", "discovery"] as const)(
"retains complete call coverage diagnostics for %s observations",
(coverageKind) => {
const diagnostic = "Indirect calls remain unresolved.";
const coverage: RelationshipCoverage = {
status: "complete",
diagnostics: [diagnostic],
...(coverageKind === "legacy"
? {}
: {
discovery: {
callers: { status: "complete" },
callees: { status: "complete" },
},
}),
};
const left = observe(
"a",
dossier("return 0;", "0x1000"),
"rea-workflow",
coverage,
);
const right = observe(
"b",
dossier("return 0;", "0x2000"),
"rea-workflow",
coverage,
);
const comparison = compareFunctions(
functionSnapshotFixture(left),
functionSnapshotFixture(right),
);
expect(
comparison.dimensions.find(({ dimension }) => dimension === "calls"),
).toMatchObject({
status: "unchanged",
left_count: 0,
right_count: 0,
discovery_status: coverageKind === "legacy" ? "unknown" : "complete",
limitations: [
`Left: ${diagnostic}`,
`Right: ${diagnostic}`,
...(coverageKind === "legacy"
? [
"Left: Static direct-call discovery is not established for callers and callees.",
"Right: Static direct-call discovery is not established for callers and callees.",
]
: []),
],
});
},
);
it("retains diagnostics alongside incomplete call coverage blockers", () => {
const diagnostic = "Indirect calls remain unresolved.";
@@ -1039,25 +1048,6 @@ describe("function comparison normalization and provenance", () => {
).toMatchObject({ status: "changed" });
});
it("treats provider-specific text as unknown and validates Evidence", () => {
const left = observe("5", dossier("return 0;", "0x1000"), "provider-a");
const right = observe("6", dossier("return 1;", "0x2000"), "provider-b");
const comparison = compareFunctions(
functionSnapshotFixture(left),
functionSnapshotFixture(right),
);
expect(
comparison.dimensions.find(({ dimension }) => dimension === "pseudocode"),
).toMatchObject({ status: "unknown" });
expect(comparison.changes).toHaveLength(2);
expect(() =>
compareFunctions(
functionSnapshotFixture({ ...left, operation: "binary_overview" }),
functionSnapshotFixture(right),
),
).toThrow(/identifier/u);
});
it("matches entries by address only within the same opened target", () => {
const raw = (entryPoint: string): EvidenceSubjectTarget => ({
path: "/tmp/function.bin",
+4 -1
View File
@@ -401,7 +401,10 @@ const compareReferencedStrings = (
continue;
}
if (leftRows === undefined || rightRows === undefined) {
if (leftUnlocated || rightUnlocated)
// Only an unlocated row on the missing side could occupy this offset.
const missingSideHasUnlocated =
leftRows === undefined ? leftUnlocated : rightUnlocated;
if (missingSideHasUnlocated)
limitations.add(
`Referenced string membership at source offset ${offset} is ambiguous because another source location is unavailable.`,
);
@@ -1,4 +1,4 @@
import { expect, it, onTestFinished } from "vitest";
import { expect, it } from "vitest";
import { FUNCTION_COMPARISON_EXAMPLE } from "../../../src/contracts/functionComparisonExample.js";
import {
@@ -194,7 +194,6 @@ it.each([
);
});
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
for (const record of [
FUNCTION_COMPARISON_EXAMPLE.left,
FUNCTION_COMPARISON_EXAMPLE.right,
@@ -4,7 +4,7 @@ import { Ajv2020 } from "ajv/dist/2020.js";
import type { AnySchema } from "ajv";
import { functionSnapshotFixture } from "../../../src/domain/functionDossierEvidence.fixture.js";
import { ok as resultOk } from "../../../src/domain/result.js";
import { describe, expect, it, onTestFinished } from "vitest";
import { describe, expect, it } from "vitest";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
@@ -33,7 +33,6 @@ it.each([
);
});
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
const source = (side: "1" | "2", space: string) => {
const example = FUNCTION_COMPARISON_EXAMPLE.left;
const value = functionDossierSchema.parse(example.normalized_result);
@@ -327,7 +326,6 @@ describe("function comparison input-kind diagnostics", () => {
throw new Error("Wrong-kind function input must not launch a provider");
});
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
const wrong = wrongKindFunctionEvidence(mismatch);
const good =
FUNCTION_COMPARISON_EXAMPLE[side === "left" ? "right" : "left"];
@@ -376,7 +374,6 @@ describe("function comparison input-kind diagnostics", () => {
true,
);
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
const result = await harness.client.callTool({
name: "compare_functions",
arguments: {
@@ -407,7 +404,6 @@ describe("function comparison input-kind diagnostics", () => {
throw new Error("Tampered function input must not launch a provider");
});
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
const tampered = {
...FUNCTION_COMPARISON_EXAMPLE.left,
limitations: [
@@ -513,7 +509,6 @@ it.each([
throw new Error("Imported comparison must not launch a provider");
});
const harness = await createApplicationMcpHarness({ session });
onTestFinished(harness.close);
const imported = await harness.client.callTool({
name: "import_evidence_bundle",
arguments: { path },
@@ -48,7 +48,6 @@ const createHarness = async () => {
throw new Error("Function comparison must not launch a provider");
}),
});
onTestFinished(harness.close);
return harness;
};
@@ -121,6 +121,42 @@ beforeEach(async () => {
const stringsNames = (result: Comparison) =>
result.dimensions.find(({ dimension }) => dimension === "strings_names");
it("keeps located membership changes when only that side has an unlocated reference", async () => {
const located = reference("known", { sourceAddress: "0x1004" });
const unlocated = reference("unplaced", { sourceAddress: "0x0fff" });
const mixed = evidence("mixed", [located, unlocated]);
const empty = evidence("empty", []);
const unknown = evidence("unknown", [unlocated]);
for (const [left, right, leftCount, rightCount] of [
[mixed, empty, 2, 0],
[empty, mixed, 0, 2],
] as const) {
expect(stringsNames(await compare(left, right))).toMatchObject({
status: "changed",
left_count: leftCount,
right_count: rightCount,
evidence_links: [left.evidence_id, right.evidence_id],
limitations: [
"Referenced string source location could not be normalized.",
],
});
}
for (const [left, right] of [
[mixed, unknown],
[unknown, mixed],
] as const)
expect(stringsNames(await compare(left, right))).toMatchObject({
status: "unknown",
left_digest: null,
right_digest: null,
limitations: expect.arrayContaining([
"Referenced string membership at source offset 4 is ambiguous because another source location is unavailable.",
]),
});
});
describe("compare_functions referenced string decoding", () => {
const reason = "The native string bytes are unavailable";
const undecodable = (id: string, display: string) =>
@@ -208,8 +244,7 @@ describe("compare_functions referenced string decoding", () => {
termination:
| "missing"
| "present_or_not_required" = "present_or_not_required",
byteLength = 6,
) => evidence(id, [reference("hello", { termination, byteLength })]);
) => evidence(id, [reference("hello", { termination })]);
const equal = await compare(decoded("5"), decoded("6"));
expect(equal.status).toBe("unchanged");
expect(stringsNames(equal)).toMatchObject({
@@ -222,7 +257,7 @@ describe("compare_functions referenced string decoding", () => {
stringsNames(equal)?.left_digest,
);
const different = await compare(decoded("7"), decoded("8", "missing", 5));
const different = await compare(decoded("7"), decoded("8", "missing"));
expect(different.status).toBe("changed");
expect(stringsNames(different)).toMatchObject({ status: "changed" });
});