The best way to control Claude Code, Codex and more from any computer or phone

main
ts 103 lines 3.61 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.getOrganizationsSpaces({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag(["NotFound", "ApigeeResourceNotFound"], () => 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 "getOrganizationsSpaces on a missing space fails with ApigeeResourceNotFound",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 apigee.getOrganizationsSpaces({
41 name: `organizations/${project}/spaces/alchemy-apigee-missing-space`,
42 }),
43 );
44 expect(error._tag).toEqual("ApigeeResourceNotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
49 );
50
51 test.provider.skipIf(!runLifecycle)(
52 "create, update, and delete an Apigee space",
53 (stack) =>
54 Effect.gen(function* () {
55 const { project } = yield* GcpEnvironment.current;
56
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.Apigee.Space("Team", {
62 displayName: "alchemy test space",
63 });
64 }),
65 );
66
67 expect(created.spaceId).toEqual(expect.any(String));
68 expect(created.organization).toEqual(project);
69 expect(created.name).toEqual(`organizations/${project}/spaces/${created.spaceId}`);
70 expect(created.displayName).toEqual("alchemy test space");
71
72 const fetched = yield* apigee.getOrganizationsSpaces({
73 name: created.name,
74 });
75 expect(fetched.name).toEqual(created.name);
76 expect(fetched.displayName).toContain("alchemy-id=");
77 expect(fetched.displayName).toContain("alchemy test space");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.Apigee.Space("Team", {
82 spaceId: created.spaceId,
83 displayName: "alchemy updated space",
84 });
85 }),
86 );
87
88 expect(updated.spaceId).toEqual(created.spaceId);
89 expect(updated.displayName).toEqual("alchemy updated space");
90
91 const fetchedUpdate = yield* apigee.getOrganizationsSpaces({
92 name: updated.name,
93 });
94 expect(fetchedUpdate.displayName).toContain("alchemy updated space");
95 expect(fetchedUpdate.displayName).toContain("alchemy-id=");
96
97 yield* stack.destroy();
98
99 const gone = yield* waitUntilGone(created.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
103 );