The best way to control Claude Code, Codex and more from any computer or phone
| 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 datalineage from "@distilled.cloud/gcp/datalineage_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 | const waitUntilGone = (name: string) => |
| 15 | datalineage.getProjectsLocationsProcessesRunsLineageEvents({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider.skipIf(!!process.env.FAST)( |
| 26 | "create and delete a lineage event", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const created = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | const process = yield* GCP.DataLineage.Process("Etl", { |
| 36 | location: "us-central1", |
| 37 | displayName: "event parent", |
| 38 | attributes: { env: "test" }, |
| 39 | }); |
| 40 | const run = yield* GCP.DataLineage.ProcessesRun("Nightly", { |
| 41 | process: process.name, |
| 42 | startTime: "2024-01-01T00:00:00Z", |
| 43 | state: "STARTED", |
| 44 | attributes: { env: "test" }, |
| 45 | }); |
| 46 | const event = yield* GCP.DataLineage.ProcessesRunsLineageEvent("Load", { |
| 47 | run: run.name, |
| 48 | startTime: "2024-01-01T00:00:00Z", |
| 49 | endTime: "2024-01-01T00:05:00Z", |
| 50 | links: [ |
| 51 | { |
| 52 | source: { |
| 53 | fullyQualifiedName: `custom:${project}.raw.orders`, |
| 54 | }, |
| 55 | target: { |
| 56 | fullyQualifiedName: `custom:${project}.dw.orders`, |
| 57 | }, |
| 58 | }, |
| 59 | ], |
| 60 | }); |
| 61 | return { process, run, event }; |
| 62 | }), |
| 63 | ); |
| 64 | |
| 65 | expect(created.event.name).toContain("/lineageEvents/"); |
| 66 | expect(created.event.lineageEventId).toEqual(expect.any(String)); |
| 67 | expect(created.event.run).toEqual(created.run.name); |
| 68 | expect(created.event.process).toEqual(created.process.name); |
| 69 | expect(created.event.links.length).toEqual(1); |
| 70 | expect(created.event.links[0]?.source.fullyQualifiedName).toContain("raw.orders"); |
| 71 | expect(created.event.links[0]?.target.fullyQualifiedName).toContain("dw.orders"); |
| 72 | |
| 73 | const fetched = yield* datalineage.getProjectsLocationsProcessesRunsLineageEvents({ |
| 74 | name: created.event.name, |
| 75 | }); |
| 76 | expect(fetched.name).toEqual(created.event.name); |
| 77 | expect(fetched.links?.length).toEqual(1); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | const gone = yield* waitUntilGone(created.event.name); |
| 81 | expect(gone).toEqual("gone"); |
| 82 | }).pipe(logLevel), |
| 83 | { |
| 84 | tags: ["provider:gcp", "provider:gcp:datalineage", "live"], |
| 85 | timeout: 90_000, |
| 86 | }, |
| 87 | ); |