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

main
ts 49 lines 1.92 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AccessKey, User } from "@alchemy.run/aws/IAM";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as IAM from "@distilled.cloud/aws/iam";
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 describe("AWS.IAM.AccessKey", { tags: ["provider:aws", "provider:aws:iam", "live"] }, () => {
12 // Canonical `list()` test: IAM is a global service and `listAccessKeys`
13 // requires a `UserName`, so the provider enumerates every user first and then
14 // lists keys per user. Deploy a real user + access key, resolve the provider
15 // from context with the typed `findProvider`, call `list()`, and assert the
16 // deployed key appears in the exhaustively-paginated result.
17 test.provider("list enumerates the deployed access key", (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const deployed = yield* stack.deploy(
22 Effect.gen(function* () {
23 const user = yield* User("AccessKeyListOwner", {});
24 const key = yield* AccessKey("AccessKeyListKey", {
25 userName: user.userName,
26 status: "Active",
27 });
28 return { user, key };
29 }),
30 );
31
32 const provider = yield* Provider.findProvider(AccessKey);
33 const all = yield* provider.list();
34
35 const found = all.find((entry) => entry.accessKeyId === deployed.key.accessKeyId);
36 expect(found).toBeDefined();
37 expect(found?.userName).toBe(deployed.user.userName);
38 expect(found?.secretAccessKey).toBeUndefined();
39
40 yield* stack.destroy();
41
42 // The user (and with it every access key it owned) is gone.
43 const deletedUser = yield* IAM.getUser({ UserName: deployed.user.userName }).pipe(
44 Effect.option,
45 );
46 expect(deletedUser._tag).toBe("None");
47 }),
48 );
49 });