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

main
ts 106 lines 4.07 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Channel } from "@alchemy.run/aws/IVS";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ivs from "@distilled.cloud/aws/ivs";
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 "getChannel 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 ivs.getChannel({
22 arn: `arn:aws:ivs:${region}:${Account}:channel/AbCdEfGh1234`,
23 }),
24 );
25 expect(error._tag).toBe("ResourceNotFoundException");
26 }),
27 { tags: ["provider:aws", "provider:aws:ivs", "live"], timeout: 60_000 },
28 );
29
30 const assertChannelGone = (arn: string) =>
31 Effect.gen(function* () {
32 const channel = yield* ivs.getChannel({ arn }).pipe(
33 Effect.map((r) => r.channel),
34 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
35 );
36 if (channel !== undefined) {
37 return yield* Effect.fail(new Error(`channel '${arn}' still exists`));
38 }
39 }).pipe(
40 Effect.retry({
41 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
42 }),
43 );
44
45 // Channels are free while idle and provision synchronously — the full
46 // lifecycle (create, no-op, update-in-place, destroy) runs ungated.
47 test.provider(
48 "create, update, and destroy an IVS channel",
49 (stack) =>
50 Effect.gen(function* () {
51 // Clean slate in case a previous run died mid-flight.
52 yield* stack.destroy();
53
54 const props = {
55 channelName: "alchemy-test-ivs-channel",
56 latencyMode: "LOW" as const,
57 type: "BASIC",
58 tags: { fixture: "ivs-channel" },
59 };
60
61 // Create.
62 const created = yield* stack.deploy(Channel("Live", props));
63 expect(created.channelName).toBe("alchemy-test-ivs-channel");
64 expect(created.channelArn).toContain(":channel/");
65 expect(created.ingestEndpoint).toBeDefined();
66 expect(created.playbackUrl).toContain("https://");
67 expect(created.type).toBe("BASIC");
68 expect(created.latencyMode).toBe("LOW");
69
70 // Out-of-band verification via distilled.
71 const observed = yield* ivs.getChannel({ arn: created.channelArn });
72 expect(observed.channel?.name).toBe("alchemy-test-ivs-channel");
73 expect(observed.channel?.type).toBe("BASIC");
74 expect(observed.channel?.tags?.fixture).toBe("ivs-channel");
75 expect(observed.channel?.tags?.["alchemy::id"]).toBe("Live");
76
77 // No-op redeploy keeps the same channel.
78 const noop = yield* stack.deploy(Channel("Live", props));
79 expect(noop.channelArn).toBe(created.channelArn);
80
81 // Update in place — latency mode, authorization, and name are all
82 // mutable; the ARN must not change.
83 const updated = yield* stack.deploy(
84 Channel("Live", {
85 ...props,
86 channelName: "alchemy-test-ivs-channel-b",
87 latencyMode: "NORMAL",
88 authorized: true,
89 }),
90 );
91 expect(updated.channelArn).toBe(created.channelArn);
92 expect(updated.channelName).toBe("alchemy-test-ivs-channel-b");
93 expect(updated.latencyMode).toBe("NORMAL");
94 expect(updated.authorized).toBe(true);
95
96 const reobserved = yield* ivs.getChannel({ arn: created.channelArn });
97 expect(reobserved.channel?.name).toBe("alchemy-test-ivs-channel-b");
98 expect(reobserved.channel?.latencyMode).toBe("NORMAL");
99 expect(reobserved.channel?.authorized).toBe(true);
100
101 // Destroy and verify out-of-band with a typed wait-until-gone.
102 yield* stack.destroy();
103 yield* assertChannelGone(created.channelArn);
104 }),
105 { tags: ["provider:aws", "provider:aws:ivs", "live"], timeout: 240_000 },
106 );