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

CheckpointService.test.ts

98 lines3.6 KB

1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import { assert, it } from "@effect/vitest";
3import {
4 CheckpointScopeId,
5 NodeId,
6 ProviderThreadId,
7 RunId,
8 ThreadId,
9 type OrchestrationV2CheckpointScope,
10 VcsProcessTimeoutError,
11 VcsUnsupportedOperationError,
12} from "@t3tools/contracts";
13import * as DateTime from "effect/DateTime";
14import * as Effect from "effect/Effect";
15import * as Layer from "effect/Layer";
16​
17import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
18import * as CheckpointService from "./CheckpointService.ts";
19import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
20​
21it.effect(
22 "skips unsupported baseline and turn checkpoints without swallowing capture failures",
23 () =>
24 Effect.gen(function* () {
25 const scope: OrchestrationV2CheckpointScope = {
26 id: CheckpointScopeId.make("checkpoint-scope:capture-failure"),
27 threadId: ThreadId.make("thread:capture-failure"),
28 runId: RunId.make("run:capture-failure:1"),
29 nodeId: NodeId.make("node:capture-failure:1"),
30 parentScopeId: null,
31 providerThreadId: ProviderThreadId.make("provider-thread:capture-failure"),
32 kind: "root_run",
33 ordinalWithinParent: 0,
34 advancesAppRunCount: true,
35 cwd: "/repo/ignored",
36 createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
37 };
38 for (const captureError of [
39 new VcsProcessTimeoutError({
40 operation: "test.capture",
41 command: "git",
42 cwd: scope.cwd,
43 timeoutMs: 30000,
44 }),
45 new VcsUnsupportedOperationError({
46 operation: "test.capture",
47 kind: "git",
48 detail: "The workspace directory is ignored by its Git repository.",
49 }),
50 ]) {
51 const layerTest = CheckpointService.layer.pipe(
52 Layer.provide(
53 Layer.mergeAll(
54 IdAllocator.layer,
55 Layer.mock(CheckpointStore.CheckpointStore)({
56 isGitRepository: () => Effect.succeed(true),
57 hasCheckpointRef: () => Effect.succeed(false),
58 captureCheckpoint: () => Effect.fail(captureError),
59 }),
60 ),
61 ),
62 Layer.provideMerge(NodeCrypto.layer),
63 );
64 yield* Effect.gen(function* () {
65 const checkpoints = yield* CheckpointService.CheckpointServiceV2;
66 const baseline = yield* Effect.result(
67 checkpoints.captureBaseline({ scope, ordinalWithinScope: 0 }),
68 );
69 const checkpoint = yield* checkpoints.capture({
70 scope,
71 ordinalWithinScope: 1,
72 runId: scope.runId!,
73 nodeId: scope.nodeId!,
74 appRunOrdinal: 1,
75 capturedAt: scope.createdAt,
76 });
77​
78 assert.deepEqual(
79 { baseline: baseline._tag, turn: checkpoint.status, files: checkpoint.files },
80 captureError._tag === "VcsUnsupportedOperationError"
81 ? { baseline: "Success", turn: "missing", files: [] }
82 : { baseline: "Failure", turn: "error", files: [] },
83 );
84 if (baseline._tag === "Failure") {
85 assert.strictEqual(baseline.failure.cause, captureError);
86 } else {
87 const materialized = yield* checkpoints.materializeBaselineCheckpoint({
88 scope,
89 ordinalWithinScope: 0,
90 nodeId: scope.nodeId,
91 capturedAt: scope.createdAt,
92 });
93 assert.strictEqual(materialized.status, "missing");
94 }
95 }).pipe(Effect.provide(layerTest));
96 }
97 }),
98);