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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { OptOutList } from "@alchemy.run/aws/PinpointSMSVoiceV2"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as smsvoice from "@distilled.cloud/aws/pinpoint-sms-voice-v2"; |
| 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 | // Ungated typed-error probe: proves the distilled error union carries the |
| 12 | // not-found tag this provider's read/observe paths depend on. |
| 13 | test.provider( |
| 14 | "describeOptOutLists on a nonexistent name fails with ResourceNotFoundException", |
| 15 | () => |
| 16 | Effect.gen(function* () { |
| 17 | const error = yield* Effect.flip( |
| 18 | smsvoice.describeOptOutLists({ |
| 19 | OptOutListNames: ["alchemy-nonexistent-opt-out-list-probe"], |
| 20 | }), |
| 21 | ); |
| 22 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 23 | }), |
| 24 | { |
| 25 | tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "live"], |
| 26 | timeout: 60_000, |
| 27 | }, |
| 28 | ); |
| 29 | |
| 30 | const getOptOutList = (name: string) => |
| 31 | smsvoice.describeOptOutLists({ OptOutListNames: [name] }).pipe( |
| 32 | Effect.map((r) => r.OptOutLists?.[0]), |
| 33 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 34 | ); |
| 35 | |
| 36 | const assertOptOutListGone = (name: string) => |
| 37 | Effect.gen(function* () { |
| 38 | const found = yield* getOptOutList(name); |
| 39 | if (found !== undefined) { |
| 40 | return yield* Effect.fail(new Error(`opt-out list '${name}' still exists`)); |
| 41 | } |
| 42 | }).pipe( |
| 43 | Effect.retry({ |
| 44 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]), |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | // Opt-out lists are free and provision synchronously — the full lifecycle |
| 49 | // (create, no-op, tag update, destroy) runs ungated. |
| 50 | test.provider( |
| 51 | "create, update tags, and destroy an opt-out list", |
| 52 | (stack) => |
| 53 | Effect.gen(function* () { |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | const props = { |
| 57 | optOutListName: "alchemy-test-smsvoice-opt-out-list", |
| 58 | tags: { fixture: "smsvoice-opt-out-list" }, |
| 59 | }; |
| 60 | |
| 61 | // Create. |
| 62 | const created = yield* stack.deploy(OptOutList("OptOuts", props)); |
| 63 | expect(created.optOutListName).toBe("alchemy-test-smsvoice-opt-out-list"); |
| 64 | expect(created.optOutListArn).toContain(":opt-out-list/"); |
| 65 | |
| 66 | // Out-of-band verification via distilled. |
| 67 | const observed = yield* getOptOutList(created.optOutListName); |
| 68 | expect(observed?.OptOutListName).toBe(created.optOutListName); |
| 69 | const tags = yield* smsvoice.listTagsForResource({ |
| 70 | ResourceArn: created.optOutListArn, |
| 71 | }); |
| 72 | const tagRecord = Object.fromEntries((tags.Tags ?? []).map((t) => [t.Key, t.Value])); |
| 73 | expect(tagRecord.fixture).toBe("smsvoice-opt-out-list"); |
| 74 | expect(tagRecord["alchemy::id"]).toBe("OptOuts"); |
| 75 | |
| 76 | // No-op redeploy keeps the same list. |
| 77 | const noop = yield* stack.deploy(OptOutList("OptOuts", props)); |
| 78 | expect(noop.optOutListArn).toBe(created.optOutListArn); |
| 79 | |
| 80 | // Tag update in place — the ARN must not change. |
| 81 | const updated = yield* stack.deploy( |
| 82 | OptOutList("OptOuts", { |
| 83 | ...props, |
| 84 | tags: { fixture: "smsvoice-opt-out-list-v2", extra: "1" }, |
| 85 | }), |
| 86 | ); |
| 87 | expect(updated.optOutListArn).toBe(created.optOutListArn); |
| 88 | const retags = yield* smsvoice.listTagsForResource({ |
| 89 | ResourceArn: created.optOutListArn, |
| 90 | }); |
| 91 | const retagRecord = Object.fromEntries((retags.Tags ?? []).map((t) => [t.Key, t.Value])); |
| 92 | expect(retagRecord.fixture).toBe("smsvoice-opt-out-list-v2"); |
| 93 | expect(retagRecord.extra).toBe("1"); |
| 94 | |
| 95 | // Destroy and verify out-of-band with a typed wait-until-gone. |
| 96 | yield* stack.destroy(); |
| 97 | yield* assertOptOutListGone(created.optOutListName); |
| 98 | }), |
| 99 | { |
| 100 | tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "live"], |
| 101 | timeout: 240_000, |
| 102 | }, |
| 103 | ); |