The best way to control Claude Code, Codex and more from any computer or phone

main
ts 55 lines 1.69 KB
Raw
1 import { describe, expect, it } from "@alchemy.run/test";
2 import * as Effect from "effect/Effect";
3 import { inMemoryState } from "@/State/InMemoryState.ts";
4 import type { ResourceState } from "@/State/ResourceState.ts";
5 import { deleteState, listState, readState } from "@/State/Tree.ts";
6
7 const resource = {
8 resourceType: "test:resource",
9 namespace: undefined,
10 fqn: "resource",
11 logicalId: "resource",
12 instanceId: "instance-resource",
13 providerVersion: 1,
14 status: "created",
15 downstream: [],
16 bindings: [],
17 props: {},
18 attr: { value: 1 },
19 } as ResourceState;
20
21 const state = () =>
22 inMemoryState({ app: { dev: { resource } } }, { app: { dev: { url: "https://example.com" } } });
23
24 describe("State tree", { tags: ["unit", "local"] }, () => {
25 it.effect("queries state as structured data", () =>
26 Effect.gen(function* () {
27 expect(yield* listState({})).toEqual(["app/"]);
28 expect(yield* listState({ path: "app/dev", recursive: true })).toEqual([
29 "app/dev/resource",
30 "app/dev/output",
31 ]);
32
33 expect(yield* readState({ path: "app/dev/output" })).toEqual([
34 {
35 path: "app/dev/output",
36 kind: "output",
37 value: { url: "https://example.com" },
38 },
39 ]);
40 }).pipe(Effect.provide(state())),
41 );
42
43 it.effect("deletes subtrees and reports what was removed", () =>
44 Effect.gen(function* () {
45 const deleted = yield* deleteState({ path: "app/dev", recursive: true });
46
47 expect(deleted).toEqual({
48 _tag: "StateDeleted",
49 path: "app/dev",
50 deleted: ["app/dev/resource", "app/dev/output"],
51 });
52 expect(yield* listState({ path: "app" })).toEqual([]);
53 }).pipe(Effect.provide(state())),
54 );
55 });