test(snapshot): share procedure cache fixtures (#17109)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 23:25:49 +08:00
1 parent fbdf8ce812
commit b495bfcd1d
1 file changed
+61 -76
@@ -50,6 +50,21 @@ import { EvidenceLedger } from "../investigation/EvidenceLedger.js";
import { nativeCallGraphSchema } from "../../domain/native/nativeCallGraph.js";
type SnapshotRecord = Parameters<AnalysisSnapshotCache["record"]>[0];
const recordProcedureInfo = (
cache: AnalysisSnapshotCache,
parameters: SnapshotRecord["parameters"],
execution: SnapshotRecord["execution"],
) =>
cache.record({
target: ANALYSIS_SNAPSHOT_TARGET,
profile: ANALYSIS_SNAPSHOT_PROFILE,
operation: "procedure_info",
parameters,
execution,
});
it.each(["provider", "workflow"] as const)(
"owns nested %s execution data before returning control to callers",
(kind) => {
@@ -122,17 +137,15 @@ it("exports independent nested query, workflow and Evidence payloads", () => {
const result = { nested: [{ text: "ret" }], name: "main" };
const parameters = { address: "0x1000", document: "fixture" };
const workflowProfile = workflowAnalysisProfile(profile);
cache.record({
target,
profile,
operation: "procedure_info",
recordProcedureInfo(
cache,
parameters,
execution: createAnalysisExecution(result, ANALYSIS_SNAPSHOT_PROVIDER, {
createAnalysisExecution(result, ANALYSIS_SNAPSHOT_PROVIDER, {
subject: target,
analysisProfile: profile,
rawResult: result,
}),
});
);
cache.recordWorkflow({
target,
profile,
@@ -406,16 +419,14 @@ it("counts newly retained direct and workflow bindings when staging", () => {
const profile = ANALYSIS_SNAPSHOT_PROFILE;
const parameters = { address: "0x1000" };
const workflowProfile = workflowAnalysisProfile(profile, "trace_feature");
source.record({
target,
profile,
operation: "procedure_info",
recordProcedureInfo(
source,
parameters,
execution: createAnalysisExecution("direct", ANALYSIS_SNAPSHOT_PROVIDER, {
createAnalysisExecution("direct", ANALYSIS_SNAPSHOT_PROVIDER, {
subject: target,
analysisProfile: profile,
}),
});
);
source.recordWorkflow({
target,
profile,
@@ -471,22 +482,16 @@ it("rebinds replayed target subjects while preserving child artifact subjects",
const relocatedTarget = { ...target, path: "/tmp/relocated-app" };
const parameters = { address: "0x1000" };
const locations = [{ kind: "address" as const, address: "0x1000" }];
cache.record({
target,
profile,
operation: "procedure_info",
recordProcedureInfo(
cache,
parameters,
execution: createAnalysisExecution(
{ name: "main" },
ANALYSIS_SNAPSHOT_PROVIDER,
{
subject: target,
rawResult: { provider: "raw" },
locations,
analysisProfile: profile,
},
),
});
createAnalysisExecution({ name: "main" }, ANALYSIS_SNAPSHOT_PROVIDER, {
subject: target,
rawResult: { provider: "raw" },
locations,
analysisProfile: profile,
}),
);
const replayedTarget = cache.lookup(
relocatedTarget,
@@ -504,17 +509,14 @@ it("rebinds replayed target subjects while preserving child artifact subjects",
format: "zip" as const,
};
const childParameters = { address: "0x2000" };
cache.record({
target,
profile,
operation: "procedure_info",
parameters: childParameters,
execution: createAnalysisExecution(
{ name: "child" },
ANALYSIS_SNAPSHOT_PROVIDER,
{ subject: childSubject, analysisProfile: profile },
),
});
recordProcedureInfo(
cache,
childParameters,
createAnalysisExecution({ name: "child" }, ANALYSIS_SNAPSHOT_PROVIDER, {
subject: childSubject,
analysisProfile: profile,
}),
);
expect(
cache.lookup(relocatedTarget, profile, "procedure_info", childParameters)
?.subject,
@@ -533,13 +535,7 @@ it("binds an omitted subject to the selected target in snapshot replay", () => {
{ analysisProfile: profile },
);
expect(execution).not.toHaveProperty("subject");
cache.record({
target,
profile,
operation: "procedure_info",
parameters,
execution,
});
recordProcedureInfo(cache, parameters, execution);
const snapshot = cache.export(
target,
@@ -579,17 +575,14 @@ it("preserves an explicitly unbound subject through snapshot replay", () => {
const target = ANALYSIS_SNAPSHOT_TARGET;
const profile = ANALYSIS_SNAPSHOT_PROFILE;
const parameters = { address: "0x3000" };
cache.record({
target,
profile,
operation: "procedure_info",
recordProcedureInfo(
cache,
parameters,
execution: createAnalysisExecution(
{ name: "unbound" },
ANALYSIS_SNAPSHOT_PROVIDER,
{ subject: null, analysisProfile: profile },
),
});
createAnalysisExecution({ name: "unbound" }, ANALYSIS_SNAPSHOT_PROVIDER, {
subject: null,
analysisProfile: profile,
}),
);
expect(
cache.lookup(
@@ -1403,21 +1396,15 @@ it("declines source-bearing snapshot entries while replaying omitted and empty s
result: "observed source",
});
const parameters = { address: "0x1000", document: "fixture" };
cache.record({
target,
profile,
operation: "procedure_info",
recordProcedureInfo(
cache,
parameters,
execution: createAnalysisExecution(
"parent observation",
ANALYSIS_SNAPSHOT_PROVIDER,
{
subject: target,
analysisProfile: profile,
sourceEvidence: [source],
},
),
});
createAnalysisExecution("parent observation", ANALYSIS_SNAPSHOT_PROVIDER, {
subject: target,
analysisProfile: profile,
sourceEvidence: [source],
}),
);
expect(
cache.lookup(target, profile, "procedure_info", parameters),
).toBeUndefined();
@@ -1428,12 +1415,10 @@ it("declines source-bearing snapshot entries while replaying omitted and empty s
address: sourceEvidence === undefined ? "0x2000" : "0x3000",
document: "fixture",
};
cache.record({
target,
profile,
operation: "procedure_info",
parameters: control,
execution: createAnalysisExecution(
recordProcedureInfo(
cache,
control,
createAnalysisExecution(
"source-free observation",
ANALYSIS_SNAPSHOT_PROVIDER,
{
@@ -1442,7 +1427,7 @@ it("declines source-bearing snapshot entries while replaying omitted and empty s
...(sourceEvidence === undefined ? {} : { sourceEvidence }),
},
),
});
);
expect(
cache.lookup(target, profile, "procedure_info", control)?.result,
).toBe("source-free observation");