@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 87 lines 3.38 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AccountName } from "@alchemy.run/aws/Account";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as account from "@distilled.cloud/aws/account";
5 import * as Effect from "effect/Effect";
6 import * as Redacted from "effect/Redacted";
7 import * as Schedule from "effect/Schedule";
8 import * as OrganizationLease from "../Organizations/OrganizationLease.ts";
9
10 // Shared organization lease: Floci reports the management account's name from
11 // the organization when one exists, so the organization must not be created or
12 // deleted while this test captures and restores the name.
13 const { test } = OrganizationLease.make({ providers: AWS.providers() }, "shared");
14
15 const unwrap = (value: string | Redacted.Redacted<string> | undefined) =>
16 value === undefined ? undefined : typeof value === "string" ? value : Redacted.value(value);
17
18 const TEST_NAME = "alchemy-test-account-name";
19
20 // getAccountInformation is eventually consistent after putAccountName (the
21 // rename can take ~20s to become visible), so out-of-band reads poll
22 // (bounded) until the expected name is observed.
23 const readNameUntil = (expected: string | undefined) =>
24 account.getAccountInformation({}).pipe(
25 Effect.map((info) => unwrap(info.AccountName)),
26 Effect.repeat({
27 schedule: Schedule.spaced("3 seconds"),
28 until: (name): boolean => name === expected,
29 times: 10,
30 }),
31 );
32
33 // The account name is an account-global singleton. This test captures the
34 // current name, renames the account to a marker, verifies out-of-band,
35 // destroys (a no-op — an account always has a name), and restores the
36 // original name so the account is left exactly as it was found.
37 describe.sequential(
38 "Account AccountName",
39 { tags: ["provider:aws", "provider:aws:account", "live"] },
40 () => {
41 test.provider(
42 "set, read, and restore the account name",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const info = yield* account.getAccountInformation({});
48 const originalName = unwrap(info.AccountName);
49
50 const restore = Effect.gen(function* () {
51 if (originalName !== undefined) {
52 yield* account.putAccountName({ AccountName: originalName });
53 }
54 });
55
56 yield* Effect.gen(function* () {
57 const name = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* AccountName("Name", {
60 accountName: TEST_NAME,
61 });
62 }),
63 );
64
65 expect(name.accountName).toBe(TEST_NAME);
66 expect(name.accountId).toBe(info.AccountId);
67
68 // Out-of-band verification (bounded poll through the rename's
69 // eventual consistency).
70 const live = yield* readNameUntil(TEST_NAME);
71 expect(live).toBe(TEST_NAME);
72
73 // Destroy is a no-op — an account always has a name, so the last
74 // value stays in place.
75 yield* stack.destroy();
76 const after = yield* readNameUntil(TEST_NAME);
77 expect(after).toBe(TEST_NAME);
78 }).pipe(Effect.ensuring(restore.pipe(Effect.orDie)));
79
80 // Confirm restoration matches the captured original.
81 const restored = yield* readNameUntil(originalName);
82 expect(restored).toBe(originalName);
83 }),
84 { timeout: 120_000 },
85 );
86 },
87 );