import { assert, it, vi } from "@effect/vitest"; import { CheckpointScopeId, RunId, ThreadId, type OrchestrationV2ThreadProjection, } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as CheckpointCapture from "./CheckpointCaptureService.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as RunFinalization from "./RunFinalizationService.ts"; it.effect("captures the root checkpoint and refreshes workspace state", () => { const threadId = ThreadId.make("thread_finalize"); const runId = RunId.make("run_finalize"); const scopeId = CheckpointScopeId.make("scope_finalize"); const capture = vi.fn(() => Effect.void); const refresh = vi.fn(() => Effect.void); const projection = { checkpointScopes: [{ id: scopeId, cwd: "/repo" }], } as unknown as OrchestrationV2ThreadProjection; const layer = RunFinalization.layer.pipe( Layer.provide( Layer.mergeAll( Layer.mock(CheckpointCapture.CheckpointCaptureServiceV2)({ execute: capture }), Layer.mock(ProjectionStore.ProjectionStoreV2)({ getThreadProjection: () => Effect.succeed(projection), }), Layer.succeed(RunFinalization.RunFinalizationObserver, { refresh }), ), ), ); return Effect.gen(function* () { const service = yield* RunFinalization.RunFinalizationService; yield* service.finalize({ threadId, runId, scopeId }); assert.equal(capture.mock.calls.length, 1); assert.deepEqual(refresh.mock.calls[0], ["/repo"]); }).pipe(Effect.provide(layer)); });