mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
test(functions): share Evidence comparison fixtures (#16667)
This commit is contained in:
1 parent
5dd4efa5ac
commit
6c6204b2d8
1 file changed
+37
-68
@@ -20,6 +20,12 @@ import { functionCfgDossier } from "../../tests/fixtures/functionCfgDossier.js";
|
||||
|
||||
import { compareFunctions } from "./functionComparison.js";
|
||||
import type { RelationshipCoverage } from "./relationshipCoverage.js";
|
||||
const compareFixtureEvidence = (left: unknown, right: unknown) =>
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
|
||||
const procedure = (address: string, name: string) => ({
|
||||
address,
|
||||
name,
|
||||
@@ -210,10 +216,7 @@ it.each(["imported", null] as const)(
|
||||
});
|
||||
const left = observe("a", before);
|
||||
const right = observe("a", after);
|
||||
const result = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const result = compareFixtureEvidence(left, right);
|
||||
expect(result.function_match).toMatchObject({
|
||||
status: "matched",
|
||||
method: "same-entry",
|
||||
@@ -283,10 +286,9 @@ describe("function comparison normalized identity", () => {
|
||||
};
|
||||
delete value.facet_availability;
|
||||
const legacy = observe("a", functionDossierSchema.parse(value), "ida");
|
||||
const calls = compareFunctions(
|
||||
functionSnapshotFixture(legacy),
|
||||
functionSnapshotFixture(legacy),
|
||||
).dimensions.find(({ dimension }) => dimension === "calls");
|
||||
const calls = compareFixtureEvidence(legacy, legacy).dimensions.find(
|
||||
({ dimension }) => dimension === "calls",
|
||||
);
|
||||
expect(calls).toMatchObject({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
@@ -302,10 +304,7 @@ describe("function comparison normalized identity", () => {
|
||||
};
|
||||
delete value.facet_availability;
|
||||
const legacy = observe("a", functionDossierSchema.parse(value), "ida");
|
||||
const result = compareFunctions(
|
||||
functionSnapshotFixture(legacy),
|
||||
functionSnapshotFixture(legacy),
|
||||
);
|
||||
const result = compareFixtureEvidence(legacy, legacy);
|
||||
for (const dimension of [
|
||||
"comments",
|
||||
"references",
|
||||
@@ -333,10 +332,9 @@ describe("function comparison normalized identity", () => {
|
||||
);
|
||||
const right = observe("b", dossier("return 0;", "0x2000"));
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
).dimensions.find(({ dimension }) => dimension === "comments"),
|
||||
compareFixtureEvidence(left, right).dimensions.find(
|
||||
({ dimension }) => dimension === "comments",
|
||||
),
|
||||
).toMatchObject({ status: "unknown", left_count: null, right_count: null });
|
||||
});
|
||||
it(
|
||||
@@ -506,10 +504,7 @@ describe("function call relationship coverage", () => {
|
||||
"rea-workflow",
|
||||
coverage,
|
||||
);
|
||||
const result = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const result = compareFixtureEvidence(left, right);
|
||||
const calls = result.dimensions.find(
|
||||
({ dimension }) => dimension === "calls",
|
||||
);
|
||||
@@ -537,10 +532,9 @@ describe("function call relationship coverage", () => {
|
||||
});
|
||||
const right = observe("f", rightDossier);
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
).dimensions.find(({ dimension }) => dimension === "calls"),
|
||||
compareFixtureEvidence(left, right).dimensions.find(
|
||||
({ dimension }) => dimension === "calls",
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "unknown",
|
||||
limitations: [
|
||||
@@ -725,10 +719,7 @@ it.each([
|
||||
);
|
||||
rightValue.basic_blocks.reverse();
|
||||
const right = observe("b", rightValue);
|
||||
const result = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const result = compareFixtureEvidence(left, right);
|
||||
expect(result.status).toBe(status);
|
||||
expect(
|
||||
result.dimensions.find(({ dimension }) => dimension === "cfg"),
|
||||
@@ -884,10 +875,7 @@ describe("function comparison unresolved text", () => {
|
||||
assembly: ["0x2000 call FUN_00002010", "0x2004 ret"],
|
||||
}),
|
||||
);
|
||||
const comparison = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const comparison = compareFixtureEvidence(left, right);
|
||||
for (const name of ["pseudocode", "assembly"]) {
|
||||
const dimension = comparison.dimensions.find(
|
||||
({ dimension }) => dimension === name,
|
||||
@@ -909,10 +897,7 @@ describe("function comparison unresolved text", () => {
|
||||
it("counts Unicode text consistently for unresolved provider comparisons", () => {
|
||||
const left = observe("b", dossier("return '😀';", "0x1000"), "provider-a");
|
||||
const right = observe("c", dossier("return '😀';", "0x2000"), "provider-b");
|
||||
const comparison = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const comparison = compareFixtureEvidence(left, right);
|
||||
expect(
|
||||
comparison.dimensions.find(({ dimension }) => dimension === "pseudocode"),
|
||||
).toMatchObject({
|
||||
@@ -970,10 +955,7 @@ describe("function comparison", () => {
|
||||
"rea-workflow",
|
||||
coverage,
|
||||
);
|
||||
const comparison = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const comparison = compareFixtureEvidence(left, right);
|
||||
expect(
|
||||
comparison.dimensions.find(({ dimension }) => dimension === "calls"),
|
||||
).toMatchObject({
|
||||
@@ -1010,10 +992,9 @@ describe("function comparison", () => {
|
||||
diagnostics: [diagnostic],
|
||||
});
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
).dimensions.find(({ dimension }) => dimension === "calls"),
|
||||
compareFixtureEvidence(left, right).dimensions.find(
|
||||
({ dimension }) => dimension === "calls",
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
@@ -1053,10 +1034,7 @@ describe("function comparison normalization and provenance", () => {
|
||||
it("normalizes CFG relocation but preserves changed edges and constants", () => {
|
||||
const left = observe("2", dossier("return 0x10; /* 🎨 */", "0x1000"));
|
||||
const relocated = observe("3", dossier("return 0x10; /* 🎨 */", "0x2000"));
|
||||
const same = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(relocated),
|
||||
);
|
||||
const same = compareFixtureEvidence(left, relocated);
|
||||
expect(
|
||||
same.dimensions.find(({ dimension }) => dimension === "cfg"),
|
||||
).toMatchObject({
|
||||
@@ -1075,10 +1053,7 @@ describe("function comparison normalization and provenance", () => {
|
||||
"4",
|
||||
dossier("return 0x20; /* 🎨 */", "0x2000", ["0x2000"]),
|
||||
);
|
||||
const comparison = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(changed),
|
||||
);
|
||||
const comparison = compareFixtureEvidence(left, changed);
|
||||
expect(
|
||||
comparison.dimensions.find(({ dimension }) => dimension === "cfg"),
|
||||
).toMatchObject({ status: "changed" });
|
||||
@@ -1118,10 +1093,7 @@ describe("function comparison normalization and provenance", () => {
|
||||
it("reports fully observed identical dossiers as unchanged", () => {
|
||||
const left = observe("7", dossier("return 0;\n", "0x1000"));
|
||||
const right = observe("8", dossier("return 0;\n", "0x2000"));
|
||||
const comparison = compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(right),
|
||||
);
|
||||
const comparison = compareFixtureEvidence(left, right);
|
||||
expect(comparison.status).toBe("unchanged");
|
||||
expect(
|
||||
comparison.dimensions.every(({ status }) => status === "unchanged"),
|
||||
@@ -1132,18 +1104,16 @@ describe("function comparison normalization and provenance", () => {
|
||||
const left = observe("d", dossierWithReference("0x1000", "call"));
|
||||
const same = observe("e", dossierWithReference("0x2000", "call"));
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(same),
|
||||
).dimensions.find(({ dimension }) => dimension === "references"),
|
||||
compareFixtureEvidence(left, same).dimensions.find(
|
||||
({ dimension }) => dimension === "references",
|
||||
),
|
||||
).toMatchObject({ status: "unchanged" });
|
||||
|
||||
const changed = observe("f", dossierWithReference("0x2000", "data"));
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(changed),
|
||||
).dimensions.find(({ dimension }) => dimension === "references"),
|
||||
compareFixtureEvidence(left, changed).dimensions.find(
|
||||
({ dimension }) => dimension === "references",
|
||||
),
|
||||
).toMatchObject({ status: "changed" });
|
||||
|
||||
const unavailable = observe(
|
||||
@@ -1151,10 +1121,9 @@ describe("function comparison normalization and provenance", () => {
|
||||
dossierWithReference("0x2000", "unavailable"),
|
||||
);
|
||||
expect(
|
||||
compareFunctions(
|
||||
functionSnapshotFixture(left),
|
||||
functionSnapshotFixture(unavailable),
|
||||
).dimensions.find(({ dimension }) => dimension === "references"),
|
||||
compareFixtureEvidence(left, unavailable).dimensions.find(
|
||||
({ dimension }) => dimension === "references",
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "unknown",
|
||||
limitations: [expect.stringContaining("did not expose reference kinds")],
|
||||
|
||||
Reference in new issue
Block a user