@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 123 lines 4.35 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 apigee from "@distilled.cloud/gcp/apigee_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 // Needs a provisioned Apigee organization on the testing project (paid, or
15 // ~1h eval provisioning); without one calls fail with ApigeeResourceNotFound (403 "Permission
16 // denied on resource \"organizations/{project}\" (or it may not exist)").
17 // Set GCP_TEST_APIGEE_ORG=1 when the org exists.
18 const runLifecycle = !!process.env.GCP_TEST_APIGEE_ORG;
19
20 const waitUntilGone = (name: string) =>
21 apigee.getOrganizationsAppgroupsAppsKeys({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.catchTag("ApigeeResourceNotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("1 second"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "getOrganizationsAppgroupsAppsKeys on a missing key fails with ApigeeResourceNotFound",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37 const org = `organizations/${project}`;
38
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 apigee.getOrganizationsAppgroupsAppsKeys({
43 name: `${org}/appgroups/missing-group/apps/missing-app/keys/missing-key`,
44 }),
45 );
46 expect(error._tag).toEqual("ApigeeResourceNotFound");
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
51 );
52
53 test.provider.skipIf(!runLifecycle)(
54 "create, update, and delete an appgroup app key",
55 (stack) =>
56 Effect.gen(function* () {
57 const { project } = yield* GcpEnvironment.current;
58 const org = `organizations/${project}`;
59
60 yield* stack.destroy();
61
62 const group = yield* apigee.createOrganizationsAppgroups({
63 parent: org,
64 body: { name: "alchemy-appgroup", displayName: "alchemy-appgroup" },
65 });
66 const groupId = group.name ?? "alchemy-appgroup";
67 const groupParent = groupId.includes("/appgroups/") ? groupId : `${org}/appgroups/${groupId}`;
68
69 const app = yield* apigee.createOrganizationsAppgroupsApps({
70 parent: groupParent,
71 body: { name: "alchemy-app" },
72 });
73 const appName = app.name ?? "alchemy-app";
74
75 const created = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.Apigee.AppgroupsAppsKey("GroupKey", {
78 appGroup: groupId,
79 app: appName,
80 attributes: { team: "platform" },
81 });
82 }),
83 );
84
85 expect(created.consumerKey).toEqual(expect.any(String));
86 expect(created.attributes).toMatchObject({ team: "platform" });
87
88 const fetched = yield* apigee.getOrganizationsAppgroupsAppsKeys({
89 name: created.name,
90 });
91 expect(fetched.consumerKey).toEqual(created.consumerKey);
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 return yield* GCP.Apigee.AppgroupsAppsKey("GroupKey", {
96 appGroup: groupId,
97 app: appName,
98 consumerKey: created.consumerKey,
99 consumerSecret: created.consumerSecret,
100 attributes: { team: "runtime" },
101 });
102 }),
103 );
104
105 expect(updated.name).toEqual(created.name);
106 expect(updated.attributes).toMatchObject({ team: "runtime" });
107
108 yield* stack.destroy();
109
110 const gone = yield* waitUntilGone(created.name);
111 expect(gone).toEqual("gone");
112
113 yield* apigee
114 .deleteOrganizationsAppgroupsApps({
115 name: `${groupParent}/apps/${appName}`,
116 })
117 .pipe(Effect.catchTag("NotFound", () => Effect.void));
118 yield* apigee
119 .deleteOrganizationsAppgroups({ name: groupParent })
120 .pipe(Effect.catchTag("NotFound", () => Effect.void));
121 }).pipe(logLevel),
122 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
123 );