| 1 | import { EnvironmentId, type OrchestrationV2ArchivedShellSnapshot } from "@t3tools/contracts"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity"; |
| 4 | import { expect, it } from "vite-plus/test"; |
| 5 | |
| 6 | import { |
| 7 | createArchivedThreadSnapshotsAtomFamily, |
| 8 | makeArchivedThreadsEnvironmentKey, |
| 9 | parseArchivedThreadsEnvironmentKey, |
| 10 | } from "./archivedThreads.ts"; |
| 11 | |
| 12 | it("round-trips environment keys in sorted order", () => { |
| 13 | const envA = EnvironmentId.make("env-a"); |
| 14 | const envB = EnvironmentId.make("env-b"); |
| 15 | const key = makeArchivedThreadsEnvironmentKey([envB, envA]); |
| 16 | |
| 17 | expect(parseArchivedThreadsEnvironmentKey(key)).toEqual([envA, envB]); |
| 18 | }); |
| 19 | |
| 20 | it("does not expose an archived snapshot failure message", () => { |
| 21 | const environmentId = EnvironmentId.make("env-sensitive"); |
| 22 | const snapshotsAtom = createArchivedThreadSnapshotsAtomFamily<Error>({ |
| 23 | getSnapshotAtom: () => |
| 24 | Atom.make( |
| 25 | AsyncResult.failure<OrchestrationV2ArchivedShellSnapshot, Error>( |
| 26 | Cause.fail(new Error("credential=secret-value")), |
| 27 | ), |
| 28 | ), |
| 29 | labelPrefix: "test:archived-thread-snapshots", |
| 30 | }); |
| 31 | const registry = AtomRegistry.make(); |
| 32 | |
| 33 | expect(registry.get(snapshotsAtom(makeArchivedThreadsEnvironmentKey([environmentId])))).toEqual({ |
| 34 | snapshots: [], |
| 35 | error: "Failed to load archived threads.", |
| 36 | isLoading: false, |
| 37 | }); |
| 38 | |
| 39 | registry.dispose(); |
| 40 | }); |