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

main
ts 132 lines 4.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 vmwareengine from "@distilled.cloud/gcp/vmwareengine_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 // Private clouds need VMware Engine node quota and bill thousands of dollars
15 // a month; set GCP_TEST_VMWAREENGINE=1 on an entitled project to opt in.
16 const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST;
17 const serviceNetworkOf = (project: string) =>
18 process.env.GCP_TEST_VMWAREENGINE_SERVICE_NETWORK ??
19 `projects/${project}/global/networks/default`;
20
21 const waitUntilGone = (name: string) =>
22 vmwareengine.getProjectsLocationsPrivateConnections({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("2 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "getProjectsLocationsPrivateConnections on a missing connection fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 vmwareengine.getProjectsLocationsPrivateConnections({
42 name: `projects/${project}/locations/us-central1/privateConnections/alchemy-pc-missing`,
43 }),
44 );
45 expect(error._tag).toEqual("NotFound");
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
51 timeout: 90_000,
52 },
53 );
54
55 test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete a private connection",
57 (stack) =>
58 Effect.gen(function* () {
59 const { project } = yield* GcpEnvironment.current;
60
61 yield* stack.destroy();
62
63 const created = yield* stack.deploy(
64 Effect.gen(function* () {
65 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
66 type: "STANDARD",
67 description: "alchemy-test-pc-ven",
68 });
69 const connection = yield* GCP.VMwareEngine.PrivateConnection("Peer", {
70 location: "us-central1",
71 type: "THIRD_PARTY_SERVICE",
72 vmwareEngineNetwork: ven.name,
73 serviceNetwork: serviceNetworkOf(project),
74 description: "alchemy-test-pc",
75 });
76 return { ven, connection };
77 }),
78 );
79
80 expect(created.connection.name).toContain("/privateConnections/");
81 expect(created.connection.location).toEqual("us-central1");
82 expect(created.connection.type).toEqual("THIRD_PARTY_SERVICE");
83 expect(created.connection.description).toEqual("alchemy-test-pc");
84 expect(created.connection.vmwareEngineNetwork).toEqual(created.ven.name);
85 expect(created.connection.createTime).toEqual(expect.any(String));
86
87 const fetched = yield* vmwareengine.getProjectsLocationsPrivateConnections({
88 name: created.connection.name,
89 });
90 expect(fetched.name).toEqual(created.connection.name);
91 expect(fetched.description).toContain("alchemy-id=");
92 expect(fetched.description).toContain("alchemy-test-pc");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
97 vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId,
98 location: "global",
99 type: "STANDARD",
100 description: "alchemy-test-pc-ven",
101 });
102 const connection = yield* GCP.VMwareEngine.PrivateConnection("Peer", {
103 privateConnectionId: created.connection.privateConnectionId,
104 location: "us-central1",
105 type: "THIRD_PARTY_SERVICE",
106 vmwareEngineNetwork: ven.name,
107 serviceNetwork: serviceNetworkOf(project),
108 description: "alchemy-prod-pc",
109 });
110 return { ven, connection };
111 }),
112 );
113
114 expect(updated.connection.name).toEqual(created.connection.name);
115 expect(updated.connection.description).toEqual("alchemy-prod-pc");
116
117 const refetched = yield* vmwareengine.getProjectsLocationsPrivateConnections({
118 name: created.connection.name,
119 });
120 expect(refetched.description).toContain("alchemy-prod-pc");
121 expect(refetched.description).toContain("alchemy-id=");
122
123 yield* stack.destroy();
124
125 const gone = yield* waitUntilGone(created.connection.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 {
129 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
130 timeout: 120_000,
131 },
132 );