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 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 | aiplatform.getDatasetsDatasetVersions({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("2 seconds"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getDatasetsDatasetVersions on a missing version fails with a typed tag", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | const parent = `projects/${project}/locations/us-central1`; |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const error = yield* Effect.flip( |
| 34 | aiplatform.getDatasetsDatasetVersions({ |
| 35 | name: `${parent}/datasets/1234567890123456789/datasetVersions/0`, |
| 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 | const imageDataset = { |
| 49 | location: "us-central1", |
| 50 | displayName: "version-parent", |
| 51 | metadataSchemaUri: "gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml", |
| 52 | metadata: {}, |
| 53 | labels: { env: "test" }, |
| 54 | savedQueries: [ |
| 55 | { |
| 56 | displayName: "default", |
| 57 | problemType: "IMAGE_CLASSIFICATION_SINGLE_LABEL", |
| 58 | }, |
| 59 | ], |
| 60 | }; |
| 61 | |
| 62 | test.provider( |
| 63 | "creating a version of a dataset without data items fails with GCP.OperationFailed", |
| 64 | (stack) => |
| 65 | Effect.gen(function* () { |
| 66 | yield* stack.destroy(); |
| 67 | |
| 68 | const error = yield* Effect.flip( |
| 69 | stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | const dataset = yield* GCP.AIPlatform.Dataset("Samples", imageDataset); |
| 72 | const version = yield* GCP.AIPlatform.DatasetsDatasetVersion("V1", { |
| 73 | dataset: dataset.name, |
| 74 | displayName: "v1", |
| 75 | }); |
| 76 | return { dataset, version }; |
| 77 | }), |
| 78 | ), |
| 79 | ); |
| 80 | expect(error._tag).toEqual("GCP.OperationFailed"); |
| 81 | |
| 82 | yield* stack.destroy(); |
| 83 | }).pipe(logLevel), |
| 84 | { |
| 85 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 86 | timeout: 600_000, |
| 87 | }, |
| 88 | ); |
| 89 | |
| 90 | // Set GCP_TEST_AIPLATFORM_DATASET_VERSION on a project where this succeeds to run the full lifecycle. |
| 91 | test.provider.skipIf(!process.env.GCP_TEST_AIPLATFORM_DATASET_VERSION)( |
| 92 | "create, update, and delete a dataset version", |
| 93 | (stack) => |
| 94 | Effect.gen(function* () { |
| 95 | yield* stack.destroy(); |
| 96 | |
| 97 | const created = yield* stack.deploy( |
| 98 | Effect.gen(function* () { |
| 99 | const dataset = yield* GCP.AIPlatform.Dataset("Samples", imageDataset); |
| 100 | const version = yield* GCP.AIPlatform.DatasetsDatasetVersion("V1", { |
| 101 | dataset: dataset.name, |
| 102 | displayName: "v1", |
| 103 | }); |
| 104 | return { dataset, version }; |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | expect(created.version.name).toContain("/datasetVersions/"); |
| 109 | expect(created.version.dataset).toEqual(created.dataset.name); |
| 110 | expect(created.version.displayName).toEqual("v1"); |
| 111 | |
| 112 | const fetched = yield* aiplatform.getDatasetsDatasetVersions({ |
| 113 | name: created.version.name, |
| 114 | }); |
| 115 | expect(fetched.name).toEqual(created.version.name); |
| 116 | |
| 117 | const updated = yield* stack.deploy( |
| 118 | Effect.gen(function* () { |
| 119 | const dataset = yield* GCP.AIPlatform.Dataset("Samples", { |
| 120 | ...imageDataset, |
| 121 | datasetId: created.dataset.datasetId, |
| 122 | }); |
| 123 | const version = yield* GCP.AIPlatform.DatasetsDatasetVersion("V1", { |
| 124 | dataset: dataset.name, |
| 125 | displayName: "v1-final", |
| 126 | }); |
| 127 | return { dataset, version }; |
| 128 | }), |
| 129 | ); |
| 130 | |
| 131 | expect(updated.version.name).toEqual(created.version.name); |
| 132 | expect(updated.version.displayName).toEqual("v1-final"); |
| 133 | |
| 134 | yield* stack.destroy(); |
| 135 | |
| 136 | const gone = yield* waitUntilGone(created.version.name); |
| 137 | expect(gone).toEqual("gone"); |
| 138 | }).pipe(logLevel), |
| 139 | { |
| 140 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 141 | timeout: 120_000, |
| 142 | }, |
| 143 | ); |