@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 97 lines 3.96 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AWSEnvironment } from "@alchemy.run/aws/Environment";
3 import { AccountAssignment, Group, PermissionSet } from "@alchemy.run/aws/IdentityCenter";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Identity Center requires an enabled SSO instance / identity store in the
12 // testing account. If unavailable, `resolveInstance` fails with:
13 // Error: "Unable to resolve a single visible Identity Center instance; pass instanceArn explicitly"
14 // The testing account is an organization management account where
15 // `CreateInstance` fails with a typed ValidationException ("Organization
16 // management account is not allowed to perform the operation."), so an
17 // instance cannot be provisioned programmatically. Gate the live list test
18 // behind ALCHEMY_TEST_IDENTITY_CENTER=1 so an entitled account runs it
19 // unchanged.
20 const SKIP_IDENTITY_CENTER = !process.env.ALCHEMY_TEST_IDENTITY_CENTER;
21
22 // Canonical `list()` test for an account assignment (a fan-out collection:
23 // instances -> permission sets -> accounts -> assignments). Deploy a real
24 // permission set + group + assignment targeting the current account, resolve
25 // the provider from context via the typed `findProvider`, call `list()`, and
26 // assert the deployed assignment appears in the exhaustively-paginated result.
27 test.provider.skipIf(SKIP_IDENTITY_CENTER)(
28 "list enumerates the deployed account assignment",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const { accountId } = yield* AWSEnvironment.current;
34
35 const assignment = yield* stack.deploy(
36 Effect.gen(function* () {
37 const permissionSet = yield* PermissionSet("ListPermissionSet", {
38 name: "alchemy-list-test-permission-set",
39 description: "Permission set used to verify list() enumeration",
40 sessionDuration: "1 hour",
41 });
42
43 const group = yield* Group("ListGroup", {
44 displayName: "alchemy-list-assignment-group",
45 description: "Group used to verify assignment list() enumeration",
46 });
47
48 return yield* AccountAssignment("ListAssignment", {
49 permissionSetArn: permissionSet.permissionSetArn,
50 principalType: "GROUP",
51 principalId: group.groupId,
52 targetId: accountId,
53 });
54 }),
55 );
56
57 const provider = yield* Provider.findProvider(AccountAssignment);
58 const all = yield* provider.list();
59
60 expect(
61 all.some(
62 (a) =>
63 a.permissionSetArn === assignment.permissionSetArn &&
64 a.principalId === assignment.principalId &&
65 a.targetId === assignment.targetId,
66 ),
67 ).toBe(true);
68
69 yield* stack.destroy();
70 }),
71 { tags: ["provider:aws", "provider:aws:identitycenter", "live"], timeout: 300_000 },
72 );
73
74 // A `creating` row can persist without resolved Outputs (`targetId` from
75 // `account.accountId`). Distilled `ListAccountAssignments` then fails with
76 // `ParseError: Expected string at ["AccountId"]`. Guarded `read` must report
77 // not-found without calling AWS.
78 test.provider(
79 "read returns undefined when creating-state lost targetId",
80 () =>
81 Effect.gen(function* () {
82 const provider = yield* Provider.findProvider(AccountAssignment);
83 const result = yield* provider.read!({
84 id: "AccountAssignment",
85 fqn: "AccountAssignment",
86 instanceId: "test-instance",
87 olds: {
88 permissionSetArn: "arn:aws:sso:::permissionSet/ssoins-example/ps-example",
89 principalId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
90 principalType: "GROUP",
91 } as AccountAssignment["Props"],
92 output: undefined,
93 });
94 expect(result).toBeUndefined();
95 }),
96 { tags: ["provider:aws", "provider:aws:identitycenter", "live"] },
97 );