fix(analysis): preserve relationship coverage across evidence and replay

Separate observed relationship coverage from general provider caveats. Authenticate and replay coverage without changing legacy Evidence IDs; expose unknown and capped relationship sets through CLI/MCP graphs and traces.

Validated focused domain, snapshot, IDA/Ghidra boundary, MCP, schema, package and static checks. Provider fixtures establish contract behavior; licensed engine behavior was not reverified.
This commit is contained in:
morluto
2026-10-12 05:57:35 +08:00
parent f1924cf9c1
commit 9c8511409c
24 changed files with 469 additions and 55 deletions
+12 -1
View File
@@ -40,6 +40,7 @@ const snapshotWithHistoricalEvidence = () => {
raw_result: null,
provider: binding.provider,
limitations: [],
relationship_coverage: null,
locations: [],
subject: {
path: ANALYSIS_SNAPSHOT_TARGET.path,
@@ -392,7 +393,10 @@ describe("analysis snapshot Evidence binding", () => {
workflow_entries: [],
evidence_bundle: createEvidenceBundle([evidence]),
};
expect(parseAnalysisSnapshot(snapshot)).toEqual(snapshot);
const parsedLegacySnapshot = parseAnalysisSnapshot(snapshot);
expect(
parsedLegacySnapshot.entries[0]?.execution.relationship_coverage,
).toBeNull();
expect(() =>
parseAnalysisSnapshot({
@@ -420,6 +424,13 @@ describe("analysis snapshot Evidence binding", () => {
if (subject !== null && subject !== undefined)
subject.path = "/different/path";
},
(altered: typeof snapshot) => {
const entry = altered.entries[0];
if (entry === undefined) throw new TypeError("missing fixture entry");
Reflect.set(entry.execution, "relationship_coverage", {
status: "complete",
});
},
];
for (const alter of alterations) {
const altered = structuredClone(snapshot);
+31 -14
View File
@@ -42,6 +42,10 @@ import { prefixedDigestSchema } from "./../domain/digests.js";
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
import { freezeJsonSnapshot } from "./immutableJson.js";
import { rawBinaryEntryPointSchema } from "./rawBinary.js";
import {
relationshipCoverageSchema,
type RelationshipCoverage,
} from "./relationshipCoverage.js";
const architectureSchema = z.enum(BINARY_ARCHITECTURES);
const formatSchema = z.enum([
@@ -125,6 +129,7 @@ const entrySchema = z.object({
raw_result: jsonValueSchema.nullable(),
provider: committedProviderSchema,
limitations: z.array(z.string()),
relationship_coverage: relationshipCoverageSchema.nullable().default(null),
locations: z.array(evidenceLocationSchema),
subject: subjectSchema.nullable(),
}),
@@ -139,6 +144,7 @@ const workflowEntrySchema = z.object({
provider: committedProviderSchema,
analysis_profile: analysisProfileSchema,
limitations: z.array(z.string()),
relationship_coverage: relationshipCoverageSchema.nullable().default(null),
locations: z.array(evidenceLocationSchema),
subject: subjectSchema.nullable(),
}),
@@ -268,7 +274,7 @@ const snapshotContentDigest = (
rawResult: JsonValue | null,
execution: Pick<
AnalysisSnapshotEntry["execution"],
"limitations" | "locations" | "subject"
"limitations" | "locations" | "subject" | "relationship_coverage"
>,
): string => {
const metadata = jsonObjectSchema.parse({
@@ -283,6 +289,9 @@ const snapshotContentDigest = (
format: execution.subject.format,
architecture: execution.subject.architecture,
},
...(execution.relationship_coverage === null
? {}
: { relationship_coverage: execution.relationship_coverage }),
});
return contentDigest({
...metadata,
@@ -309,6 +318,7 @@ interface SnapshotExecution {
};
readonly analysisProfile?: AnalysisProfileCommitment;
readonly limitations: readonly string[];
readonly relationshipCoverage?: RelationshipCoverage | null | undefined;
readonly locations: readonly EvidenceLocation[];
readonly subject: EvidenceSubjectTarget | null;
}
@@ -460,6 +470,7 @@ export const createAnalysisSnapshotWorkflowEntry = (input: {
provider: execution.analysisProfile.provider,
analysis_profile: execution.analysisProfile,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
@@ -522,6 +533,7 @@ export const createAnalysisSnapshotEntry = (input: {
raw_result: execution.rawResult,
provider: binding.provider,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
@@ -838,19 +850,24 @@ const evidenceMatchesWorkflowEntry = (
evidenceContentDigest(evidence),
]) === workflowEntryEvidenceKey(entry);
const evidenceContentMetadata = (evidence: Evidence) => ({
limitations: evidence.limitations,
locations: evidence.locations,
subject:
evidence.subject === null
? null
: {
local_path: evidence.subject.local_path,
sha256: evidence.subject.digest.sha256,
format: evidence.subject.format,
architecture: evidence.subject.architecture,
},
});
const evidenceContentMetadata = (evidence: Evidence) => {
return {
limitations: evidence.limitations,
...(evidence.relationship_coverage === null
? {}
: { relationship_coverage: evidence.relationship_coverage }),
locations: evidence.locations,
subject:
evidence.subject === null
? null
: {
local_path: evidence.subject.local_path,
sha256: evidence.subject.digest.sha256,
format: evidence.subject.format,
architecture: evidence.subject.architecture,
},
};
};
/** Serialize a validated snapshot with byte-stable canonical entry ordering. */
export const serializeAnalysisSnapshot = (snapshot: AnalysisSnapshot): string =>
+18 -4
View File
@@ -27,6 +27,10 @@ import {
} from "./immutableJson.js";
import { digestSchema } from "./../domain/digests.js";
import { prefixedDigestSchema } from "./../domain/digests.js";
import {
relationshipCoverageSchema,
type RelationshipCoverage,
} from "./relationshipCoverage.js";
/** Provider identity schema shared by evidence-bearing persistence formats. */
export const providerSchema = z.object({
@@ -118,6 +122,7 @@ const evidenceBaseSchema = z
authority: evidenceAuthoritySchema,
environment: executionEnvironmentSchema.nullable(),
limitations: z.array(z.string()),
relationship_coverage: relationshipCoverageSchema.nullable().default(null),
locations: z.array(evidenceLocationSchema),
evidence_links: z.array(prefixedDigestSchema("ev")),
})
@@ -163,9 +168,11 @@ const authenticatedEvidenceSchema = evidenceSchema.superRefine(
);
/** Complete observation whose normalized payload retains its operation-specific type. */
export type Evidence<Result extends JsonValue = JsonValue> = z.infer<
typeof evidenceSchema
> & { readonly normalized_result: Result };
type EvidenceSchemaValue = z.infer<typeof evidenceSchema>;
export type Evidence<Result extends JsonValue = JsonValue> =
EvidenceSchemaValue & {
readonly normalized_result: Result;
};
const immutableEvidenceSnapshots = new WeakMap<object, Evidence>();
const immutableResultSchema = z
.custom<JsonValue>(isImmutableJsonSnapshot)
@@ -215,13 +222,14 @@ export interface EvidenceObservation {
readonly authority?: EvidenceAuthority;
readonly environment?: ExecutionEnvironment | null;
readonly limitations?: readonly string[];
readonly relationshipCoverage?: RelationshipCoverage;
/** Reason the subject identity is unavailable, when no target identity is supplied. */
readonly subjectUnavailableReason?: string;
readonly locations?: readonly EvidenceLocation[];
readonly evidenceLinks?: readonly string[];
}
type EvidenceWithoutId = Omit<Evidence, "evidence_id">;
type EvidenceWithoutId = Omit<EvidenceSchemaValue, "evidence_id">;
const semanticProjection = (evidence: EvidenceWithoutId): JsonValue => ({
subject:
@@ -243,6 +251,9 @@ const semanticProjection = (evidence: EvidenceWithoutId): JsonValue => ({
authority: evidence.authority,
environment: evidence.environment,
limitations: evidence.limitations,
...(evidence.relationship_coverage === null
? {}
: { relationship_coverage: evidence.relationship_coverage }),
locations: evidence.locations,
evidence_links: evidence.evidence_links,
});
@@ -404,6 +415,9 @@ const normalizeEvidenceObservation = (
: []),
...(observation.limitations ?? []),
],
...(observation.relationshipCoverage === undefined
? { relationship_coverage: null }
: { relationship_coverage: observation.relationshipCoverage }),
locations: [...(observation.locations ?? [])],
evidence_links: [...(observation.evidenceLinks ?? [])],
} satisfies JsonValue;
+16
View File
@@ -0,0 +1,16 @@
import { z } from "zod";
/** 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 type RelationshipCoverage = z.infer<typeof relationshipCoverageSchema>;