Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CheckpointService.test.ts

72 lines2.2 KB

1import { assert, it, vi } from "@effect/vitest";
2import {
3 CheckpointScopeId,
4 NodeId,
5 ProviderThreadId,
6 RunId,
7 ThreadId,
8 type OrchestrationV2CheckpointScope,
9} from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11import * as Effect from "effect/Effect";
12import * as Layer from "effect/Layer";
13​
14import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
15import {
16 CheckpointServiceV2,
17 checkpointRefForScopeOrdinal,
18 layer as checkpointServiceLayer,
19} from "./CheckpointService.ts";
20import { layer as idAllocatorLayer } from "./IdAllocator.ts";
21​
22it.effect("materializes the captured baseline at the requested scope ordinal", () => {
23 const scope: OrchestrationV2CheckpointScope = {
24 id: CheckpointScopeId.make("checkpoint-scope:materialize-baseline"),
25 threadId: ThreadId.make("thread:materialize-baseline"),
26 runId: RunId.make("run:materialize-baseline:3"),
27 nodeId: NodeId.make("node:materialize-baseline:3"),
28 parentScopeId: null,
29 providerThreadId: ProviderThreadId.make("provider-thread:materialize-baseline"),
30 kind: "root_run",
31 ordinalWithinParent: 0,
32 advancesAppRunCount: true,
33 cwd: "/repo",
34 createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
35 };
36 const hasCheckpointRef = vi.fn((_input: CheckpointStore.RestoreCheckpointInput) =>
37 Effect.succeed(true),
38 );
39 const testLayer = checkpointServiceLayer.pipe(
40 Layer.provide(
41 Layer.mergeAll(
42 idAllocatorLayer,
43 Layer.mock(CheckpointStore.CheckpointStore)({
44 isGitRepository: () => Effect.succeed(true),
45 hasCheckpointRef,
46 }),
47 ),
48 ),
49 );
50​
51 return Effect.gen(function* () {
52 const checkpoints = yield* CheckpointServiceV2;
53 const baseline = yield* checkpoints.materializeBaselineCheckpoint({
54 scope,
55 ordinalWithinScope: 2,
56 });
57​
58 assert.equal(baseline.ordinalWithinScope, 2);
59 assert.equal(
60 baseline.ref,
61 checkpointRefForScopeOrdinal({
62 scopeId: scope.id,
63 ordinalWithinScope: 2,
64 }),
65 );
66 assert.equal(baseline.status, "ready");
67 assert.deepEqual(hasCheckpointRef.mock.calls[0]?.[0], {
68 cwd: scope.cwd,
69 checkpointRef: baseline.ref,
70 });
71 }).pipe(Effect.provide(testLayer));
72});