@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 109 lines 4.6 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { PlaybackRestrictionPolicy } 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 "getPlaybackRestrictionPolicy 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.getPlaybackRestrictionPolicy({
22 arn: `arn:aws:ivs:${region}:${Account}:playback-restriction-policy/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 assertPolicyGone = (arn: string) =>
31 Effect.gen(function* () {
32 const policy = yield* ivs.getPlaybackRestrictionPolicy({ arn }).pipe(
33 Effect.map((r) => r.playbackRestrictionPolicy),
34 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
35 );
36 if (policy !== undefined) {
37 return yield* Effect.fail(new Error(`policy '${arn}' still exists`));
38 }
39 }).pipe(
40 Effect.retry({
41 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
42 }),
43 );
44
45 // Playback restriction policies are free and provision synchronously — the
46 // full lifecycle (create, no-op, update-in-place, destroy) runs ungated.
47 test.provider(
48 "create, update, and destroy an IVS playback restriction policy",
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 playbackRestrictionPolicyName: "alchemy-test-ivs-prp",
56 allowedCountries: ["US", "CA"],
57 allowedOrigins: ["https://example.com"],
58 tags: { fixture: "ivs-prp" },
59 };
60
61 // Create.
62 const created = yield* stack.deploy(PlaybackRestrictionPolicy("GeoFence", props));
63 expect(created.playbackRestrictionPolicyArn).toContain(":playback-restriction-policy/");
64 expect(created.playbackRestrictionPolicyName).toBe("alchemy-test-ivs-prp");
65 expect([...created.allowedCountries].sort()).toEqual(["CA", "US"]);
66 expect(created.allowedOrigins).toEqual(["https://example.com"]);
67
68 // Out-of-band verification via distilled.
69 const observed = yield* ivs.getPlaybackRestrictionPolicy({
70 arn: created.playbackRestrictionPolicyArn,
71 });
72 expect(observed.playbackRestrictionPolicy?.name).toBe("alchemy-test-ivs-prp");
73 expect(observed.playbackRestrictionPolicy?.tags?.fixture).toBe("ivs-prp");
74 expect(observed.playbackRestrictionPolicy?.tags?.["alchemy::id"]).toBe("GeoFence");
75
76 // No-op redeploy keeps the same policy.
77 const noop = yield* stack.deploy(PlaybackRestrictionPolicy("GeoFence", props));
78 expect(noop.playbackRestrictionPolicyArn).toBe(created.playbackRestrictionPolicyArn);
79
80 // Update in place — countries, origins, and strict enforcement are
81 // all mutable; the ARN must not change.
82 const updated = yield* stack.deploy(
83 PlaybackRestrictionPolicy("GeoFence", {
84 ...props,
85 allowedCountries: ["US"],
86 allowedOrigins: ["https://example.com", "https://example.org"],
87 enableStrictOriginEnforcement: true,
88 }),
89 );
90 expect(updated.playbackRestrictionPolicyArn).toBe(created.playbackRestrictionPolicyArn);
91 expect(updated.allowedCountries).toEqual(["US"]);
92 expect([...updated.allowedOrigins].sort()).toEqual([
93 "https://example.com",
94 "https://example.org",
95 ]);
96 expect(updated.enableStrictOriginEnforcement).toBe(true);
97
98 const reobserved = yield* ivs.getPlaybackRestrictionPolicy({
99 arn: created.playbackRestrictionPolicyArn,
100 });
101 expect(reobserved.playbackRestrictionPolicy?.enableStrictOriginEnforcement).toBe(true);
102 expect(reobserved.playbackRestrictionPolicy?.allowedCountries).toEqual(["US"]);
103
104 // Destroy and verify out-of-band with a typed wait-until-gone.
105 yield* stack.destroy();
106 yield* assertPolicyGone(created.playbackRestrictionPolicyArn);
107 }),
108 { tags: ["provider:aws", "provider:aws:ivs", "live"], timeout: 240_000 },
109 );