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

orchestrationCache.test.ts

59 lines2.0 KB

1import { describe, expect, it } from "@effect/vitest";
2import { EnvironmentId } from "@t3tools/contracts";
3import * as Effect from "effect/Effect";
4import * as Option from "effect/Option";
5import * as Schema from "effect/Schema";
6​
7import {
8 ORCHESTRATION_CACHE_SCHEMA_VERSION,
9 StoredOrchestrationShellSnapshot,
10 StoredOrchestrationThreadSnapshot,
11 decodeOrDiscardOrchestrationCache,
12} from "./orchestrationCache.ts";
13import { v2Projection, v2ShellSnapshot, v2ThreadId } from "../state/orchestrationV2TestFixtures.ts";
14​
15const environmentId = EnvironmentId.make("environment-cache-test");
16const decodeStoredShellSnapshot = Schema.decodeUnknownEffect(StoredOrchestrationShellSnapshot);
17const decodeStoredThreadSnapshot = Schema.decodeUnknownEffect(StoredOrchestrationThreadSnapshot);
18​
19describe("orchestration cache envelopes", () => {
20 it.effect("accepts V2 shell and thread cache envelopes", () =>
21 Effect.gen(function* () {
22 const shell = yield* decodeStoredShellSnapshot({
23 schemaVersion: ORCHESTRATION_CACHE_SCHEMA_VERSION,
24 environmentId,
25 snapshot: v2ShellSnapshot,
26 });
27 const thread = yield* decodeStoredThreadSnapshot({
28 schemaVersion: ORCHESTRATION_CACHE_SCHEMA_VERSION,
29 environmentId,
30 threadId: v2ThreadId,
31 thread: v2Projection,
32 });
33​
34 expect(shell.snapshot).toEqual(v2ShellSnapshot);
35 expect(thread.thread).toEqual(v2Projection);
36 }),
37 );
38​
39 it.effect("discards V1-versioned cache envelopes after a decode failure", () =>
40 Effect.gen(function* () {
41 let discardCount = 0;
42 const decoded = decodeStoredShellSnapshot({
43 schemaVersion: 1,
44 environmentId,
45 snapshot: v2ShellSnapshot,
46 }).pipe(Effect.map(Option.some));
47​
48 const result = yield* decodeOrDiscardOrchestrationCache(
49 decoded,
50 Effect.sync(() => {
51 discardCount += 1;
52 }),
53 );
54​
55 expect(Option.isNone(result)).toBe(true);
56 expect(discardCount).toBe(1);
57 }),
58 );
59});