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

CheckpointService.test.ts

158 lines5.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 VcsProcessExitError,
11 VcsProcessTimeoutError,
12 VcsUnsupportedOperationError,
13} from "@t3tools/contracts";
14import * as DateTime from "effect/DateTime";
15import * as Effect from "effect/Effect";
16import * as Layer from "effect/Layer";
17​
18import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
19import * as CheckpointService from "./CheckpointService.ts";
20import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
21​
22it.effect(
23 "skips unsupported baseline and turn checkpoints without swallowing capture failures",
24 () =>
25 Effect.gen(function* () {
26 const scope: OrchestrationV2CheckpointScope = {
27 id: CheckpointScopeId.make("checkpoint-scope:capture-failure"),
28 threadId: ThreadId.make("thread:capture-failure"),
29 runId: RunId.make("run:capture-failure:1"),
30 nodeId: NodeId.make("node:capture-failure:1"),
31 parentScopeId: null,
32 providerThreadId: ProviderThreadId.make("provider-thread:capture-failure"),
33 kind: "root_run",
34 ordinalWithinParent: 0,
35 advancesAppRunCount: true,
36 cwd: "/repo/ignored",
37 createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
38 };
39 for (const captureError of [
40 new VcsProcessTimeoutError({
41 operation: "test.capture",
42 command: "git",
43 cwd: scope.cwd,
44 timeoutMs: 30000,
45 }),
46 new VcsUnsupportedOperationError({
47 operation: "test.capture",
48 kind: "git",
49 detail: "The workspace directory is ignored by its Git repository.",
50 }),
51 ]) {
52 const layerTest = CheckpointService.layer.pipe(
53 Layer.provide(
54 Layer.mergeAll(
55 IdAllocator.layer,
56 Layer.mock(CheckpointStore.CheckpointStore)({
57 isGitRepository: () => Effect.succeed(true),
58 hasCheckpointRef: () => Effect.succeed(false),
59 captureCheckpoint: () => Effect.fail(captureError),
60 }),
61 ),
62 ),
63 Layer.provideMerge(NodeCrypto.layer),
64 );
65 yield* Effect.gen(function* () {
66 const checkpoints = yield* CheckpointService.CheckpointServiceV2;
67 const baseline = yield* Effect.result(
68 checkpoints.captureBaseline({ scope, ordinalWithinScope: 0 }),
69 );
70 const checkpoint = yield* checkpoints.capture({
71 scope,
72 ordinalWithinScope: 1,
73 runId: scope.runId!,
74 nodeId: scope.nodeId!,
75 appRunOrdinal: 1,
76 capturedAt: scope.createdAt,
77 });
78​
79 assert.deepEqual(
80 { baseline: baseline._tag, turn: checkpoint.status, files: checkpoint.files },
81 captureError._tag === "VcsUnsupportedOperationError"
82 ? { baseline: "Success", turn: "missing", files: [] }
83 : { baseline: "Failure", turn: "error", files: [] },
84 );
85 if (baseline._tag === "Failure") {
86 assert.strictEqual(baseline.failure.cause, captureError);
87 } else {
88 const materialized = yield* checkpoints.materializeBaselineCheckpoint({
89 scope,
90 ordinalWithinScope: 0,
91 nodeId: scope.nodeId,
92 capturedAt: scope.createdAt,
93 });
94 assert.strictEqual(materialized.status, "missing");
95 }
96 }).pipe(Effect.provide(layerTest));
97 }
98 }),
99);
100​
101it.effect("records a repository probe failure as an error checkpoint, not a missing one", () =>
102 Effect.gen(function* () {
103 const scope: OrchestrationV2CheckpointScope = {
104 id: CheckpointScopeId.make("checkpoint-scope:probe-failure"),
105 threadId: ThreadId.make("thread:probe-failure"),
106 runId: RunId.make("run:probe-failure:1"),
107 nodeId: NodeId.make("node:probe-failure:1"),
108 parentScopeId: null,
109 providerThreadId: ProviderThreadId.make("provider-thread:probe-failure"),
110 kind: "root_run",
111 ordinalWithinParent: 0,
112 advancesAppRunCount: true,
113 cwd: "/repo/bad-config",
114 createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
115 };
116 const layerTest = CheckpointService.layer.pipe(
117 Layer.provide(
118 Layer.mergeAll(
119 IdAllocator.layer,
120 Layer.mock(CheckpointStore.CheckpointStore)({
121 isGitRepository: () =>
122 Effect.fail(
123 new VcsProcessExitError({
124 operation: "GitVcsDriver.detectRepository",
125 command: "git",
126 cwd: scope.cwd,
127 exitCode: 128,
128 detail: "fatal: bad config line 1 in file .git/config",
129 }),
130 ),
131 }),
132 ),
133 ),
134 Layer.provideMerge(NodeCrypto.layer),
135 );
136​
137 const statuses = yield* Effect.gen(function* () {
138 const checkpoints = yield* CheckpointService.CheckpointServiceV2;
139 const baseline = yield* checkpoints.materializeBaselineCheckpoint({
140 scope,
141 ordinalWithinScope: 0,
142 nodeId: scope.nodeId,
143 capturedAt: scope.createdAt,
144 });
145 const turn = yield* checkpoints.capture({
146 scope,
147 ordinalWithinScope: 1,
148 runId: scope.runId!,
149 nodeId: scope.nodeId!,
150 appRunOrdinal: 1,
151 capturedAt: scope.createdAt,
152 });
153 return { baseline: baseline.status, turn: turn.status };
154 }).pipe(Effect.provide(layerTest));
155​
156 assert.deepEqual(statuses, { baseline: "error", turn: "error" });
157 }),
158);