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

main
ts 69 lines 2.83 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { expect } from "@alchemy.run/test";
3 import * as Provider from "alchemy/Provider";
4 import * as Effect from "effect/Effect";
5 import * as OrganizationLease from "./OrganizationLease.ts";
6
7 const { test } = OrganizationLease.make({ providers: AWS.providers() }, "shared");
8
9 // `Root` is import-only and there is exactly one organization root per
10 // management account. `list()` enumerates roots via `listRoots` (paginated) and
11 // hydrates each into the full Attributes shape, or returns `[]` when the account
12 // isn't an organization management account (the typed
13 // `AWSOrganizationsNotInUseException` / `AccessDeniedException` are caught to
14 // `[]`). This runs read-only — it neither creates nor deletes anything.
15 test.provider(
16 "list enumerates the organization root",
17 (stack) =>
18 Effect.gen(function* () {
19 const provider = yield* Provider.findProvider(AWS.Organizations.Root);
20 const all = yield* provider.list();
21
22 // 0 (account is not a management account) or 1 (it is) — never more.
23 expect(all.length).toBeLessThanOrEqual(1);
24
25 // When the account is an organization management account, the single entry
26 // carries a well-typed Attributes shape.
27 if (all.length === 1) {
28 const root = all[0];
29 expect(typeof root.rootId).toBe("string");
30 expect(root.rootId.length).toBeGreaterThan(0);
31 expect(typeof root.rootArn).toBe("string");
32 expect(root.rootArn.startsWith("arn:aws:organizations::")).toBe(true);
33 expect(typeof root.rootName).toBe("string");
34 expect(Array.isArray(root.policyTypes)).toBe(true);
35 expect(typeof root.tags).toBe("object");
36 }
37
38 yield* stack.destroy();
39 }),
40 { tags: ["provider:aws", "provider:aws:organizations", "live"] },
41 );
42
43 // `rootId` and `name` only select which root to adopt, so adding, removing, or
44 // pinning one that matches the adopted root plans an update, never a replace.
45 test.provider(
46 "pinning or dropping the lookup id of the adopted root updates in place",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const root = yield* stack.deploy(AWS.Organizations.Root("Root", {}));
52
53 const pinned = yield* stack.plan(
54 AWS.Organizations.Root("Root", { rootId: root.rootId, name: root.rootName }),
55 );
56 expect(pinned.resources.Root?.action).toBe("update");
57
58 yield* stack.deploy(AWS.Organizations.Root("Root", { rootId: root.rootId }));
59
60 const dropped = yield* stack.plan(AWS.Organizations.Root("Root", {}));
61 expect(dropped.resources.Root?.action).toBe("update");
62
63 const other = yield* stack.plan(AWS.Organizations.Root("Root", { rootId: "r-zzzz" }));
64 expect(other.resources.Root?.action).toBe("replace");
65
66 yield* stack.destroy();
67 }),
68 { tags: ["provider:aws", "provider:aws:organizations", "live"] },
69 );