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 { EmailContact } from "@alchemy.run/aws/NotificationsContacts"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as contacts from "@distilled.cloud/aws/notificationscontacts"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const CONTACT_NAME = "alchemy-test-email-contact"; |
| 13 | const EMAIL_A = "sam+alchemy-test-contact-a@alchemy.run"; |
| 14 | const EMAIL_B = "sam+alchemy-test-contact-b@alchemy.run"; |
| 15 | |
| 16 | const unwrap = (value: string | Redacted.Redacted<string>): string => |
| 17 | typeof value === "string" ? value : Redacted.value(value); |
| 18 | |
| 19 | const assertContactGone = (arn: string) => |
| 20 | contacts.getEmailContact({ arn }).pipe( |
| 21 | Effect.flatMap(() => Effect.fail(new Error(`contact ${arn} still exists`))), |
| 22 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 23 | Effect.retry({ |
| 24 | while: (e) => e instanceof Error, |
| 25 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]), |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | describe( |
| 30 | "AWS.NotificationsContacts.EmailContact", |
| 31 | { tags: ["provider:aws", "provider:aws:notificationscontacts", "live"] }, |
| 32 | () => { |
| 33 | test.provider( |
| 34 | "email contact lifecycle (unverified create, tag update, replacement)", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const deployContact = (props: { emailAddress: string; tags: Record<string, string> }) => |
| 40 | stack.deploy( |
| 41 | Effect.gen(function* () { |
| 42 | const contact = yield* EmailContact("OnCall", { |
| 43 | name: CONTACT_NAME, |
| 44 | emailAddress: props.emailAddress, |
| 45 | tags: props.tags, |
| 46 | }); |
| 47 | return { |
| 48 | arn: contact.emailContactArn, |
| 49 | name: contact.name, |
| 50 | emailAddress: contact.emailAddress, |
| 51 | status: contact.status, |
| 52 | }; |
| 53 | }), |
| 54 | ); |
| 55 | |
| 56 | // CREATE — the contact exists in the unverified state (activation |
| 57 | // is a human email-confirmation loop; AWS reports it as |
| 58 | // `inactive` until the address owner confirms). |
| 59 | const created = yield* deployContact({ |
| 60 | emailAddress: EMAIL_A, |
| 61 | tags: { purpose: "alchemy-test" }, |
| 62 | }); |
| 63 | expect(created.arn).toContain(":emailcontact/"); |
| 64 | expect(created.name).toBe(CONTACT_NAME); |
| 65 | expect(created.emailAddress).toBe(EMAIL_A); |
| 66 | expect(created.status).toBe("inactive"); |
| 67 | |
| 68 | // Out-of-band: the contact and its tags are live. |
| 69 | const observed = yield* contacts.getEmailContact({ arn: created.arn }); |
| 70 | expect(unwrap(observed.emailContact.address)).toBe(EMAIL_A); |
| 71 | expect(observed.emailContact.status).toBe("inactive"); |
| 72 | const tags = yield* contacts.listTagsForResource({ arn: created.arn }); |
| 73 | expect(tags.tags?.purpose).toBe("alchemy-test"); |
| 74 | expect(tags.tags?.["alchemy::id"]).toBe("OnCall"); |
| 75 | |
| 76 | // UPDATE — tags are the only mutable aspect; the ARN is stable. |
| 77 | const updated = yield* deployContact({ |
| 78 | emailAddress: EMAIL_A, |
| 79 | tags: { purpose: "alchemy-test", updated: "true" }, |
| 80 | }); |
| 81 | expect(updated.arn).toBe(created.arn); |
| 82 | const tagsAfterUpdate = yield* contacts.listTagsForResource({ arn: created.arn }); |
| 83 | expect(tagsAfterUpdate.tags?.updated).toBe("true"); |
| 84 | |
| 85 | // REPLACE — contacts have no update API, so changing the address |
| 86 | // replaces the contact (new ARN, old one deleted). |
| 87 | const replaced = yield* deployContact({ |
| 88 | emailAddress: EMAIL_B, |
| 89 | tags: { purpose: "alchemy-test" }, |
| 90 | }); |
| 91 | expect(replaced.arn).not.toBe(created.arn); |
| 92 | expect(replaced.emailAddress).toBe(EMAIL_B); |
| 93 | yield* assertContactGone(created.arn); |
| 94 | |
| 95 | // DESTROY — verified out-of-band with a typed wait-until-gone. |
| 96 | yield* stack.destroy(); |
| 97 | yield* assertContactGone(replaced.arn); |
| 98 | }), |
| 99 | { timeout: 240_000 }, |
| 100 | ); |
| 101 | }, |
| 102 | ); |