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

main
ts 91 lines 3.35 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 // Each serverless workload reserves 12 vCPUs and hundreds of GB of Hyperdisk;
15 // next to the rest of the suite the testing project's quotas run out
16 // (`Quota 'HDB_TOTAL_GB' exceeded. Limit: 500.0 in region us-central1`,
17 // `Insufficient 'CPUS_ALL_REGIONS' quota`). Passes solo in ~2 minutes; set
18 // GCP_TEST_DATAPROC_SERVERLESS=1 on a project with headroom.
19 const runLifecycle = !!process.env.GCP_TEST_DATAPROC_SERVERLESS && !process.env.FAST;
20
21 const waitUntilGone = (name: string) =>
22 dataproc.getProjectsLocationsBatches({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("3 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "getProjectsLocationsBatches on a missing batch fails with NotFound",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 dataproc.getProjectsLocationsBatches({
41 name: `projects/${project}/locations/us-central1/batches/alchemy-dataproc-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 90_000 },
49 );
50
51 test.provider.skipIf(!runLifecycle)(
52 "create and delete a spark batch",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.Dataproc.Batch("Pi", {
60 location: "us-central1",
61 sparkBatch: {
62 mainClass: "org.apache.spark.examples.SparkPi",
63 jarFileUris: ["file:///usr/lib/spark/examples/jars/spark-examples.jar"],
64 args: ["1"],
65 },
66 environmentConfig: { executionConfig: { ttl: "600s" } },
67 labels: { env: "test" },
68 });
69 }),
70 );
71
72 expect(created.name).toContain("/batches/");
73 expect(created.batchId).toEqual(expect.any(String));
74 expect(created.location).toEqual("us-central1");
75 expect(created.labels).toMatchObject({ env: "test" });
76 expect(created.state).toEqual(expect.any(String));
77
78 const fetched = yield* dataproc.getProjectsLocationsBatches({
79 name: created.name,
80 });
81 expect(fetched.name).toEqual(created.name);
82 expect(fetched.labels?.env).toEqual("test");
83 expect(fetched.sparkBatch?.mainClass).toEqual("org.apache.spark.examples.SparkPi");
84
85 yield* stack.destroy();
86
87 const gone = yield* waitUntilGone(created.name);
88 expect(gone).toEqual("gone");
89 }).pipe(logLevel),
90 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 600_000 },
91 );