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

main
ts 99 lines 3.52 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as datalineage from "@distilled.cloud/gcp/datalineage_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 datalineage.getProjectsLocationsProcessesRuns({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider.skipIf(!!process.env.FAST)(
25 "create, update, and delete a lineage run",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 const process = yield* GCP.DataLineage.Process("Etl", {
33 location: "us-central1",
34 displayName: "run parent",
35 attributes: { env: "test" },
36 });
37 const run = yield* GCP.DataLineage.ProcessesRun("Nightly", {
38 process: process.name,
39 startTime: "2024-01-01T00:00:00Z",
40 state: "STARTED",
41 displayName: "nightly a",
42 attributes: { env: "test" },
43 });
44 return { process, run };
45 }),
46 );
47
48 expect(created.run.name).toContain("/runs/");
49 expect(created.run.runId).toEqual(expect.any(String));
50 expect(created.run.process).toEqual(created.process.name);
51 expect(created.run.state).toEqual("STARTED");
52 expect(created.run.displayName).toEqual("nightly a");
53 expect(created.run.attributes).toMatchObject({ env: "test" });
54
55 const fetched = yield* datalineage.getProjectsLocationsProcessesRuns({
56 name: created.run.name,
57 });
58 expect(fetched.name).toEqual(created.run.name);
59 expect(fetched.state).toEqual("STARTED");
60 expect(
61 Object.keys(fetched.attributes ?? {}).some((key) => key.startsWith("alchemy-")),
62 ).toEqual(true);
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 const process = yield* GCP.DataLineage.Process("Etl", {
67 processId: created.process.processId,
68 location: "us-central1",
69 displayName: "run parent",
70 attributes: { env: "test" },
71 });
72 const run = yield* GCP.DataLineage.ProcessesRun("Nightly", {
73 process: process.name,
74 runId: created.run.runId,
75 startTime: "2024-01-01T00:00:00Z",
76 endTime: "2024-01-01T01:00:00Z",
77 state: "COMPLETED",
78 displayName: "nightly b",
79 attributes: { env: "prod" },
80 });
81 return { process, run };
82 }),
83 );
84
85 expect(updated.run.name).toEqual(created.run.name);
86 expect(updated.run.state).toEqual("COMPLETED");
87 expect(updated.run.endTime).toBeDefined();
88 expect(updated.run.displayName).toEqual("nightly b");
89 expect(updated.run.attributes).toMatchObject({ env: "prod" });
90
91 yield* stack.destroy();
92 const gone = yield* waitUntilGone(created.run.name);
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 {
96 tags: ["provider:gcp", "provider:gcp:datalineage", "live"],
97 timeout: 90_000,
98 },
99 );