@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 115 lines 4.22 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.getOrganizationsAppgroupsApps({ 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 "getOrganizationsAppgroupsApps on a missing app 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.getOrganizationsAppgroupsApps({
43 name: `${org}/appgroups/missing-group/apps/alchemy-missing`,
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",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const group = yield* GCP.Apigee.Appgroup("Partners", {
62 displayName: "Partners",
63 email: "partners@example.com",
64 });
65 const app = yield* GCP.Apigee.AppgroupsApp("Mobile", {
66 appgroup: group.appgroupId,
67 callbackUrl: "https://example.com/oauth",
68 attributes: [{ name: "team", value: "platform" }],
69 });
70 return { group, app };
71 }),
72 );
73
74 expect(created.app.appId).toEqual(expect.any(String));
75 expect(created.app.appgroupId).toEqual(created.group.appgroupId);
76 expect(created.app.callbackUrl).toEqual("https://example.com/oauth");
77 expect(created.app.attributes).toEqual(
78 expect.arrayContaining([{ name: "team", value: "platform" }]),
79 );
80
81 const fetched = yield* apigee.getOrganizationsAppgroupsApps({
82 name: created.app.name,
83 });
84 expect(fetched.attributes?.some((item) => item.name === "alchemy-id")).toEqual(true);
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 const group = yield* GCP.Apigee.Appgroup("Partners", {
89 appgroupId: created.group.appgroupId,
90 displayName: "Partners",
91 email: "partners@example.com",
92 });
93 const app = yield* GCP.Apigee.AppgroupsApp("Mobile", {
94 appgroup: group.appgroupId,
95 appId: created.app.appId,
96 callbackUrl: "https://example.com/updated",
97 attributes: [{ name: "team", value: "runtime" }],
98 });
99 return { group, app };
100 }),
101 );
102
103 expect(updated.app.name).toEqual(created.app.name);
104 expect(updated.app.callbackUrl).toEqual("https://example.com/updated");
105 expect(updated.app.attributes).toEqual(
106 expect.arrayContaining([{ name: "team", value: "runtime" }]),
107 );
108
109 yield* stack.destroy();
110
111 const gone = yield* waitUntilGone(created.app.name);
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
115 );