1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as datalineage from "@distilled.cloud/gcp/datalineage_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import * as Schedule from "effect/Schedule";
8import { GcpEnvironment } from "@/GCP/Environment";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17const waitUntilGone = (name: string) =>
18 datalineage.getProjectsLocationsProcesses({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "getProjectsLocationsProcesses on a missing process fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 datalineage.getProjectsLocationsProcesses({
38 name: `projects/${project}/locations/us-central1/processes/alchemy-missing-process`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 {
46 tags: ["provider:gcp", "provider:gcp:datalineage", "live"],
47 timeout: 90_000,
48 },
49);
50
51test.provider.skipIf(!!process.env.FAST)(
52 "create, update, and delete a lineage process",
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.DataLineage.Process("Etl", {
60 location: "us-central1",
61 displayName: "etl a",
62 origin: { sourceType: "CUSTOM", name: "alchemy" },
63 attributes: { env: "test" },
64 });
65 }),
66 );
67
68 expect(created.name).toContain("/processes/");
69 expect(created.processId).toEqual(expect.any(String));
70 expect(created.location).toEqual("us-central1");
71 expect(created.displayName).toEqual("etl a");
72 expect(created.origin?.sourceType).toEqual("CUSTOM");
73 expect(created.attributes).toMatchObject({ env: "test" });
74
75 const fetched = yield* datalineage.getProjectsLocationsProcesses({
76 name: created.name,
77 });
78 expect(fetched.name).toEqual(created.name);
79 expect(fetched.displayName).toEqual("etl a");
80 expect(fetched.attributes?.env).toEqual("test");
81 expect(
82 Object.keys(fetched.attributes ?? {}).some((key) =>
83 key.startsWith("alchemy-"),
84 ),
85 ).toEqual(true);
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.DataLineage.Process("Etl", {
90 processId: created.processId,
91 location: "us-central1",
92 displayName: "etl b",
93 origin: { sourceType: "CUSTOM", name: "dbt" },
94 attributes: { env: "prod", team: "data" },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.displayName).toEqual("etl b");
101 expect(updated.origin?.name).toEqual("dbt");
102 expect(updated.attributes).toMatchObject({ env: "prod", team: "data" });
103
104 yield* stack.destroy();
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:datalineage", "live"],
110 timeout: 90_000,
111 },
112);