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 aiplatform from "@distilled.cloud/gcp/aiplatform_v1"; |
| 6 | import * as Output from "alchemy/Output"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as ScheduleLib 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 | aiplatform.getProjectsLocationsSchedules({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: ScheduleLib.spaced("2 seconds"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | test.provider( |
| 27 | "getProjectsLocationsSchedules on a missing schedule fails with a typed tag", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const { project } = yield* GcpEnvironment.current; |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const error = yield* Effect.flip( |
| 34 | aiplatform.getProjectsLocationsSchedules({ |
| 35 | name: `projects/${project}/locations/us-central1/schedules/1234567890123456789`, |
| 36 | }), |
| 37 | ); |
| 38 | expect(error._tag).toEqual("NotFound"); |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | }).pipe(logLevel), |
| 42 | { |
| 43 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 44 | timeout: 90_000, |
| 45 | }, |
| 46 | ); |
| 47 | |
| 48 | test.provider( |
| 49 | "create, pause, and delete a vertex schedule", |
| 50 | (stack) => |
| 51 | Effect.gen(function* () { |
| 52 | yield* stack.destroy(); |
| 53 | |
| 54 | const created = yield* stack.deploy( |
| 55 | Effect.gen(function* () { |
| 56 | const bucket = yield* GCP.Storage.Bucket("PipelineRoot", { |
| 57 | location: "US-CENTRAL1", |
| 58 | forceDestroy: true, |
| 59 | }); |
| 60 | return yield* GCP.AIPlatform.Schedule("Nightly", { |
| 61 | location: "us-central1", |
| 62 | displayName: "nightly", |
| 63 | cron: "0 8 * * *", |
| 64 | paused: true, |
| 65 | maxRunCount: "1", |
| 66 | createPipelineJobRequest: { |
| 67 | pipelineJob: { |
| 68 | displayName: "nightly-hello", |
| 69 | templateUri: |
| 70 | "https://us-kfp.pkg.dev/ml-pipeline/google-cloud-registry/hello-world/latest", |
| 71 | runtimeConfig: { |
| 72 | gcsOutputDirectory: Output.interpolate`gs://${bucket.bucketName}/runs`, |
| 73 | }, |
| 74 | }, |
| 75 | }, |
| 76 | }); |
| 77 | }), |
| 78 | ); |
| 79 | |
| 80 | expect(created.name).toContain("/schedules/"); |
| 81 | expect(created.paused).toEqual(true); |
| 82 | expect(created.cron).toContain("0 8 * * *"); |
| 83 | |
| 84 | const fetched = yield* aiplatform.getProjectsLocationsSchedules({ |
| 85 | name: created.name, |
| 86 | }); |
| 87 | expect(fetched.name).toEqual(created.name); |
| 88 | expect(fetched.displayName).toContain("alchemy-id="); |
| 89 | |
| 90 | const updated = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | const bucket = yield* GCP.Storage.Bucket("PipelineRoot", { |
| 93 | location: "US-CENTRAL1", |
| 94 | forceDestroy: true, |
| 95 | }); |
| 96 | return yield* GCP.AIPlatform.Schedule("Nightly", { |
| 97 | location: "us-central1", |
| 98 | displayName: "nightly-v2", |
| 99 | cron: "0 9 * * *", |
| 100 | paused: true, |
| 101 | maxRunCount: "1", |
| 102 | createPipelineJobRequest: { |
| 103 | pipelineJob: { |
| 104 | displayName: "nightly-hello", |
| 105 | templateUri: |
| 106 | "https://us-kfp.pkg.dev/ml-pipeline/google-cloud-registry/hello-world/latest", |
| 107 | runtimeConfig: { |
| 108 | gcsOutputDirectory: Output.interpolate`gs://${bucket.bucketName}/runs`, |
| 109 | }, |
| 110 | }, |
| 111 | }, |
| 112 | }); |
| 113 | }), |
| 114 | ); |
| 115 | expect(updated.name).toEqual(created.name); |
| 116 | expect(updated.cron).toContain("0 9 * * *"); |
| 117 | |
| 118 | yield* stack.destroy(); |
| 119 | const gone = yield* waitUntilGone(created.name); |
| 120 | expect(gone).toEqual("gone"); |
| 121 | }).pipe(logLevel), |
| 122 | { |
| 123 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 124 | timeout: 120_000, |
| 125 | }, |
| 126 | ); |