@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 90 lines 3.55 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { PlaybackKeyPair } 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 Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Generated once with `openssl ecparam -name secp384r1 -genkey | openssl
12 // ec -pubout` and checked in as constants (never generated at test time).
13 const PUBLIC_KEY_A = `-----BEGIN PUBLIC KEY-----
14 MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAESErCxbkHXtts2QDGbIfjMpUjNtnBtHwm
15 vIu3tC3Rqdv3NAcDzBadv045/QzYLFYpW1qqAMBGCASZKl+fvk+oI6ES+wV6aT1i
16 vGQdcQN88zA1DeJLu2CEA5dRXmSKhP4C
17 -----END PUBLIC KEY-----`;
18
19 const PUBLIC_KEY_B = `-----BEGIN PUBLIC KEY-----
20 MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEiS2HkhQsxtJG4i++/Na99ZwNEugpI+M/
21 N0EKZtiBKnt5QhZMcyeRjcwY3zJBtrZSd8hgdyaW0HQoGtyNVNZNi54XPRq3BQUf
22 r4NJCuts5JUtFVRM6ynCdqdi78ZxNUBj
23 -----END PUBLIC KEY-----`;
24
25 const assertKeyPairGone = (arn: string) =>
26 Effect.gen(function* () {
27 const keyPair = yield* ivs.getPlaybackKeyPair({ arn }).pipe(
28 Effect.map((r) => r.keyPair),
29 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
30 );
31 if (keyPair !== undefined) {
32 return yield* Effect.fail(new Error(`playback key pair '${arn}' still exists`));
33 }
34 }).pipe(
35 Effect.retry({
36 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
37 }),
38 );
39
40 // Key pairs are free and provision synchronously. Covers create, no-op,
41 // and the replace path (key material is immutable).
42 test.provider(
43 "import, replace, and destroy a playback key pair",
44 (stack) =>
45 Effect.gen(function* () {
46 yield* stack.destroy();
47
48 const props = {
49 playbackKeyPairName: "alchemy-test-ivs-keypair",
50 publicKeyMaterial: PUBLIC_KEY_A,
51 tags: { fixture: "ivs-playback-key-pair" },
52 };
53
54 // Create (import).
55 const created = yield* stack.deploy(PlaybackKeyPair("Viewer", props));
56 expect(created.playbackKeyPairName).toBe("alchemy-test-ivs-keypair");
57 expect(created.playbackKeyPairArn).toContain(":playback-key/");
58 expect(created.fingerprint).toBeDefined();
59
60 // Out-of-band verification via distilled.
61 const observed = yield* ivs.getPlaybackKeyPair({
62 arn: created.playbackKeyPairArn,
63 });
64 expect(observed.keyPair?.name).toBe("alchemy-test-ivs-keypair");
65 expect(observed.keyPair?.fingerprint).toBe(created.fingerprint);
66 expect(observed.keyPair?.tags?.["alchemy::id"]).toBe("Viewer");
67
68 // No-op redeploy keeps the same key pair.
69 const noop = yield* stack.deploy(PlaybackKeyPair("Viewer", props));
70 expect(noop.playbackKeyPairArn).toBe(created.playbackKeyPairArn);
71 expect(noop.fingerprint).toBe(created.fingerprint);
72
73 // Changing the key material replaces the key pair — new ARN and
74 // fingerprint under the same name.
75 const replaced = yield* stack.deploy(
76 PlaybackKeyPair("Viewer", {
77 ...props,
78 publicKeyMaterial: PUBLIC_KEY_B,
79 }),
80 );
81 expect(replaced.playbackKeyPairArn).not.toBe(created.playbackKeyPairArn);
82 expect(replaced.fingerprint).not.toBe(created.fingerprint);
83 yield* assertKeyPairGone(created.playbackKeyPairArn);
84
85 // Destroy and verify out-of-band with a typed wait-until-gone.
86 yield* stack.destroy();
87 yield* assertKeyPairGone(replaced.playbackKeyPairArn);
88 }),
89 { tags: ["provider:aws", "provider:aws:ivs", "live"], timeout: 240_000 },
90 );