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

main
ts 71 lines 2.82 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { MultiRegionEndpoint } 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 class EndpointStillExists extends Data.TaggedError("EndpointStillExists")<{
13 readonly name: string;
14 }> {}
15
16 const getEndpoint = (name: string) =>
17 sesv2
18 .getMultiRegionEndpoint({ EndpointName: name })
19 .pipe(Effect.catchTag("NotFoundException", () => Effect.succeed(undefined)));
20
21 const assertEndpointDeleted = (name: string) =>
22 getEndpoint(name).pipe(
23 Effect.flatMap((found) =>
24 found ? Effect.fail(new EndpointStillExists({ name })) : Effect.void,
25 ),
26 Effect.retry({
27 while: (e) => e._tag === "EndpointStillExists",
28 // Deletion is asynchronous (DELETING -> gone); poll a bounded window.
29 schedule: Schedule.max([Schedule.exponential(1000), Schedule.recurs(10)]),
30 }),
31 );
32
33 // A multi-region endpoint costs nothing to provision — SES charges $0.03/1k
34 // emails routed through it and nothing for the endpoint itself — so this runs
35 // ungated. Provisioning is asynchronous: create returns CREATING and reaching
36 // READY exceeds the polling budget, so the lifecycle asserts CREATING and
37 // deletes from there rather than waiting.
38 test.provider(
39 "multi-region endpoint lifecycle: create (CREATING), verify, delete",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const endpoint = yield* stack.deploy(
45 Effect.gen(function* () {
46 return yield* MultiRegionEndpoint("Global", {
47 regions: ["eu-west-1"],
48 });
49 }),
50 );
51
52 expect(endpoint.endpointName).toBeDefined();
53 expect(endpoint.endpointId).toBeDefined();
54 // Reconcile does not wait for READY, so the status is CREATING (or READY
55 // if provisioning was unusually fast).
56 expect(["CREATING", "READY"]).toContain(endpoint.status);
57
58 // out-of-band verification via distilled
59 const observed = yield* getEndpoint(endpoint.endpointName);
60 expect(observed?.EndpointId).toBe(endpoint.endpointId);
61
62 yield* stack.destroy();
63 yield* assertEndpointDeleted(endpoint.endpointName);
64 }),
65 // Measured ~113s: create returns immediately at CREATING, but the delete
66 // cannot land until SES finishes provisioning (it answers
67 // ConcurrentModificationException until then), so the wall-clock floor is
68 // AWS-side provisioning time. 120s left no headroom and flaked; the wait is
69 // bounded by the provider's retry schedule, not by this timeout.
70 { tags: ["provider:aws", "provider:aws:ses", "live"], timeout: 180_000 },
71 );