fix(analysis)!: scope call-graph caveats to their observed relationships

Return deduplicated execution caveats once and preserve provider-owned relationship diagnostics and completeness on graph nodes. Keep complete relationship reads exhaustive despite contextual caveats, including portable call-path reconstruction.

Preserve omitted diagnostic fields in historical Evidence and bind reported diagnostics into semantic identity. Revise graph workflow and Ghidra adapter profiles so old cached representations cannot replay under the new contracts.

Remove stale duplicate-lookup test claims and redundant fixture validation. Prune million-entry duplicate cases while retaining argument-stack and deep-chain regressions; bounded Flameox captures identified validation and canonical hashing costs.

Validation: static and architecture checks, generated docs, 364 focused tests before pruning, 21 call-path tests after pruning, public MCP schema validation and targeted profile tests. Real engine behavior was not locally exercised.

BREAKING CHANGE: get_call_graph normalized_result now contains { graph, limitations }; traversal-depth groups are under graph.
This commit is contained in:
morluto
2026-10-12 09:29:07 +08:00
parent b38429cb6a
commit 5dfb9d050c
21 changed files with 433 additions and 186 deletions
+34 -43
View File
@@ -1,14 +1,9 @@
import { describe, expect, it } from "vitest";
import { enhancedInputSchemas } from "../contracts/enhancedInputs.js";
import { buildCallPath } from "./callPath.js";
import {
callPathInputSchema,
callPathResultSchema,
} from "./callPathSchemas.js";
import { callPathResultSchema, type CallPathInput } from "./callPathSchemas.js";
import { createEvidence, type Evidence } from "./evidence.js";
import { functionDossierSchema } from "./hopperValues.js";
import { jsonValueSchema } from "./jsonValue.js";
import type { JsonValue } from "./jsonValue.js";
import type { RelationshipCoverage } from "./relationshipCoverage.js";
const observe = (
@@ -21,7 +16,7 @@ const observe = (
readonly relationshipCoverage?: RelationshipCoverage;
} = {},
): Evidence => {
const value = functionDossierSchema.parse({
const value = {
procedure: {
address,
name: `fn_${address.slice(2)}`,
@@ -56,16 +51,14 @@ const observe = (
native_value_flow: null,
basic_blocks: [],
limitations: [...(options.dossierLimitations ?? [])],
});
} satisfies JsonValue;
return createEvidence(
{ path: "/tmp/a", sha256: "a".repeat(64), format: "mach-o" },
{ id: provider, name: provider, version: "1" },
{
operation: "analyze_function",
parameters: enhancedInputSchemas.analyze_function.parse({
procedure: address,
}),
result: jsonValueSchema.parse(value),
parameters: { procedure: address },
result: value,
confidence: "derived",
authority: "shipped-artifact",
...(options.evidenceLimitations === undefined
@@ -78,15 +71,16 @@ const observe = (
);
};
const run = (functions: Evidence[], overrides: Record<string, unknown> = {}) =>
buildCallPath(
callPathInputSchema.parse({
functions,
start: { address: "0x1000" },
goal: { address: "0x4000" },
...overrides,
}),
);
const run = (
functions: Evidence[],
overrides: Partial<Pick<CallPathInput, "start" | "goal">> = {},
) =>
buildCallPath({
functions,
start: { address: "0x1000" },
goal: { address: "0x4000" },
...overrides,
});
describe("call path reconstruction", () => {
it("returns deterministic shortest-first cited paths", () => {
@@ -178,7 +172,7 @@ 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 },
{ length: 150_000 },
(_, index) => `context-${index.toString().padStart(7, "0")}`,
);
const result = run([
@@ -335,26 +329,23 @@ 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("accumulates 150,000 partial reasons without argument-stack exhaustion", () => {
const result = run([
observe("0x1000", [], "rea-workflow", {
relationshipCoverage: {
status: "partial",
limitations: Array<string>(150_000).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.";
+4
View File
@@ -244,6 +244,10 @@ const inspectSearch = ({
limitations.push(limitation);
else if (coverage?.status === "unknown")
limitations.push(coverage.reason);
for (const diagnostic of coverage !== null && "diagnostics" in coverage
? coverage.diagnostics
: [])
limitations.push(diagnostic);
// 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.
+33
View File
@@ -19,6 +19,39 @@ const TARGET: BinaryTarget = {
const PROVIDER = { id: "fixture", name: "Fixture provider", version: "1" };
const PROFILE = createAnalysisProfile(PROVIDER, { loader: "default" });
it("preserves omitted relationship diagnostics and authenticates reported diagnostics", () => {
const observation = {
operation: "procedure_callees",
parameters: { procedure: "0x1000" },
result: ["0x2000"],
};
const historical = createEvidence(TARGET, PROVIDER, {
...observation,
relationshipCoverage: { status: "complete" },
});
expect(historical.relationship_coverage).toEqual({ status: "complete" });
expect(parseEvidence(JSON.parse(JSON.stringify(historical)))).toEqual(
historical,
);
const diagnosed = createEvidence(TARGET, PROVIDER, {
...observation,
relationshipCoverage: {
status: "complete",
diagnostics: ["Only resolved direct call references are observed."],
},
});
expect(parseEvidence(JSON.parse(JSON.stringify(diagnosed)))).toEqual(
diagnosed,
);
expect(diagnosed.evidence_id).not.toBe(historical.evidence_id);
expect(() =>
parseEvidence({
...historical,
relationship_coverage: diagnosed.relationship_coverage,
}),
).toThrow("semantic identifier");
});
it("preserves identity and bytes when reusing an owned immutable result", () => {
const value = { nested: { values: ["observed", 1] } };
const mutable = createEvidence(TARGET, PROVIDER, {
+18 -10
View File
@@ -1,16 +1,24 @@
import { z } from "zod";
const diagnostics = z.array(z.string().min(1)).min(1);
const completeCoverage = z.strictObject({ status: z.literal("complete") });
const partialCoverage = z.strictObject({
status: z.literal("partial"),
limitations: z.array(z.string().min(1)).min(1),
});
const unknownCoverage = z.strictObject({
status: z.literal("unknown"),
reason: z.string().min(1),
});
/** Explicit coverage state for a provider's observed caller/callee set. */
export const relationshipCoverageSchema = z.discriminatedUnion("status", [
z.strictObject({ status: z.literal("complete") }),
z.strictObject({
status: z.literal("partial"),
limitations: z.array(z.string().min(1)).min(1),
}),
z.strictObject({
status: z.literal("unknown"),
reason: z.string().min(1),
}),
export const relationshipCoverageSchema = z.union([
completeCoverage,
completeCoverage.extend({ diagnostics }),
partialCoverage,
partialCoverage.extend({ diagnostics }),
unknownCoverage,
unknownCoverage.extend({ diagnostics }),
]);
export type RelationshipCoverage = z.infer<typeof relationshipCoverageSchema>;