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

main
ts 101 lines 3.7 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Room } from "@alchemy.run/aws/IVSChat";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ivschat from "@distilled.cloud/aws/ivschat";
6 import * as sts from "@distilled.cloud/aws/sts";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // Ungated typed-error probe: proves the distilled error union carries the
13 // not-found tag this provider's read/delete paths depend on.
14 test.provider(
15 "getRoom on a nonexistent ARN fails with ResourceNotFoundException",
16 () =>
17 Effect.gen(function* () {
18 const region = yield* yield* AWS.Region;
19 const { Account } = yield* sts.getCallerIdentity({});
20 const error = yield* Effect.flip(
21 ivschat.getRoom({
22 identifier: `arn:aws:ivschat:${region}:${Account}:room/AbCdEfGh1234`,
23 }),
24 );
25 expect(error._tag).toBe("ResourceNotFoundException");
26 }),
27 { tags: ["provider:aws", "provider:aws:ivschat", "live"], timeout: 60_000 },
28 );
29
30 const assertRoomGone = (arn: string) =>
31 Effect.gen(function* () {
32 const room = yield* ivschat.getRoom({ identifier: arn }).pipe(
33 Effect.map((r) => r.arn),
34 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
35 );
36 if (room !== undefined) {
37 return yield* Effect.fail(new Error(`room '${arn}' still exists`));
38 }
39 }).pipe(
40 Effect.retry({
41 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
42 }),
43 );
44
45 // Rooms are free and provision synchronously — the full lifecycle
46 // (create, no-op, update-in-place, destroy) runs ungated.
47 test.provider(
48 "create, update, and destroy an IVS Chat room",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const props = {
54 roomName: "alchemy-test-ivschat-room",
55 maximumMessageRatePerSecond: 5,
56 maximumMessageLength: 200,
57 tags: { fixture: "ivschat-room" },
58 };
59
60 // Create.
61 const created = yield* stack.deploy(Room("Chat", props));
62 expect(created.roomName).toBe("alchemy-test-ivschat-room");
63 expect(created.roomArn).toContain(":room/");
64 expect(created.roomId).toBeDefined();
65
66 // Out-of-band verification via distilled.
67 const observed = yield* ivschat.getRoom({ identifier: created.roomArn });
68 expect(observed.name).toBe("alchemy-test-ivschat-room");
69 expect(observed.maximumMessageRatePerSecond).toBe(5);
70 expect(observed.maximumMessageLength).toBe(200);
71 expect(observed.tags?.fixture).toBe("ivschat-room");
72 expect(observed.tags?.["alchemy::id"]).toBe("Chat");
73
74 // No-op redeploy keeps the same room.
75 const noop = yield* stack.deploy(Room("Chat", props));
76 expect(noop.roomArn).toBe(created.roomArn);
77
78 // Update in place — message limits and name are mutable; the ARN
79 // must not change.
80 const updated = yield* stack.deploy(
81 Room("Chat", {
82 ...props,
83 roomName: "alchemy-test-ivschat-room-b",
84 maximumMessageLength: 300,
85 }),
86 );
87 expect(updated.roomArn).toBe(created.roomArn);
88 expect(updated.roomName).toBe("alchemy-test-ivschat-room-b");
89
90 const reobserved = yield* ivschat.getRoom({
91 identifier: created.roomArn,
92 });
93 expect(reobserved.name).toBe("alchemy-test-ivschat-room-b");
94 expect(reobserved.maximumMessageLength).toBe(300);
95
96 // Destroy and verify out-of-band with a typed wait-until-gone.
97 yield* stack.destroy();
98 yield* assertRoomGone(created.roomArn);
99 }),
100 { tags: ["provider:aws", "provider:aws:ivschat", "live"], timeout: 240_000 },
101 );