@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 146 lines 5.05 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as iap from "@distilled.cloud/gcp/iap_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // IAP OAuth clients hang off an OAuth brand, which only an org-internal project
15 // with a Workspace support email can create (createProjectsBrands otherwise
16 // fails with BadRequest "invalid argument", see probe). Set GCP_TEST_IAP_BRAND
17 // to an existing brand name (projects/{number}/brands/{id}) to run it.
18 const brandName = process.env.GCP_TEST_IAP_BRAND?.trim();
19
20 const waitUntilGone = (name: string) =>
21 iap.getProjectsBrandsIdentityAwareProxyClients({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsBrandsIdentityAwareProxyClients on a missing client fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 iap.getProjectsBrandsIdentityAwareProxyClients({
40 name: `projects/${project}/brands/1/identityAwareProxyClients/missing`,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
48 );
49
50 test.provider.skipIf(!!brandName)(
51 "createProjectsBrands without a Workspace support email fails with a typed tag",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56
57 const error = yield* Effect.flip(
58 iap.createProjectsBrands({
59 parent: `projects/${project}`,
60 body: {
61 applicationTitle: "Alchemy IAP probe",
62 supportEmail: "iap@example.com",
63 },
64 }),
65 );
66 expect(error._tag).toEqual("BadRequest");
67 expect(error.message).toContain("invalid argument");
68
69 yield* stack.destroy();
70 }).pipe(logLevel),
71 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
72 );
73
74 test.provider.skipIf(!!brandName)(
75 "createProjectsBrandsIdentityAwareProxyClients without a Workspace brand fails with a typed tag",
76 (stack) =>
77 Effect.gen(function* () {
78 const { project } = yield* GcpEnvironment.current;
79 yield* stack.destroy();
80
81 const error = yield* Effect.flip(
82 iap.createProjectsBrandsIdentityAwareProxyClients({
83 parent: `projects/${project}/brands/missing`,
84 body: { displayName: "Alchemy IAP client probe" },
85 }),
86 );
87 expect(error._tag).toEqual("BadRequest");
88 expect(error.message).toContain("Unable to parse project number and brand");
89
90 yield* stack.destroy();
91 }).pipe(logLevel),
92 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
93 );
94
95 test.provider.skipIf(!brandName)(
96 "create, replace, and delete an IAP OAuth client",
97 (stack) =>
98 Effect.gen(function* () {
99 yield* stack.destroy();
100 const brand = brandName!;
101
102 const created = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.IAP.BrandsIdentityAwareProxyClient("Console", {
105 brand,
106 displayName: "Alchemy console",
107 });
108 }),
109 );
110
111 expect(created.name).toContain("/identityAwareProxyClients/");
112 expect(created.brand).toEqual(brand);
113 expect(created.displayName).toEqual("Alchemy console");
114 expect(created.identityAwareProxyClientId.length).toBeGreaterThan(0);
115
116 const fetched = yield* iap.getProjectsBrandsIdentityAwareProxyClients({
117 name: created.name,
118 });
119 expect(fetched.name).toEqual(created.name);
120 expect(fetched.displayName).toContain("[alchemy ");
121 expect(fetched.displayName).toContain("Alchemy console");
122
123 const replaced = yield* stack.deploy(
124 Effect.gen(function* () {
125 return yield* GCP.IAP.BrandsIdentityAwareProxyClient("Console", {
126 brand,
127 displayName: "Alchemy portal",
128 });
129 }),
130 );
131
132 expect(replaced.displayName).toEqual("Alchemy portal");
133 expect(replaced.brand).toEqual(brand);
134
135 const fetchedReplace = yield* iap.getProjectsBrandsIdentityAwareProxyClients({
136 name: replaced.name,
137 });
138 expect(fetchedReplace.displayName).toContain("Alchemy portal");
139
140 yield* stack.destroy();
141
142 const gone = yield* waitUntilGone(replaced.name);
143 expect(gone).toEqual("gone");
144 }).pipe(logLevel),
145 { tags: ["provider:gcp", "provider:gcp:iap", "live"], timeout: 90_000 },
146 );