@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 52 lines 2.03 KB
Raw
1 import { describe, expect } from "@alchemy.run/test";
2 import * as Test from "@alchemy.run/test/Alchemy";
3 import * as Effect from "effect/Effect";
4 import * as Exit from "effect/Exit";
5 import { DuplicateLogicalIdError } from "@/Resource";
6 import { Bucket, Queue, TestLayers } from "./test.resources.ts";
7
8 const { test } = Test.make({ providers: TestLayers() });
9
10 describe("logical ids", { tags: ["unit", "local"] }, () => {
11 test.provider("a second type under the same logical id dies", (stack) =>
12 Effect.gen(function* () {
13 const exit = yield* Effect.gen(function* () {
14 yield* Bucket("Thing", { name: "topic" });
15 yield* Queue("Thing", { name: "queue" });
16 return {};
17 }).pipe(stack.deploy, Effect.exit);
18
19 expect(Exit.isFailure(exit)).toBe(true);
20 if (Exit.isFailure(exit)) {
21 const defects = exit.cause.reasons.flatMap((reason) =>
22 reason._tag === "Die" && reason.defect instanceof DuplicateLogicalIdError
23 ? [reason.defect]
24 : [],
25 );
26 const duplicate = defects.find((defect) => defect._tag === "DuplicateLogicalIdError");
27 expect(duplicate?.fqn).toEqual("Thing");
28 expect(duplicate?.existingType).toEqual("Test.Bucket");
29 expect(duplicate?.conflictingType).toEqual("Test.Queue");
30 expect(duplicate?.message).toContain("'Thing'");
31 expect(duplicate?.message).toContain("'Test.Bucket'");
32 expect(duplicate?.message).toContain("'Test.Queue'");
33 }
34 }),
35 );
36
37 test.provider("yielding the same logical id returns the registered resource", (stack) =>
38 Effect.gen(function* () {
39 const output = yield* Effect.gen(function* () {
40 const first = yield* Bucket("Thing", { name: "a" });
41 const again = yield* Bucket("Thing", { name: "a" });
42 const reference = yield* Bucket("Thing");
43 return { first, again, reference };
44 }).pipe(stack.deploy);
45
46 expect(output.again).toBe(output.first);
47 expect(output.reference).toBe(output.first);
48
49 yield* stack.destroy();
50 }),
51 );
52 });