@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 106 lines 3.77 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 // Apigee X organizations are 1:1 with the GCP project. Deploying
21 // GCP.Apigee.Organization against that project would adopt/update (and
22 // destroy would delete) the account org. Keep lifecycle skipped.
23 const runOrgLifecycle = false;
24
25 const waitUntilGone = (name: string) =>
26 apigee.getOrganizations({ name }).pipe(
27 Effect.as("found" as const),
28 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
29 Effect.catchTag("ApigeeResourceNotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("2 seconds"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );
36
37 test.provider(
38 "getOrganizations on a missing organization fails with ApigeeResourceNotFound",
39 (stack) =>
40 Effect.gen(function* () {
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 apigee.getOrganizations({
45 name: "organizations/alchemy-missing-org",
46 }),
47 );
48 expect(error._tag).toEqual("ApigeeResourceNotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
53 );
54
55 test.provider.skipIf(!runLifecycle || !runOrgLifecycle)(
56 "create, update, and delete an organization",
57 (stack) =>
58 Effect.gen(function* () {
59 const { project } = yield* GcpEnvironment.current;
60 const org = `organizations/${project}`;
61
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.Apigee.Organization("Org", {
67 displayName: "alchemy-org",
68 description: "alchemy test org",
69 disableVpcPeering: true,
70 });
71 }),
72 );
73
74 expect(created.organizationId).toEqual(project);
75 expect(created.name).toEqual(org);
76 expect(created.displayName).toEqual("alchemy-org");
77 expect(created.description).toEqual("alchemy test org");
78
79 const fetched = yield* apigee.getOrganizations({
80 name: created.name,
81 });
82 expect(fetched.description).toContain("alchemy-id=");
83 expect(fetched.description).toContain("alchemy test org");
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 return yield* GCP.Apigee.Organization("Org", {
88 organizationId: created.organizationId,
89 displayName: "alchemy-org-updated",
90 description: "updated alchemy test org",
91 disableVpcPeering: true,
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.displayName).toEqual("alchemy-org-updated");
98 expect(updated.description).toEqual("updated alchemy test org");
99
100 yield* stack.destroy();
101
102 const gone = yield* waitUntilGone(created.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
106 );