Open History to see the last commit
1import { assert, it, vi } from "@effect/vitest";
2import {
3 CheckpointScopeId,
4 RunId,
5 ThreadId,
6 type OrchestrationV2ThreadProjection,
7} from "@t3tools/contracts";
8import * as Effect from "effect/Effect";
9import * as Layer from "effect/Layer";
10
11import * as CheckpointCapture from "./CheckpointCaptureService.ts";
12import * as ProjectionStore from "./ProjectionStore.ts";
13import * as RunFinalization from "./RunFinalizationService.ts";
14
15it.effect("captures the root checkpoint and refreshes workspace state", () => {
16 const threadId = ThreadId.make("thread_finalize");
17 const runId = RunId.make("run_finalize");
18 const scopeId = CheckpointScopeId.make("scope_finalize");
19 const capture = vi.fn(() => Effect.void);
20 const refresh = vi.fn(() => Effect.void);
21 const projection = {
22 checkpointScopes: [{ id: scopeId, cwd: "/repo" }],
23 } as unknown as OrchestrationV2ThreadProjection;
24 const layer = RunFinalization.layer.pipe(
25 Layer.provide(
26 Layer.mergeAll(
27 Layer.mock(CheckpointCapture.CheckpointCaptureServiceV2)({ execute: capture }),
28 Layer.mock(ProjectionStore.ProjectionStoreV2)({
29 getThreadProjection: () => Effect.succeed(projection),
30 }),
31 Layer.succeed(RunFinalization.RunFinalizationObserver, { refresh }),
32 ),
33 ),
34 );
35 return Effect.gen(function* () {
36 const service = yield* RunFinalization.RunFinalizationService;
37 yield* service.finalize({ threadId, runId, scopeId });
38 assert.equal(capture.mock.calls.length, 1);
39 assert.deepEqual(refresh.mock.calls[0], ["/repo"]);
40 }).pipe(Effect.provide(layer));
41});