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

main
ts 116 lines 4 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 dataproc from "@distilled.cloud/gcp/dataproc_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 // Cluster create + update + delete takes ~8 minutes (observed 475s).
15 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
16
17 const waitUntilGone = (projectId: string, region: string, clusterName: string) =>
18 dataproc.getProjectsRegionsClusters({ projectId, region, clusterName }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("3 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsRegionsClusters on a missing cluster fails with NotFound",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 dataproc.getProjectsRegionsClusters({
37 projectId: project,
38 region: "us-central1",
39 clusterName: "alchemy-dataproc-missing",
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 90_000 },
47 );
48
49 test.provider.skipIf(!runLifecycle)(
50 "create, update, and delete a dataproc cluster",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* GCP.Dataproc.Cluster("Spark", {
58 region: "us-central1",
59 clusterType: "SINGLE_NODE",
60 masterMachineType: "e2-standard-2",
61 masterBootDiskSizeGb: 30,
62 labels: { env: "test" },
63 });
64 }),
65 );
66
67 expect(created.name).toContain("/clusters/");
68 expect(created.clusterName).toEqual(expect.any(String));
69 expect(created.region).toEqual("us-central1");
70 expect(created.clusterType).toEqual("SINGLE_NODE");
71 expect(created.labels).toMatchObject({ env: "test" });
72 expect(created.state).toEqual("RUNNING");
73
74 const fetched = yield* dataproc.getProjectsRegionsClusters({
75 projectId: created.project,
76 region: created.region,
77 clusterName: created.clusterName,
78 });
79 expect(fetched.clusterName).toEqual(created.clusterName);
80 expect(fetched.labels?.env).toEqual("test");
81 expect(fetched.status?.state).toEqual("RUNNING");
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.Dataproc.Cluster("Spark", {
86 clusterName: created.clusterName,
87 region: "us-central1",
88 clusterType: "SINGLE_NODE",
89 masterMachineType: "e2-standard-2",
90 masterBootDiskSizeGb: 30,
91 labels: { env: "prod", role: "spark" },
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.labels).toMatchObject({ env: "prod", role: "spark" });
98
99 const refetched = yield* dataproc.getProjectsRegionsClusters({
100 projectId: created.project,
101 region: created.region,
102 clusterName: created.clusterName,
103 });
104 expect(refetched.labels?.env).toEqual("prod");
105 expect(refetched.labels?.role).toEqual("spark");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(created.project, created.region, created.clusterName);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 {
113 tags: ["provider:gcp", "provider:gcp:dataproc", "live"],
114 timeout: 1_800_000,
115 },
116 );