Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/application/FunctionAnalysisEvidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const executeFunctionAnalysisEvidence = async (
rawResult: observation.rawResult,
limitations: observation.limitations,
locations: observation.locations,
...(observation.relationshipCoverage === undefined
? {}
: { relationshipCoverage: observation.relationshipCoverage }),
...(observation.analysisProfile === undefined
? {}
: { analysisProfile: observation.analysisProfile }),
Expand Down
110 changes: 110 additions & 0 deletions src/domain/callPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { createEvidence, type Evidence } from "./evidence.js";
import { functionDossierSchema } from "./hopperValues.js";
import { jsonValueSchema } from "./jsonValue.js";
import type { RelationshipCoverage } from "./relationshipCoverage.js";

const observe = (
address: string,
Expand All @@ -17,6 +18,7 @@ const observe = (
options: {
readonly evidenceLimitations?: readonly string[];
readonly dossierLimitations?: readonly string[];
readonly relationshipCoverage?: RelationshipCoverage;
} = {},
): Evidence => {
const value = functionDossierSchema.parse({
Expand Down Expand Up @@ -69,6 +71,9 @@ const observe = (
...(options.evidenceLimitations === undefined
? {}
: { limitations: options.evidenceLimitations }),
...(options.relationshipCoverage === undefined
? {}
: { relationshipCoverage: options.relationshipCoverage }),
},
);
};
Expand Down Expand Up @@ -171,6 +176,21 @@ describe("call path reconstruction", () => {
});

describe("call path topology and capacity", () => {
it("retains every distinct generic limitation beyond the push argument limit", () => {
const limitations = Array.from(
{ length: 1_000_000 },
(_, index) => `context-${index.toString().padStart(7, "0")}`,
);
const result = run([
observe("0x1000", [], "rea-workflow", {
evidenceLimitations: [...limitations].reverse(),
}),
]);
expect(result.status).toBe("unknown");
expect(result.search_scope.exhaustive).toBe(false);
expect(result.limitations).toEqual(limitations);
}, 30_000);

it("retains every shortest path through merging branches and cycles", () => {
const result = run([
observe("0x1000", ["0x3000", "0x2000", "0x1000"]),
Expand Down Expand Up @@ -314,6 +334,96 @@ describe("call path topology and capacity", () => {
});
});

describe("explicit call relationship coverage", () => {
it.each([150_000, 1_000_000])(
"accumulates %i partial reasons without argument-stack exhaustion",
(length) => {
const result = run([
observe("0x1000", [], "rea-workflow", {
relationshipCoverage: {
status: "partial",
limitations: Array<string>(length).fill("omitted"),
},
evidenceLimitations: [],
dossierLimitations: [],
}),
]);
expect(result).toMatchObject({
status: "unknown",
search_scope: { exhaustive: false },
limitations: ["omitted"],
});
},
);

it("retains contextual limits on a found path without reducing complete coverage", () => {
const limitation = "Provider results reflect the current database state.";
const result = run([
observe("0x1000", ["0x4000"], "rea-workflow", {
relationshipCoverage: { status: "complete" },
evidenceLimitations: [limitation],
}),
]);
expect(result).toMatchObject({
status: "found",
shortest_hops: 1,
search_scope: { exhaustive: true },
});
expect(result.limitations).toContain(limitation);
});

it("retains a found path while its expanded relationship coverage remains partial", () => {
const limitation = "Other callees were omitted by the provider cap.";
const result = run([
observe("0x1000", ["0x4000"], "rea-workflow", {
relationshipCoverage: { status: "partial", limitations: [limitation] },
}),
]);
expect(result).toMatchObject({
status: "found",
shortest_hops: 1,
search_scope: { exhaustive: false },
});
expect(result.limitations).toContain(limitation);
});

it("retains an unknown goal coverage reason without expanding the terminal goal", () => {
const reason = "The goal's outgoing relationship coverage is unknown.";
const result = run([
observe("0x1000", ["0x4000"], "rea-workflow", {
relationshipCoverage: { status: "complete" },
}),
observe("0x4000", ["0x5000"], "rea-workflow", {
relationshipCoverage: { status: "unknown", reason },
}),
]);
expect(result).toMatchObject({
status: "found",
search_scope: { exhaustive: true },
explored: { nodes: 2 },
});
expect(result.limitations).toEqual([reason]);
});

it("ignores incomplete relationship coverage outside the reachable search closure", () => {
const reason = "An unrelated function's callees were not observed.";
const result = run([
observe("0x1000", [], "rea-workflow", {
relationshipCoverage: { status: "complete" },
}),
observe("0x2000", ["0x5000"], "rea-workflow", {
relationshipCoverage: { status: "unknown", reason },
}),
]);
expect(result).toMatchObject({
status: "not_found",
search_scope: { exhaustive: true },
explored: { nodes: 1 },
});
expect(result.limitations).toEqual([]);
});
});

describe("call path evidence admission", () => {
it("normalizes hex addresses and rejects duplicates and mixed providers", () => {
expect(
Expand Down
19 changes: 17 additions & 2 deletions src/domain/callPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,27 @@ const inspectSearch = ({
const depth = reached.get(node) ?? 0;
const snapshot = snapshots.get(node);
if (snapshot !== undefined) {
limitations.push(...snapshot.limitations);
const coverage = snapshot.evidence.relationship_coverage;
for (const limitation of snapshot.limitations)
limitations.push(limitation);
if (coverage?.status === "partial")
for (const limitation of coverage.limitations)
limitations.push(limitation);
else if (coverage?.status === "unknown")
limitations.push(coverage.reason);
// The requested goal is a terminal for this search. Its outgoing edges
// cannot add a path to the goal, so its dossier limits are contextual
// but do not make the searched start-to-goal closure incomplete.
if (node === goal) continue;
if (snapshot.limitations.length > 0) incompleteExpandedCoverage = true;
// Explicit, Evidence-bound relationship coverage owns completeness;
// generic provider/dossier limitations remain contextual. Legacy Evidence
// without that metadata retains its conservative limitation-based rule.
if (
coverage === null
? snapshot.limitations.length > 0
: coverage.status !== "complete"
)
incompleteExpandedCoverage = true;
} else if (node === goal) {
continue;
}
Expand Down
Loading
Loading