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 { AccountSettings } 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 Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | const getSuppressedReasons = sesv2 |
| 11 | .getAccount({}) |
| 12 | .pipe(Effect.map((response) => response.SuppressionAttributes?.SuppressedReasons ?? [])); |
| 13 | |
| 14 | // Account/region-global singleton: capture the live suppression configuration |
| 15 | // up front and restore it on scope close so the test leaves the account exactly |
| 16 | // as it found it, even if an assertion fails mid-way. Deleting the resource is |
| 17 | // a no-op (it leaves settings in place), so the restore MUST be explicit. |
| 18 | // The "aws:ses-account" label keeps other SES account-singleton tests out. |
| 19 | test.provider( |
| 20 | "manages the account suppression list in place", |
| 21 | (stack) => |
| 22 | Effect.gen(function* () { |
| 23 | yield* stack.destroy(); |
| 24 | |
| 25 | const originalReasons = yield* getSuppressedReasons; |
| 26 | yield* Effect.addFinalizer(() => |
| 27 | sesv2 |
| 28 | .putAccountSuppressionAttributes({ |
| 29 | SuppressedReasons: originalReasons, |
| 30 | }) |
| 31 | .pipe(Effect.ignore), |
| 32 | ); |
| 33 | |
| 34 | // Create — converge the account suppression list onto both reasons. |
| 35 | const created = yield* stack.deploy( |
| 36 | AccountSettings("Account", { |
| 37 | suppression: { reasons: ["BOUNCE", "COMPLAINT"] }, |
| 38 | }), |
| 39 | ); |
| 40 | expect([...created.suppressedReasons].sort()).toEqual(["BOUNCE", "COMPLAINT"]); |
| 41 | expect([...(yield* getSuppressedReasons)].sort()).toEqual(["BOUNCE", "COMPLAINT"]); |
| 42 | |
| 43 | // Update in place — narrow the suppression list to a single reason. |
| 44 | const updated = yield* stack.deploy( |
| 45 | AccountSettings("Account", { |
| 46 | suppression: { reasons: ["BOUNCE"] }, |
| 47 | }), |
| 48 | ); |
| 49 | expect(updated.suppressedReasons).toEqual(["BOUNCE"]); |
| 50 | expect(yield* getSuppressedReasons).toEqual(["BOUNCE"]); |
| 51 | |
| 52 | // Destroy is a no-op: the account settings remain as last configured |
| 53 | // until the finalizer restores the captured original. |
| 54 | yield* stack.destroy(); |
| 55 | expect(yield* getSuppressedReasons).toEqual(["BOUNCE"]); |
| 56 | }), |
| 57 | { |
| 58 | tags: ["provider:aws", "provider:aws:ses", "live"], |
| 59 | timeout: 120_000, |
| 60 | exclusive: "aws:ses-account", |
| 61 | }, |
| 62 | ); |
| 63 | |
| 64 | const getSendingEnabled = sesv2 |
| 65 | .getAccount({}) |
| 66 | .pipe(Effect.map((response) => response.SendingEnabled ?? false)); |
| 67 | |
| 68 | const restoreSendingEnabled = (enabled: boolean) => |
| 69 | sesv2.putAccountSendingAttributes({ SendingEnabled: enabled }).pipe(Effect.ignore); |
| 70 | |
| 71 | // Toggling `sendingEnabled` pauses ALL sending for the account in the run's |
| 72 | // region. It cannot be isolated to a throwaway region: `AWS.providers()` |
| 73 | // merges `Region.fromEnvironment` into the provider layer itself, so a |
| 74 | // `Region` provided around the test body never reaches the provider's SDK |
| 75 | // calls. Containment is therefore the `aws:ses-account` label, which every |
| 76 | // test that sends through SES holds too, plus a finalizer that restores the |
| 77 | // captured value on failure and interruption as well as success. A whole-run |
| 78 | // `exclusive: true` would instead stall every other test behind the slowest |
| 79 | // one in flight (MWAA, ElastiCache: 20+ minutes). |
| 80 | test.provider( |
| 81 | "toggles account-level sending in place", |
| 82 | (stack) => |
| 83 | Effect.gen(function* () { |
| 84 | yield* stack.destroy(); |
| 85 | |
| 86 | const original = yield* getSendingEnabled; |
| 87 | yield* Effect.addFinalizer(() => restoreSendingEnabled(original)); |
| 88 | |
| 89 | // Sending starts enabled; converge it to disabled. |
| 90 | const disabled = yield* stack.deploy(AccountSettings("Account", { sendingEnabled: false })); |
| 91 | expect(disabled.sendingEnabled).toBe(false); |
| 92 | expect(yield* getSendingEnabled).toBe(false); |
| 93 | |
| 94 | // Re-enable in place — the same reconciler converges either direction. |
| 95 | const enabled = yield* stack.deploy(AccountSettings("Account", { sendingEnabled: true })); |
| 96 | expect(enabled.sendingEnabled).toBe(true); |
| 97 | expect(yield* getSendingEnabled).toBe(true); |
| 98 | |
| 99 | yield* stack.destroy(); |
| 100 | }), |
| 101 | { |
| 102 | tags: ["provider:aws", "provider:aws:ses", "live"], |
| 103 | timeout: 120_000, |
| 104 | exclusive: "aws:ses-account", |
| 105 | }, |
| 106 | ); |