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

main
ts 105 lines 3.88 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 dataplex from "@distilled.cloud/gcp/dataplex_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { withDataplexSlot } from "./quota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const waitUntilGone = (name: string) =>
16 dataplex.getProjectsLocationsLakesTasks({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 const serviceAccountOf = GcpEnvironment.current.pipe(
27 Effect.map(({ project }) => `alchemy-testing@${project}.iam.gserviceaccount.com`),
28 );
29
30 test.provider.skipIf(!!process.env.FAST)(
31 "create, update, and delete a lake task",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35 const serviceAccount = yield* serviceAccountOf;
36
37 const created = yield* stack.deploy(
38 Effect.gen(function* () {
39 const lake = yield* GCP.Dataplex.Lake("Warehouse", {
40 location: "us-central1",
41 labels: { env: "test" },
42 });
43 const task = yield* GCP.Dataplex.LakesTask("SelectOne", {
44 lake: lake.name,
45 displayName: "select one",
46 description: "on demand sql",
47 labels: { env: "test" },
48 triggerSpec: { type: "ON_DEMAND" },
49 executionSpec: {
50 serviceAccount,
51 args: { output_location: "gs://dataplex-task-output/out" },
52 },
53 spark: { sqlScript: "SELECT 1" },
54 });
55 return { lake, task };
56 }),
57 );
58
59 expect(created.task.name).toContain("/tasks/");
60 expect(created.task.taskId).toEqual(expect.any(String));
61 expect(created.task.lake).toEqual(created.lake.name);
62 expect(created.task.triggerType).toEqual("ON_DEMAND");
63 expect(created.task.labels).toMatchObject({ env: "test" });
64
65 const fetched = yield* dataplex.getProjectsLocationsLakesTasks({
66 name: created.task.name,
67 });
68 expect(fetched.name).toEqual(created.task.name);
69 expect(fetched.spark?.sqlScript).toEqual("SELECT 1");
70
71 const updated = yield* stack.deploy(
72 Effect.gen(function* () {
73 const lake = yield* GCP.Dataplex.Lake("Warehouse", {
74 lakeId: created.lake.lakeId,
75 location: "us-central1",
76 labels: { env: "test" },
77 });
78 const task = yield* GCP.Dataplex.LakesTask("SelectOne", {
79 lake: lake.name,
80 taskId: created.task.taskId,
81 displayName: "select two",
82 description: "on demand sql b",
83 labels: { env: "prod", team: "data" },
84 triggerSpec: { type: "ON_DEMAND" },
85 executionSpec: {
86 serviceAccount,
87 args: { output_location: "gs://dataplex-task-output/out" },
88 },
89 spark: { sqlScript: "SELECT 2" },
90 });
91 return { lake, task };
92 }),
93 );
94
95 expect(updated.task.name).toEqual(created.task.name);
96 expect(updated.task.displayName).toEqual("select two");
97 expect(updated.task.description).toEqual("on demand sql b");
98 expect(updated.task.labels).toMatchObject({ env: "prod", team: "data" });
99
100 yield* stack.destroy();
101 const gone = yield* waitUntilGone(created.task.name);
102 expect(gone).toEqual("gone");
103 }).pipe(logLevel, withDataplexSlot),
104 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
105 );