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

main
ts 111 lines 3.9 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.getOrganizationsApisKeyvaluemapsEntries({ 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 "getOrganizationsApisKeyvaluemapsEntries on a missing entry 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.getOrganizationsApisKeyvaluemapsEntries({
43 name: `${org}/apis/missing-api/keyvaluemaps/missing-map/entries/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 api key value map entry",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const api = yield* GCP.Apigee.Api("Orders", {});
62 const map = yield* GCP.Apigee.ApisKeyvaluemap("Config", {
63 api: api.apiId,
64 });
65 const entry = yield* GCP.Apigee.ApisKeyvaluemapsEntry("Timeout", {
66 api: api.apiId,
67 map: map.mapId,
68 value: "5000",
69 });
70 return { api, map, entry };
71 }),
72 );
73
74 expect(created.entry.entryId).toEqual(expect.any(String));
75 expect(created.entry.value).toEqual("5000");
76 expect(created.entry.mapId).toEqual(created.map.mapId);
77
78 const fetched = yield* apigee.getOrganizationsApisKeyvaluemapsEntries({
79 name: created.entry.name,
80 });
81 expect(fetched.value).toEqual("5000");
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 const api = yield* GCP.Apigee.Api("Orders", {
86 apiId: created.api.apiId,
87 });
88 const map = yield* GCP.Apigee.ApisKeyvaluemap("Config", {
89 api: api.apiId,
90 mapId: created.map.mapId,
91 });
92 const entry = yield* GCP.Apigee.ApisKeyvaluemapsEntry("Timeout", {
93 api: api.apiId,
94 map: map.mapId,
95 entryId: created.entry.entryId,
96 value: "8000",
97 });
98 return { api, map, entry };
99 }),
100 );
101
102 expect(updated.entry.name).toEqual(created.entry.name);
103 expect(updated.entry.value).toEqual("8000");
104
105 yield* stack.destroy();
106
107 const gone = yield* waitUntilGone(created.entry.name);
108 expect(gone).toEqual("gone");
109 }).pipe(logLevel),
110 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
111 );