@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 135 lines 4.81 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.getProjectsLocationsPrivateCloudsClusters({ 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 "getProjectsLocationsPrivateCloudsClusters on a missing cluster 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.getProjectsLocationsPrivateCloudsClusters({
39 name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-missing/clusters/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 private cloud cluster",
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: "cluster 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: "cluster parent",
75 });
76 const cluster = yield* GCP.VMwareEngine.PrivateCloudsCluster("Work", {
77 privateCloud: cloud.name,
78 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
79 });
80 return { ven, cloud, cluster };
81 }),
82 );
83
84 expect(created.cluster.name).toContain("/clusters/");
85 expect(created.cluster.management).toEqual(false);
86 expect(created.cluster.privateCloud).toEqual(created.cloud.name);
87
88 const fetched = yield* vmwareengine.getProjectsLocationsPrivateCloudsClusters({
89 name: created.cluster.name,
90 });
91 expect(fetched.name).toEqual(created.cluster.name);
92 expect(fetched.management).toEqual(false);
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 type: "STANDARD",
99 description: "cluster grandparent",
100 });
101 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
102 privateCloudId: created.cloud.privateCloudId,
103 location: "us-central1-a",
104 networkConfig: {
105 managementCidr: "192.168.1.0/24",
106 vmwareEngineNetwork: ven.name,
107 },
108 managementCluster: {
109 clusterId: "mgmt",
110 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
111 },
112 description: "cluster parent",
113 });
114 const cluster = yield* GCP.VMwareEngine.PrivateCloudsCluster("Work", {
115 privateCloud: cloud.name,
116 clusterId: created.cluster.clusterId,
117 nodeTypeConfigs: { "standard-72": { nodeCount: 4 } },
118 });
119 return { ven, cloud, cluster };
120 }),
121 );
122
123 expect(updated.cluster.name).toEqual(created.cluster.name);
124 expect(updated.cluster.nodeTypeConfigs?.["standard-72"]?.nodeCount).toEqual(4);
125
126 yield* stack.destroy();
127
128 const gone = yield* waitUntilGone(created.cluster.name);
129 expect(gone).toEqual("gone");
130 }).pipe(logLevel),
131 {
132 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
133 timeout: 120_000,
134 },
135 );