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 { PhoneNumber } 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/delete paths depend on. |
| 13 | test.provider( |
| 14 | "describePhoneNumbers on a nonexistent ID fails with ResourceNotFoundException", |
| 15 | () => |
| 16 | Effect.gen(function* () { |
| 17 | const error = yield* Effect.flip( |
| 18 | smsvoice.describePhoneNumbers({ |
| 19 | PhoneNumberIds: ["phone-ffffffffffffffffffffffffffffffff"], |
| 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 getById = (phoneNumberId: string) => |
| 31 | smsvoice.describePhoneNumbers({ PhoneNumberIds: [phoneNumberId] }).pipe( |
| 32 | Effect.map((r) => r.PhoneNumbers?.[0]), |
| 33 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 34 | ); |
| 35 | |
| 36 | const assertPhoneNumberGone = (phoneNumberId: string) => |
| 37 | Effect.gen(function* () { |
| 38 | const found = yield* getById(phoneNumberId); |
| 39 | // A released number lingers briefly in DISASSOCIATING before vanishing. |
| 40 | if (found !== undefined && found.Status !== "DISASSOCIATING") { |
| 41 | return yield* Effect.fail( |
| 42 | new Error(`phone number '${phoneNumberId}' still exists (status: ${found.Status})`), |
| 43 | ); |
| 44 | } |
| 45 | }).pipe( |
| 46 | Effect.retry({ |
| 47 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]), |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | // Requesting even a SIMULATOR number incurs a (small) monthly leasing fee |
| 52 | // and consumes account quota, so the lifecycle is gated behind |
| 53 | // AWS_TEST_PINPOINT_SMS=1 and always releases what it leased. |
| 54 | test.provider.skipIf(!process.env.AWS_TEST_PINPOINT_SMS)( |
| 55 | "request a SIMULATOR number, update, and release it", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const props = { |
| 61 | isoCountryCode: "US", |
| 62 | messageType: "TRANSACTIONAL" as const, |
| 63 | numberCapabilities: ["SMS"], |
| 64 | numberType: "SIMULATOR", |
| 65 | tags: { fixture: "smsvoice-phone-number" }, |
| 66 | }; |
| 67 | |
| 68 | // Create. |
| 69 | const created = yield* stack.deploy(PhoneNumber("TestNumber", props)); |
| 70 | expect(created.phoneNumberId).toContain("phone-"); |
| 71 | expect(created.phoneNumberArn).toContain(":phone-number/"); |
| 72 | expect(created.phoneNumber).toMatch(/^\+1/); |
| 73 | expect(created.numberType).toBe("SIMULATOR"); |
| 74 | expect(created.status === "ACTIVE" || created.status === "PENDING").toBe(true); |
| 75 | |
| 76 | // Out-of-band verification via distilled. |
| 77 | const observed = yield* getById(created.phoneNumberId); |
| 78 | expect(observed?.PhoneNumberArn).toBe(created.phoneNumberArn); |
| 79 | const tags = yield* smsvoice.listTagsForResource({ |
| 80 | ResourceArn: created.phoneNumberArn, |
| 81 | }); |
| 82 | const tagRecord = Object.fromEntries((tags.Tags ?? []).map((t) => [t.Key, t.Value])); |
| 83 | expect(tagRecord.fixture).toBe("smsvoice-phone-number"); |
| 84 | expect(tagRecord["alchemy::id"]).toBe("TestNumber"); |
| 85 | |
| 86 | // No-op redeploy keeps the same number. |
| 87 | const noop = yield* stack.deploy(PhoneNumber("TestNumber", props)); |
| 88 | expect(noop.phoneNumberId).toBe(created.phoneNumberId); |
| 89 | |
| 90 | // Update in place — enable deletion protection; the ID must not |
| 91 | // change. |
| 92 | const updated = yield* stack.deploy( |
| 93 | PhoneNumber("TestNumber", { |
| 94 | ...props, |
| 95 | deletionProtectionEnabled: true, |
| 96 | }), |
| 97 | ); |
| 98 | expect(updated.phoneNumberId).toBe(created.phoneNumberId); |
| 99 | const reobserved = yield* getById(created.phoneNumberId); |
| 100 | expect(reobserved?.DeletionProtectionEnabled).toBe(true); |
| 101 | |
| 102 | // Disable protection again so the release below succeeds. |
| 103 | yield* stack.deploy(PhoneNumber("TestNumber", props)); |
| 104 | const unprotected = yield* getById(created.phoneNumberId); |
| 105 | expect(unprotected?.DeletionProtectionEnabled).toBe(false); |
| 106 | |
| 107 | // Destroy and verify the release out-of-band. |
| 108 | yield* stack.destroy(); |
| 109 | yield* assertPhoneNumberGone(created.phoneNumberId); |
| 110 | }), |
| 111 | { |
| 112 | tags: ["provider:aws", "provider:aws:pinpointsmsvoicev2", "live"], |
| 113 | timeout: 240_000, |
| 114 | }, |
| 115 | ); |