@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.2 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 apihub from "@distilled.cloud/gcp/apihub_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 API Hub instance in us-central1 (one per project,
15 // behind a host project registration); without one writes fail with
16 // BadRequest ("Invalid resource state … API Hub instance …"). Set
17 // GCP_TEST_APIHUB_INSTANCE=1 when the hub exists.
18 const runLifecycle = !!process.env.GCP_TEST_APIHUB_INSTANCE;
19 const location = "us-central1";
20 const resourceUri = "organizations/alchemy/environments/test/apis/orders";
21
22 const waitUntilGone = (name: string) =>
23 apihub.getProjectsLocationsDeployments({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 test.provider(
34 "getProjectsLocationsDeployments on a missing deployment fails with a typed tag",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 apihub.getProjectsLocationsDeployments({
42 name: `projects/${project}/locations/${location}/deployments/alchemy-missing-deployment`,
43 }),
44 );
45 expect(error._tag).toEqual("NotFound");
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 { tags: ["provider:gcp", "provider:gcp:apihub", "live"], timeout: 90_000 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create, update, and delete an API Hub deployment",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.ApiHub.Deployment("Orders", {
61 location,
62 displayName: "orders staging",
63 description: "checkout proxy",
64 resourceUri,
65 endpoints: ["https://orders.example.com"],
66 });
67 }),
68 );
69
70 expect(created.name).toContain("/deployments/");
71 expect(created.deploymentId).toEqual(expect.any(String));
72 expect(created.location).toEqual(location);
73 expect(created.displayName).toEqual("orders staging");
74 expect(created.description).toEqual("checkout proxy");
75 expect(created.resourceUri).toEqual(resourceUri);
76 expect(created.endpoints).toEqual(["https://orders.example.com"]);
77
78 const fetched = yield* apihub.getProjectsLocationsDeployments({
79 name: created.name,
80 });
81 expect(fetched.name).toEqual(created.name);
82 expect(fetched.description).toContain("alchemy-id=");
83 expect(fetched.description).toContain("checkout proxy");
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 return yield* GCP.ApiHub.Deployment("Orders", {
88 deploymentId: created.deploymentId,
89 location,
90 displayName: "orders staging",
91 description: "checkout proxy (updated)",
92 resourceUri,
93 endpoints: ["https://orders.example.com", "https://orders-alt.example.com"],
94 });
95 }),
96 );
97
98 expect(updated.name).toEqual(created.name);
99 expect(updated.description).toEqual("checkout proxy (updated)");
100 expect(updated.endpoints).toEqual([
101 "https://orders.example.com",
102 "https://orders-alt.example.com",
103 ]);
104
105 const fetchedUpdate = yield* apihub.getProjectsLocationsDeployments({
106 name: created.name,
107 });
108 expect(fetchedUpdate.description).toContain("checkout proxy (updated)");
109
110 yield* stack.destroy();
111 const gone = yield* waitUntilGone(created.name);
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 { tags: ["provider:gcp", "provider:gcp:apihub", "live"], timeout: 90_000 },
115 );