fix(snapshot): replay validated workflow evidence (#984)

* fix(snapshot): bind replay to validated cache entry

* fix(snapshot): persist composed workflow results

* fix(snapshot): enforce workflow replay identity

* fix(snapshot): honor cancellation after route resolution

* test(snapshot): make cancellation race deterministic

* fix(snapshot): replay all composed workflow evidence

* fix(snapshot): index workflow evidence once per snapshot

Validate workflow entries against a query and content index instead of scanning the evidence bundle for every entry.

* fix(snapshot): reuse previewed routes and bound workflow cache

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-08 01:33:39 +08:00
committed by GitHub
co-authored by Cursor Agent
parent 96a46ada0a
commit 1d62e54e1f
11 changed files with 1462 additions and 80 deletions
@@ -3,6 +3,7 @@ import type {
AnalysisProvider,
} from "../../../src/application/AnalysisProvider.js";
import type { BinarySession } from "../../../src/application/binary/BinarySession.js";
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
import type { JsonValue } from "../../../src/domain/jsonValue.js";
import type { RecordUnknownInput } from "../../../src/domain/residualUnknown.js";
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
@@ -159,6 +160,65 @@ describe("detached provider and target metadata", () => {
});
});
describe("opening previewed targets", () => {
it("rechecks the active target after another serialized transition", async () => {
const [first, second] = await createBinarySessionTargets();
const calls: string[] = [];
const session = createTestBinarySession(createCacheProvider(calls));
try {
expect((await session.open(first)).ok).toBe(true);
const target = session.activeTarget();
if (target === undefined) throw new Error("Expected an active target");
const preview = await session.previewTarget(target);
if (!preview.ok) throw preview.error;
expect(preview.value.sameTarget).toBe(true);
expect((await session.open(second)).ok).toBe(true);
expect((await session.openResolvedTarget(preview.value)).ok).toBe(true);
expect(session.activeTarget()?.path).toBe(first);
expect(calls).toEqual(["health", "health", "health"]);
} finally {
await session.close();
}
});
it("rejects cancellation and a staged snapshot changed after preview without startup", async () => {
const [first, second] = await createBinarySessionTargets();
const calls: string[] = [];
const session = createTestBinarySession(createCacheProvider(calls));
const other = createTestBinarySession(createCacheProvider([]));
try {
const parsed = await parseBinaryTarget(first);
if (!parsed.ok) throw parsed.error;
const preview = await session.previewTarget(parsed.value);
if (!preview.ok) throw preview.error;
const controller = new AbortController();
controller.abort();
const cancelled = await session.openResolvedTarget(preview.value, {
signal: controller.signal,
});
expect(cancelled).toMatchObject({
ok: false,
error: { _tag: "AnalysisCancelledError" },
});
expect((await other.open(second)).ok).toBe(true);
const snapshot = other.exportAnalysisSnapshot();
if (!snapshot.ok) throw snapshot.error;
expect(session.importAnalysisSnapshot(snapshot.value).ok).toBe(true);
const rejected = await session.openResolvedTarget(preview.value);
expect(rejected).toMatchObject({
ok: false,
error: { _tag: "EvidenceIntegrityError" },
});
expect(calls).toEqual([]);
expect(session.activeTarget()).toBeUndefined();
} finally {
await session.close();
await other.close();
}
});
});
describe("non-hopper provider dispatch", () => {
it("runs through a non-Hopper analysis provider", async () => {
const [first] = await createBinarySessionTargets();