@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 92 lines 3.36 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Profile } from "@alchemy.run/aws/Route53Profiles";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as profiles from "@distilled.cloud/aws/route53profiles";
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 // A deleted Profile lingers in `DELETING` for a short while and is still
12 // returned by GetProfile — both RNF and DELETING/DELETED count as gone.
13 const assertProfileGone = (profileId: string) =>
14 profiles.getProfile({ ProfileId: profileId }).pipe(
15 Effect.flatMap((r) =>
16 r.Profile?.Status === "DELETING" || r.Profile?.Status === "DELETED"
17 ? Effect.void
18 : Effect.fail(new Error(`profile still ${r.Profile?.Status}`)),
19 ),
20 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
21 Effect.retry({
22 while: (e) => e instanceof Error,
23 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
24 }),
25 );
26
27 test.provider(
28 "create, update tags, replace on rename, destroy",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 // Create with a generated name + user tags.
34 const first = yield* stack.deploy(
35 Effect.gen(function* () {
36 const profile = yield* Profile("DnsProfile", {
37 tags: { env: "test" },
38 });
39 return { profile };
40 }),
41 );
42 expect(first.profile.profileId).toMatch(/^rp-/);
43 expect(first.profile.profileArn).toContain(first.profile.profileId);
44
45 // Out-of-band: the profile exists and carries alchemy + user tags.
46 const live = yield* profiles.getProfile({
47 ProfileId: first.profile.profileId,
48 });
49 expect(live.Profile?.Name).toBe(first.profile.profileName);
50 const tags = yield* profiles.listTagsForResource({
51 ResourceArn: first.profile.profileArn,
52 });
53 expect(tags.Tags.env).toBe("test");
54 expect(Object.keys(tags.Tags).some((key) => key.startsWith("alchemy:"))).toBe(true);
55
56 // Update tags in place — same profile id.
57 const second = yield* stack.deploy(
58 Effect.gen(function* () {
59 const profile = yield* Profile("DnsProfile", {
60 tags: { env: "prod", team: "platform" },
61 });
62 return { profile };
63 }),
64 );
65 expect(second.profile.profileId).toBe(first.profile.profileId);
66 const updatedTags = yield* profiles.listTagsForResource({
67 ResourceArn: second.profile.profileArn,
68 });
69 expect(updatedTags.Tags.env).toBe("prod");
70 expect(updatedTags.Tags.team).toBe("platform");
71
72 // Renaming replaces (profiles have no update API).
73 const third = yield* stack.deploy(
74 Effect.gen(function* () {
75 const profile = yield* Profile("DnsProfile", {
76 name: "alchemy-test-profile-renamed",
77 });
78 return { profile };
79 }),
80 );
81 expect(third.profile.profileName).toBe("alchemy-test-profile-renamed");
82 expect(third.profile.profileId).not.toBe(first.profile.profileId);
83 yield* assertProfileGone(first.profile.profileId);
84
85 yield* stack.destroy();
86 yield* assertProfileGone(third.profile.profileId);
87 }),
88 {
89 tags: ["provider:aws", "provider:aws:route53profiles", "live"],
90 timeout: 120_000,
91 },
92 );