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

main
ts 145 lines 5.15 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.getProjectsLocationsPrivateCloudsLoggingServers({ 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 "getProjectsLocationsPrivateCloudsLoggingServers on a missing logging server 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.getProjectsLocationsPrivateCloudsLoggingServers({
39 name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-missing/loggingServers/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 a logging server",
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: "syslog 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: "syslog parent",
75 });
76 const syslog = yield* GCP.VMwareEngine.PrivateCloudsLoggingServer("Esxi", {
77 privateCloud: cloud.name,
78 hostname: "logs.example.com",
79 port: 514,
80 protocol: "UDP",
81 sourceType: "ESXI",
82 });
83 return { ven, cloud, syslog };
84 }),
85 );
86
87 expect(created.syslog.name).toContain("/loggingServers/");
88 expect(created.syslog.hostname).toEqual("logs.example.com");
89 expect(created.syslog.port).toEqual(514);
90 expect(created.syslog.protocol).toEqual("UDP");
91 expect(created.syslog.sourceType).toEqual("ESXI");
92
93 const fetched = yield* vmwareengine.getProjectsLocationsPrivateCloudsLoggingServers({
94 name: created.syslog.name,
95 });
96 expect(fetched.name).toEqual(created.syslog.name);
97 expect(fetched.hostname).toEqual("logs.example.com");
98
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
102 vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId,
103 type: "STANDARD",
104 description: "syslog grandparent",
105 });
106 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
107 privateCloudId: created.cloud.privateCloudId,
108 location: "us-central1-a",
109 networkConfig: {
110 managementCidr: "192.168.1.0/24",
111 vmwareEngineNetwork: ven.name,
112 },
113 managementCluster: {
114 clusterId: "mgmt",
115 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
116 },
117 description: "syslog parent",
118 });
119 const syslog = yield* GCP.VMwareEngine.PrivateCloudsLoggingServer("Esxi", {
120 privateCloud: cloud.name,
121 loggingServerId: created.syslog.loggingServerId,
122 hostname: "logs.example.com",
123 port: 6514,
124 protocol: "TCP",
125 sourceType: "VCSA",
126 });
127 return { ven, cloud, syslog };
128 }),
129 );
130
131 expect(updated.syslog.name).toEqual(created.syslog.name);
132 expect(updated.syslog.port).toEqual(6514);
133 expect(updated.syslog.protocol).toEqual("TCP");
134 expect(updated.syslog.sourceType).toEqual("VCSA");
135
136 yield* stack.destroy();
137
138 const gone = yield* waitUntilGone(created.syslog.name);
139 expect(gone).toEqual("gone");
140 }).pipe(logLevel),
141 {
142 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
143 timeout: 120_000,
144 },
145 );