@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 124 lines 4.7 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { OpenIDConnectProvider } 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 { isResourceState, State, type ResourceState } from "alchemy/State";
8 import * as Effect from "effect/Effect";
9 import { testOidcListUrl, testOidcThumbprintA } from "./fixtures.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // A distinct issuer URL for the #736 recovery test — the OIDC provider ARN is
14 // deterministic from the URL, so sharing a URL with another test would make
15 // two tests provision (and tear down) the same physical provider.
16 const testOidcWedgedUrl = "https://example.com/alchemy-oidc-wedged";
17
18 describe(
19 "AWS.IAM.OpenIDConnectProvider",
20 { tags: ["provider:aws", "provider:aws:iam", "live"] },
21 () => {
22 test.provider("list enumerates the deployed OpenID Connect provider", (stack) =>
23 Effect.gen(function* () {
24 yield* stack.destroy();
25
26 const deployed = yield* stack.deploy(
27 Effect.gen(function* () {
28 return yield* OpenIDConnectProvider("ListOidcProvider", {
29 url: testOidcListUrl,
30 clientIDList: ["sts.amazonaws.com"],
31 thumbprintList: [testOidcThumbprintA],
32 tags: { env: "test" },
33 });
34 }),
35 );
36
37 const provider = yield* Provider.findProvider(OpenIDConnectProvider);
38 const all = yield* provider.list();
39
40 expect(
41 all.some((p) => p.openIDConnectProviderArn === deployed.openIDConnectProviderArn),
42 ).toBe(true);
43
44 const found = all.find(
45 (p) => p.openIDConnectProviderArn === deployed.openIDConnectProviderArn,
46 );
47 expect(found?.url).toBe(testOidcListUrl.replace(/^https?:\/\//, ""));
48 expect(found?.clientIDList ?? []).toContain("sts.amazonaws.com");
49
50 yield* stack.destroy();
51
52 const deleted = yield* IAM.getOpenIDConnectProvider({
53 OpenIDConnectProviderArn: deployed.openIDConnectProviderArn,
54 }).pipe(Effect.option);
55 expect(deleted._tag).toBe("None");
56 }),
57 );
58
59 test.provider(
60 "recovers a half-created provider whose creating-state lost Output-valued props (#736)",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const deployProvider = () =>
66 stack.deploy(
67 Effect.gen(function* () {
68 return yield* OpenIDConnectProvider("WedgedOidcProvider", {
69 url: testOidcWedgedUrl,
70 clientIDList: ["sts.amazonaws.com"],
71 thumbprintList: [testOidcThumbprintA],
72 });
73 }),
74 );
75
76 const created = yield* deployProvider();
77
78 // Rewrite the provider's persisted row into the wedged shape an
79 // interrupted deploy leaves behind: `creating`, no attributes, and
80 // the Output-valued `url` prop lost in the round-trip.
81 const state = yield* yield* State;
82 const stage = stack.stage;
83 const fqns = yield* state.list({ stack: stack.name, stage });
84 const rows = yield* Effect.forEach(fqns, (fqn) =>
85 state.get({ stack: stack.name, stage, fqn }).pipe(Effect.map((row) => ({ fqn, row }))),
86 );
87 const wedged = rows.find(
88 (r): r is { fqn: string; row: ResourceState } =>
89 isResourceState(r.row) && r.row.resourceType === "AWS.IAM.OpenIDConnectProvider",
90 );
91 if (!wedged) {
92 return yield* Effect.die(
93 new Error("no AWS.IAM.OpenIDConnectProvider state row found after deploy"),
94 );
95 }
96 yield* state.set({
97 stack: stack.name,
98 stage,
99 fqn: wedged.fqn,
100 value: {
101 ...wedged.row,
102 status: "creating",
103 attr: undefined,
104 props: { ...wedged.row.props, url: undefined },
105 },
106 });
107
108 // Before the fix this crashed in `read` with
109 // `TypeError: undefined is not an object (evaluating 'url.replace')`.
110 const recovered = yield* deployProvider();
111 expect(recovered.openIDConnectProviderArn).toEqual(created.openIDConnectProviderArn);
112 expect(recovered.url).toEqual(created.url);
113
114 yield* stack.destroy();
115
116 const deleted = yield* IAM.getOpenIDConnectProvider({
117 OpenIDConnectProviderArn: created.openIDConnectProviderArn,
118 }).pipe(Effect.option);
119 expect(deleted._tag).toBe("None");
120 }),
121 { timeout: 240_000 },
122 );
123 },
124 );