The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { SignalingChannel } from "@alchemy.run/aws/KinesisVideo"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as kv from "@distilled.cloud/aws/kinesis-video"; |
| 6 | import * as Data from "effect/Data"; |
| 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 | const findChannel = (channelName: string) => |
| 13 | kv.describeSignalingChannel({ ChannelName: channelName }).pipe( |
| 14 | Effect.map((r) => r.ChannelInfo), |
| 15 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 16 | ); |
| 17 | |
| 18 | class ChannelStillExists extends Data.TaggedError("ChannelStillExists")<{ |
| 19 | readonly channelName: string; |
| 20 | }> {} |
| 21 | |
| 22 | // DeleteSignalingChannel is asynchronous: the channel lingers in DELETING |
| 23 | // for a while — treat DELETING as deleted. |
| 24 | const assertChannelDeleted = (channelName: string) => |
| 25 | findChannel(channelName).pipe( |
| 26 | Effect.flatMap((info) => |
| 27 | info === undefined || info.ChannelStatus === "DELETING" |
| 28 | ? Effect.void |
| 29 | : Effect.fail(new ChannelStillExists({ channelName })), |
| 30 | ), |
| 31 | Effect.retry({ |
| 32 | while: (e) => e._tag === "ChannelStillExists", |
| 33 | schedule: Schedule.max([Schedule.spaced("3 seconds"), Schedule.recurs(20)]), |
| 34 | }), |
| 35 | ); |
| 36 | |
| 37 | test.provider( |
| 38 | "create, update message TTL and tags, delete signaling channel", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const channel = yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | return yield* SignalingChannel("TestSignalingChannel", { |
| 46 | tags: { Environment: "test" }, |
| 47 | }); |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | expect(channel.channelName).toBeDefined(); |
| 52 | expect(channel.channelArn).toContain(":channel/"); |
| 53 | |
| 54 | // out-of-band verification via distilled |
| 55 | const created = yield* findChannel(channel.channelName); |
| 56 | expect(created?.ChannelStatus).toBe("ACTIVE"); |
| 57 | expect(created?.ChannelType).toBe("SINGLE_MASTER"); |
| 58 | const tags = yield* kv |
| 59 | .listTagsForResource({ ResourceARN: channel.channelArn }) |
| 60 | .pipe(Effect.map((r) => r.Tags ?? {})); |
| 61 | expect(tags.Environment).toBe("test"); |
| 62 | expect(tags["alchemy::id"]).toBe("TestSignalingChannel"); |
| 63 | |
| 64 | // update the message TTL in place |
| 65 | const updated = yield* stack.deploy( |
| 66 | Effect.gen(function* () { |
| 67 | return yield* SignalingChannel("TestSignalingChannel", { |
| 68 | messageTtl: "30 seconds", |
| 69 | tags: { Environment: "test", Extra: "yes" }, |
| 70 | }); |
| 71 | }), |
| 72 | ); |
| 73 | expect(updated.channelName).toBe(channel.channelName); |
| 74 | expect(updated.channelArn).toBe(channel.channelArn); |
| 75 | |
| 76 | const afterUpdate = yield* findChannel(channel.channelName); |
| 77 | expect(afterUpdate?.SingleMasterConfiguration?.MessageTtlSeconds).toBe(30); |
| 78 | const tagsAfter = yield* kv |
| 79 | .listTagsForResource({ ResourceARN: channel.channelArn }) |
| 80 | .pipe(Effect.map((r) => r.Tags ?? {})); |
| 81 | expect(tagsAfter.Extra).toBe("yes"); |
| 82 | |
| 83 | yield* stack.destroy(); |
| 84 | yield* assertChannelDeleted(channel.channelName); |
| 85 | }), |
| 86 | { |
| 87 | tags: ["provider:aws", "provider:aws:kinesisvideo", "live"], |
| 88 | timeout: 240_000, |
| 89 | }, |
| 90 | ); |
| 91 | |
| 92 | test.provider( |
| 93 | "explicit name and replacement on rename", |
| 94 | (stack) => |
| 95 | Effect.gen(function* () { |
| 96 | yield* stack.destroy(); |
| 97 | |
| 98 | const first = yield* stack.deploy( |
| 99 | Effect.gen(function* () { |
| 100 | return yield* SignalingChannel("NamedSignalingChannel", { |
| 101 | channelName: "alchemy-test-kvs-channel-a", |
| 102 | }); |
| 103 | }), |
| 104 | ); |
| 105 | expect(first.channelName).toBe("alchemy-test-kvs-channel-a"); |
| 106 | |
| 107 | // renaming triggers a replacement: new physical channel, old gone |
| 108 | const second = yield* stack.deploy( |
| 109 | Effect.gen(function* () { |
| 110 | return yield* SignalingChannel("NamedSignalingChannel", { |
| 111 | channelName: "alchemy-test-kvs-channel-b", |
| 112 | }); |
| 113 | }), |
| 114 | ); |
| 115 | expect(second.channelName).toBe("alchemy-test-kvs-channel-b"); |
| 116 | expect(second.channelArn).not.toBe(first.channelArn); |
| 117 | |
| 118 | yield* assertChannelDeleted(first.channelName); |
| 119 | |
| 120 | yield* stack.destroy(); |
| 121 | yield* assertChannelDeleted(second.channelName); |
| 122 | }), |
| 123 | { |
| 124 | tags: ["provider:aws", "provider:aws:kinesisvideo", "live"], |
| 125 | timeout: 240_000, |
| 126 | }, |
| 127 | ); |