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 datapipelines from "@distilled.cloud/gcp/datapipelines_v1"; |
| 6 | import * as Output from "alchemy/Output"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 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 | datapipelines.getProjectsLocationsPipelines({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("1 second"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | test.provider( |
| 27 | "getProjectsLocationsPipelines on a missing pipeline fails with a typed tag", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const { project } = yield* GcpEnvironment.current; |
| 31 | const parent = `projects/${project}/locations/us-central1`; |
| 32 | |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | datapipelines.getProjectsLocationsPipelines({ |
| 37 | name: `${parent}/pipelines/alchemy-missing-pipeline`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | const page = yield* datapipelines.listProjectsLocationsPipelines({ |
| 43 | parent, |
| 44 | pageSize: 10, |
| 45 | }); |
| 46 | expect( |
| 47 | (page.pipelines ?? []).map((pipeline) => pipeline.name?.split("/").pop()), |
| 48 | ).not.toContain("alchemy-missing-pipeline"); |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | }).pipe(logLevel), |
| 52 | { |
| 53 | tags: ["provider:gcp", "provider:gcp:datapipelines", "live"], |
| 54 | timeout: 90_000, |
| 55 | }, |
| 56 | ); |
| 57 | |
| 58 | test.provider( |
| 59 | "create, update, and delete a data pipeline", |
| 60 | (stack) => |
| 61 | Effect.gen(function* () { |
| 62 | const { project } = yield* GcpEnvironment.current; |
| 63 | |
| 64 | yield* stack.destroy(); |
| 65 | |
| 66 | const created = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | const bucket = yield* GCP.Storage.Bucket("PipelineTmp", { |
| 69 | location: "US-CENTRAL1", |
| 70 | forceDestroy: true, |
| 71 | }); |
| 72 | return yield* GCP.DataPipelines.Pipeline("WordCount", { |
| 73 | type: "PIPELINE_TYPE_BATCH", |
| 74 | displayName: "word-count", |
| 75 | scheduleInfo: { schedule: "0 0 1 1 *", timeZone: "UTC" }, |
| 76 | workload: { |
| 77 | dataflowLaunchTemplateRequest: { |
| 78 | projectId: project, |
| 79 | location: "us-central1", |
| 80 | gcsPath: "gs://dataflow-templates/latest/Word_Count", |
| 81 | launchParameters: { |
| 82 | jobName: "alchemy-word-count", |
| 83 | parameters: { |
| 84 | inputFile: "gs://dataflow-samples/shakespeare/kinglear.txt", |
| 85 | output: Output.interpolate`gs://${bucket.bucketName}/out`, |
| 86 | }, |
| 87 | environment: { |
| 88 | tempLocation: Output.interpolate`gs://${bucket.bucketName}/tmp`, |
| 89 | }, |
| 90 | }, |
| 91 | }, |
| 92 | }, |
| 93 | }); |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | expect(created.name).toContain("/pipelines/"); |
| 98 | expect(created.location).toEqual("us-central1"); |
| 99 | expect(created.displayName).toEqual("word-count"); |
| 100 | expect(created.type).toEqual("PIPELINE_TYPE_BATCH"); |
| 101 | expect(created.scheduleInfo?.schedule).toEqual("0 0 1 1 *"); |
| 102 | expect(created.pipelineId.length).toBeGreaterThan(0); |
| 103 | |
| 104 | const fetched = yield* datapipelines.getProjectsLocationsPipelines({ |
| 105 | name: created.name, |
| 106 | }); |
| 107 | expect(fetched.name).toEqual(created.name); |
| 108 | expect(fetched.displayName).toEqual("word-count"); |
| 109 | expect(fetched.pipelineSources?.["alchemy-id"]).toEqual(expect.any(String)); |
| 110 | expect(fetched.type).toEqual("PIPELINE_TYPE_BATCH"); |
| 111 | |
| 112 | const updated = yield* stack.deploy( |
| 113 | Effect.gen(function* () { |
| 114 | const bucket = yield* GCP.Storage.Bucket("PipelineTmp", { |
| 115 | location: "US-CENTRAL1", |
| 116 | forceDestroy: true, |
| 117 | }); |
| 118 | return yield* GCP.DataPipelines.Pipeline("WordCount", { |
| 119 | pipelineId: created.pipelineId, |
| 120 | location: created.location, |
| 121 | type: "PIPELINE_TYPE_BATCH", |
| 122 | displayName: "word-count-v2", |
| 123 | scheduleInfo: { schedule: "0 0 1 2 *", timeZone: "UTC" }, |
| 124 | workload: { |
| 125 | dataflowLaunchTemplateRequest: { |
| 126 | projectId: project, |
| 127 | location: "us-central1", |
| 128 | gcsPath: "gs://dataflow-templates/latest/Word_Count", |
| 129 | launchParameters: { |
| 130 | jobName: "alchemy-word-count", |
| 131 | parameters: { |
| 132 | inputFile: "gs://dataflow-samples/shakespeare/kinglear.txt", |
| 133 | output: Output.interpolate`gs://${bucket.bucketName}/out-v2`, |
| 134 | }, |
| 135 | environment: { |
| 136 | tempLocation: Output.interpolate`gs://${bucket.bucketName}/tmp`, |
| 137 | }, |
| 138 | }, |
| 139 | }, |
| 140 | }, |
| 141 | }); |
| 142 | }), |
| 143 | ); |
| 144 | |
| 145 | expect(updated.name).toEqual(created.name); |
| 146 | expect(updated.displayName).toEqual("word-count-v2"); |
| 147 | expect(updated.scheduleInfo?.schedule).toEqual("0 0 1 2 *"); |
| 148 | |
| 149 | const fetchedUpdate = yield* datapipelines.getProjectsLocationsPipelines({ |
| 150 | name: updated.name, |
| 151 | }); |
| 152 | expect(fetchedUpdate.displayName).toEqual("word-count-v2"); |
| 153 | expect(fetchedUpdate.scheduleInfo?.schedule).toEqual("0 0 1 2 *"); |
| 154 | expect(fetchedUpdate.pipelineSources?.["alchemy-id"]).toEqual(expect.any(String)); |
| 155 | |
| 156 | yield* stack.destroy(); |
| 157 | |
| 158 | const gone = yield* waitUntilGone(updated.name); |
| 159 | expect(gone).toEqual("gone"); |
| 160 | }).pipe(logLevel), |
| 161 | { |
| 162 | tags: ["provider:gcp", "provider:gcp:datapipelines", "live"], |
| 163 | timeout: 120_000, |
| 164 | }, |
| 165 | ); |