Open History to see the last commit
1import { assert, it, vi } from "@effect/vitest";
2import {
3 CheckpointScopeId,
4 NodeId,
5 ProviderThreadId,
6 RunId,
7 ThreadId,
8 type OrchestrationV2CheckpointScope,
9 VcsProcessTimeoutError,
10} from "@t3tools/contracts";
11import * as DateTime from "effect/DateTime";
12import * as Effect from "effect/Effect";
13import * as Exit from "effect/Exit";
14import * as Layer from "effect/Layer";
15
16import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
17import {
18 CheckpointServiceV2,
19 checkpointRefForScopeOrdinal,
20 layer as checkpointServiceLayer,
21} from "./CheckpointService.ts";
22import { layer as idAllocatorLayer } from "./IdAllocator.ts";
23
24it.effect.each([false, true, "interrupt"] as const)(
25 "materializes baseline, lookup fails=%s",
26 (lookupFails) => {
27 const scope: OrchestrationV2CheckpointScope = {
28 id: CheckpointScopeId.make("checkpoint-scope:materialize-baseline"),
29 threadId: ThreadId.make("thread:materialize-baseline"),
30 runId: RunId.make("run:materialize-baseline:3"),
31 nodeId: NodeId.make("node:materialize-baseline:3"),
32 parentScopeId: null,
33 providerThreadId: ProviderThreadId.make("provider-thread:materialize-baseline"),
34 kind: "root_run",
35 ordinalWithinParent: 0,
36 advancesAppRunCount: true,
37 cwd: "/repo",
38 createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
39 };
40 const hasCheckpointRef = vi.fn((_input: CheckpointStore.RestoreCheckpointInput) =>
41 lookupFails === "interrupt"
42 ? Effect.interrupt
43 : lookupFails
44 ? Effect.fail(
45 new VcsProcessTimeoutError({
46 operation: "test.ref",
47 command: "git",
48 cwd: "/repo",
49 timeoutMs: 30000,
50 }),
51 )
52 : Effect.succeed(true),
53 );
54 const testLayer = checkpointServiceLayer.pipe(
55 Layer.provide(
56 Layer.mergeAll(
57 idAllocatorLayer,
58 Layer.mock(CheckpointStore.CheckpointStore)({
59 isGitRepository: () => Effect.succeed(true),
60 hasCheckpointRef,
61 captureCheckpoint: () => Effect.void,
62 }),
63 ),
64 ),
65 );
66
67 return Effect.gen(function* () {
68 const checkpoints = yield* CheckpointServiceV2;
69 if (lookupFails === "interrupt") {
70 const exit = yield* Effect.exit(
71 checkpoints.materializeBaselineCheckpoint({ scope, ordinalWithinScope: 2 }),
72 );
73 assert.isTrue(Exit.hasInterrupts(exit));
74 const captureExit = yield* Effect.exit(
75 checkpoints.capture({
76 scope,
77 ordinalWithinScope: 1,
78 runId: scope.runId!,
79 nodeId: scope.nodeId!,
80 appRunOrdinal: 1,
81 capturedAt: scope.createdAt,
82 }),
83 );
84 assert.isTrue(Exit.hasInterrupts(captureExit));
85 return;
86 }
87 const baseline = yield* checkpoints.materializeBaselineCheckpoint({
88 scope,
89 ordinalWithinScope: 2,
90 });
91
92 assert.equal(baseline.ordinalWithinScope, 2);
93 assert.equal(
94 baseline.ref,
95 checkpointRefForScopeOrdinal({
96 scopeId: scope.id,
97 ordinalWithinScope: 2,
98 }),
99 );
100 assert.equal(baseline.status, lookupFails ? "missing" : "ready");
101 assert.deepEqual(hasCheckpointRef.mock.calls[0]?.[0], {
102 cwd: scope.cwd,
103 checkpointRef: baseline.ref,
104 });
105 }).pipe(Effect.provide(testLayer));
106 },
107);