@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 182 lines 6.76 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 workstations from "@distilled.cloud/gcp/workstations_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 // Workstation clusters take ~20 minutes to create and delete.
14 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
15
16 test.provider(
17 "getProjectsLocationsWorkstationClusters on a missing cluster fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 const { project } = yield* GcpEnvironment.current;
21 yield* stack.destroy();
22
23 const error = yield* Effect.flip(
24 workstations.getProjectsLocationsWorkstationClusters({
25 name: `projects/${project}/locations/us-central1/workstationClusters/alchemy-missing-cluster`,
26 }),
27 );
28 expect(error._tag).toEqual("NotFound");
29
30 const page = yield* workstations.listProjectsLocationsWorkstationClusters({
31 parent: `projects/${project}/locations/-`,
32 pageSize: 10,
33 });
34 expect((page.workstationClusters ?? []).map((item) => item.name)).not.toContain(
35 `projects/${project}/locations/us-central1/workstationClusters/alchemy-missing-cluster`,
36 );
37
38 yield* stack.destroy();
39 }).pipe(logLevel),
40 {
41 tags: ["provider:gcp", "provider:gcp:workstations", "live"],
42 timeout: 90_000,
43 },
44 );
45
46 test.provider.skipIf(!runLifecycle)(
47 "create against a missing network fails with GCP.OperationFailed",
48 (stack) =>
49 Effect.gen(function* () {
50 const { project } = yield* GcpEnvironment.current;
51 yield* stack.destroy();
52
53 const error = yield* Effect.flip(
54 stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.Workstations.WorkstationCluster("Dev", {
57 network: `projects/${project}/global/networks/alchemy-missing-vpc`,
58 subnetwork: `projects/${project}/regions/us-central1/subnetworks/alchemy-missing-subnet`,
59 displayName: "alchemy-test-cluster",
60 labels: { env: "test" },
61 });
62 }),
63 ),
64 );
65 // The cluster is accepted and provisioned before the network is
66 // validated, so the create operation fails late (~50 minutes).
67 expect(error._tag).toEqual("GCP.OperationFailed");
68
69 yield* stack.destroy();
70 }).pipe(logLevel),
71 {
72 tags: ["provider:gcp", "provider:gcp:workstations", "live"],
73 // One attempt that outlasts GCP's late failure; a retry would restart
74 // the ~50-minute wait from scratch.
75 timeout: 4_500_000,
76 retry: 0,
77 },
78 );
79
80 test.provider.skipIf(!runLifecycle)(
81 "create, update, and delete a workstation cluster, config, and workstation",
82 (stack) =>
83 Effect.gen(function* () {
84 yield* stack.destroy();
85
86 const created = yield* stack.deploy(
87 Effect.gen(function* () {
88 const cluster = yield* GCP.Workstations.WorkstationCluster("Dev", {
89 location: "us-central1",
90 network: "default",
91 subnetwork: "default",
92 displayName: "alchemy-test-cluster",
93 labels: { env: "test" },
94 });
95 const config = yield* GCP.Workstations.WorkstationClustersWorkstationConfig("Code", {
96 workstationCluster: cluster.name,
97 displayName: "alchemy-test-config",
98 idleTimeout: "300s",
99 host: {
100 gceInstance: {
101 machineType: "e2-standard-2",
102 poolSize: 0,
103 bootDiskSizeGb: 30,
104 },
105 },
106 labels: { env: "test" },
107 });
108 const workstation =
109 yield* GCP.Workstations.WorkstationClustersWorkstationConfigsWorkstation("Mine", {
110 workstationConfig: config.name,
111 displayName: "alchemy-test-station",
112 labels: { env: "test" },
113 });
114 return { cluster, config, workstation };
115 }),
116 );
117
118 expect(created.cluster.name).toContain("/workstationClusters/");
119 expect(created.cluster.labels).toMatchObject({ env: "test" });
120 expect(created.config.workstationCluster).toEqual(created.cluster.name);
121 expect(created.workstation.workstationConfig).toEqual(created.config.name);
122
123 const fetched = yield* workstations.getProjectsLocationsWorkstationClusters({
124 name: created.cluster.name,
125 });
126 expect(fetched.name).toEqual(created.cluster.name);
127 expect(fetched.labels?.env).toEqual("test");
128
129 const updated = yield* stack.deploy(
130 Effect.gen(function* () {
131 const cluster = yield* GCP.Workstations.WorkstationCluster("Dev", {
132 workstationClusterId: created.cluster.workstationClusterId,
133 location: "us-central1",
134 network: "default",
135 subnetwork: "default",
136 displayName: "alchemy-test-cluster-v2",
137 labels: { env: "prod", role: "dev" },
138 });
139 const config = yield* GCP.Workstations.WorkstationClustersWorkstationConfig("Code", {
140 workstationConfigId: created.config.workstationConfigId,
141 workstationCluster: cluster.name,
142 displayName: "alchemy-test-config-v2",
143 idleTimeout: "600s",
144 labels: { env: "prod" },
145 });
146 const workstation =
147 yield* GCP.Workstations.WorkstationClustersWorkstationConfigsWorkstation("Mine", {
148 workstationId: created.workstation.workstationId,
149 workstationConfig: config.name,
150 displayName: "alchemy-test-station-v2",
151 labels: { env: "prod" },
152 });
153 return { cluster, config, workstation };
154 }),
155 );
156
157 expect(updated.cluster.workstationClusterId).toEqual(created.cluster.workstationClusterId);
158 expect(updated.cluster.displayName).toEqual("alchemy-test-cluster-v2");
159 expect(updated.cluster.labels).toMatchObject({
160 env: "prod",
161 role: "dev",
162 });
163 expect(updated.config.displayName).toEqual("alchemy-test-config-v2");
164 expect(updated.workstation.displayName).toEqual("alchemy-test-station-v2");
165
166 yield* stack.destroy();
167
168 const gone = yield* workstations
169 .getProjectsLocationsWorkstationClusters({
170 name: created.cluster.name,
171 })
172 .pipe(
173 Effect.as("found" as const),
174 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
175 );
176 expect(gone).toEqual("gone");
177 }).pipe(logLevel),
178 {
179 tags: ["provider:gcp", "provider:gcp:workstations", "live"],
180 timeout: 3_600_000,
181 },
182 );