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

main
ts 139 lines 4.73 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ContactList } from "@alchemy.run/aws/SES";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as sesv2 from "@distilled.cloud/aws/sesv2";
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 // SES allows only one contact list per AWS account, so every test that creates
13 // one holds the "aws:ses-account" label — two contact-list suites running
14 // concurrently would collide on the account-wide singleton.
15
16 class ContactListStillExists extends Data.TaggedError("ContactListStillExists")<{
17 readonly name: string;
18 }> {}
19
20 const assertContactListDeleted = (name: string) =>
21 sesv2.getContactList({ ContactListName: name }).pipe(
22 Effect.flatMap(() => Effect.fail(new ContactListStillExists({ name }))),
23 Effect.catchTag("NotFoundException", () => Effect.void),
24 Effect.retry({
25 while: (e) => e._tag === "ContactListStillExists",
26 schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
27 }),
28 );
29
30 test.provider(
31 "contact list lifecycle: create, update topics/description/tags, delete",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35
36 const list = yield* stack.deploy(
37 Effect.gen(function* () {
38 return yield* ContactList("Newsletter", {
39 description: "Weekly newsletter",
40 topics: [
41 {
42 TopicName: "product-updates",
43 DisplayName: "Product Updates",
44 DefaultSubscriptionStatus: "OPT_IN",
45 },
46 ],
47 tags: { Environment: "test" },
48 });
49 }),
50 );
51
52 expect(list.contactListName).toBeDefined();
53 expect(list.contactListArn).toContain(":contact-list/");
54
55 // out-of-band verification via distilled
56 const observed = yield* sesv2.getContactList({
57 ContactListName: list.contactListName,
58 });
59 expect(observed.Description).toBe("Weekly newsletter");
60 expect(observed.Topics?.[0]?.TopicName).toBe("product-updates");
61 const tags = Object.fromEntries((observed.Tags ?? []).map((t) => [t.Key, t.Value]));
62 expect(tags.Environment).toBe("test");
63 expect(tags["alchemy::id"]).toBe("Newsletter");
64
65 // update description, add a topic, add a tag
66 yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* ContactList("Newsletter", {
69 description: "Weekly product newsletter",
70 topics: [
71 {
72 TopicName: "product-updates",
73 DisplayName: "Product Updates",
74 DefaultSubscriptionStatus: "OPT_IN",
75 },
76 {
77 TopicName: "promotions",
78 DisplayName: "Promotions",
79 DefaultSubscriptionStatus: "OPT_OUT",
80 },
81 ],
82 tags: { Environment: "test", Extra: "1" },
83 });
84 }),
85 );
86 const updated = yield* sesv2.getContactList({
87 ContactListName: list.contactListName,
88 });
89 expect(updated.Description).toBe("Weekly product newsletter");
90 expect((updated.Topics ?? []).length).toBe(2);
91 const updatedTags = Object.fromEntries((updated.Tags ?? []).map((t) => [t.Key, t.Value]));
92 expect(updatedTags.Extra).toBe("1");
93
94 yield* stack.destroy();
95 yield* assertContactListDeleted(list.contactListName);
96 }),
97 {
98 tags: ["provider:aws", "provider:aws:ses", "live"],
99 timeout: 120_000,
100 exclusive: "aws:ses-account",
101 },
102 );
103
104 test.provider(
105 "custom name replaces on rename",
106 (stack) =>
107 Effect.gen(function* () {
108 yield* stack.destroy();
109
110 const first = yield* stack.deploy(
111 Effect.gen(function* () {
112 return yield* ContactList("Named", {
113 contactListName: "alchemy-test-contact-list-a",
114 });
115 }),
116 );
117 expect(first.contactListName).toBe("alchemy-test-contact-list-a");
118
119 // The rename replaces delete-first: creating -b before deleting -a would
120 // exceed the one-contact-list-per-account limit.
121 const second = yield* stack.deploy(
122 Effect.gen(function* () {
123 return yield* ContactList("Named", {
124 contactListName: "alchemy-test-contact-list-b",
125 });
126 }),
127 );
128 expect(second.contactListName).toBe("alchemy-test-contact-list-b");
129 yield* assertContactListDeleted("alchemy-test-contact-list-a");
130
131 yield* stack.destroy();
132 yield* assertContactListDeleted("alchemy-test-contact-list-b");
133 }),
134 {
135 tags: ["provider:aws", "provider:aws:ses", "live"],
136 timeout: 120_000,
137 exclusive: "aws:ses-account",
138 },
139 );