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

main
ts 139 lines 5.06 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
18 const waitUntilGone = (name: string) =>
19 vmwareengine.getProjectsLocationsPrivateCloudsExternalAddresses({ name }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("2 seconds"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "getProjectsLocationsPrivateCloudsExternalAddresses on a missing address fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 vmwareengine.getProjectsLocationsPrivateCloudsExternalAddresses({
39 name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-missing/externalAddresses/missing`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 {
47 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
48 timeout: 90_000,
49 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create, update, and delete an external address",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
61 type: "STANDARD",
62 description: "address grandparent",
63 });
64 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
65 location: "us-central1-a",
66 networkConfig: {
67 managementCidr: "192.168.1.0/24",
68 vmwareEngineNetwork: ven.name,
69 },
70 managementCluster: {
71 clusterId: "mgmt",
72 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
73 },
74 description: "address parent",
75 });
76 const address = yield* GCP.VMwareEngine.PrivateCloudsExternalAddress("Web", {
77 privateCloud: cloud.name,
78 internalIp: "192.168.1.10",
79 description: "alchemy-test-ea",
80 });
81 return { ven, cloud, address };
82 }),
83 );
84
85 expect(created.address.name).toContain("/externalAddresses/");
86 expect(created.address.internalIp).toEqual("192.168.1.10");
87 expect(created.address.description).toEqual("alchemy-test-ea");
88
89 const fetched = yield* vmwareengine.getProjectsLocationsPrivateCloudsExternalAddresses({
90 name: created.address.name,
91 });
92 expect(fetched.name).toEqual(created.address.name);
93 expect(fetched.description).toContain("alchemy-id=");
94 expect(fetched.description).toContain("alchemy-test-ea");
95
96 const updated = yield* stack.deploy(
97 Effect.gen(function* () {
98 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
99 vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId,
100 type: "STANDARD",
101 description: "address grandparent",
102 });
103 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
104 privateCloudId: created.cloud.privateCloudId,
105 location: "us-central1-a",
106 networkConfig: {
107 managementCidr: "192.168.1.0/24",
108 vmwareEngineNetwork: ven.name,
109 },
110 managementCluster: {
111 clusterId: "mgmt",
112 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
113 },
114 description: "address parent",
115 });
116 const address = yield* GCP.VMwareEngine.PrivateCloudsExternalAddress("Web", {
117 privateCloud: cloud.name,
118 externalAddressId: created.address.externalAddressId,
119 internalIp: "192.168.1.11",
120 description: "alchemy-prod-ea",
121 });
122 return { ven, cloud, address };
123 }),
124 );
125
126 expect(updated.address.name).toEqual(created.address.name);
127 expect(updated.address.internalIp).toEqual("192.168.1.11");
128 expect(updated.address.description).toEqual("alchemy-prod-ea");
129
130 yield* stack.destroy();
131
132 const gone = yield* waitUntilGone(created.address.name);
133 expect(gone).toEqual("gone");
134 }).pipe(logLevel),
135 {
136 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
137 timeout: 120_000,
138 },
139 );