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

main
ts 78 lines 2.91 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AccountConfiguration } from "@alchemy.run/aws/ACM/AccountConfiguration";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as acm from "@distilled.cloud/aws/acm";
6 import { Region as AwsRegion } from "@distilled.cloud/aws/Region";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 // The AccountConfiguration provider pins its calls to us-east-1; every
11 // out-of-band ACM call in this file must target the same region.
12 const withUsEast1 = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
13 effect.pipe(Effect.provideService(AwsRegion, Effect.succeed("us-east-1")));
14
15 const { test } = Test.make({ providers: AWS.providers() });
16
17 const getDays = withUsEast1(
18 acm
19 .getAccountConfiguration({})
20 .pipe(Effect.map((response) => response.ExpiryEvents?.DaysBeforeExpiry ?? 45)),
21 );
22
23 // PutAccountConfiguration is heavily rate-limited and may report a typed
24 // ConflictException while a previous change settles — retry both, bounded.
25 const putDays = (days: number, tokenSeed: string) =>
26 withUsEast1(
27 acm
28 .putAccountConfiguration({
29 ExpiryEvents: { DaysBeforeExpiry: days },
30 IdempotencyToken: `${tokenSeed}${days}`.slice(0, 32),
31 })
32 .pipe(
33 Effect.retry({
34 while: (e): boolean => e._tag === "ConflictException" || e._tag === "ThrottlingException",
35 schedule: Schedule.max([Schedule.exponential("1 second"), Schedule.recurs(8)]),
36 }),
37 ),
38 );
39
40 // Account-global singleton: capture the live threshold up front and restore
41 // it on scope close so the test leaves the account exactly as it found it,
42 // even if an assertion fails mid-way.
43 test.provider(
44 "manages the account expiry-event threshold in place",
45 (stack) =>
46 Effect.gen(function* () {
47 yield* stack.destroy();
48
49 const originalDays = yield* getDays;
50 yield* Effect.addFinalizer(() =>
51 putDays(originalDays, "alchemyacmrestore").pipe(Effect.ignore),
52 );
53
54 // Create — converge the singleton onto a non-default threshold.
55 const created = yield* stack.deploy(
56 AccountConfiguration("ExpiryEvents", {
57 daysBeforeExpiry: "30 days",
58 }),
59 );
60 expect(created.daysBeforeExpiry).toBe(30);
61 expect(yield* getDays).toBe(30);
62
63 // Update in place — same singleton, new threshold (also proves the
64 // provider issues a fresh idempotency token per desired value).
65 const updated = yield* stack.deploy(
66 AccountConfiguration("ExpiryEvents", {
67 daysBeforeExpiry: "31 days",
68 }),
69 );
70 expect(updated.daysBeforeExpiry).toBe(31);
71 expect(yield* getDays).toBe(31);
72
73 // Destroy — resets the threshold to the AWS account default.
74 yield* stack.destroy();
75 expect(yield* getDays).toBe(45);
76 }),
77 { tags: ["provider:aws", "provider:aws:acm", "live"], timeout: 120_000 },
78 );