| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as datalabeling from "@distilled.cloud/gcp/datalabeling_v1beta1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | logLevel, |
| 8 | probe, |
| 9 | currentProject, |
| 10 | runLifecycle, |
| 11 | waitUntilGone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getProjectsDatasets on a missing dataset fails with a typed tag", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | const project = yield* currentProject; |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const error = yield* Effect.flip( |
| 24 | probe( |
| 25 | datalabeling.getProjectsDatasets({ |
| 26 | name: `projects/${project}/datasets/alchemy-missing-dataset`, |
| 27 | }), |
| 28 | ), |
| 29 | ); |
| 30 | expect(error._tag).toEqual("NotFound"); |
| 31 | |
| 32 | yield* stack.destroy(); |
| 33 | }).pipe(logLevel), |
| 34 | { |
| 35 | tags: ["provider:gcp", "provider:gcp:datalabeling", "live"], |
| 36 | timeout: 90_000, |
| 37 | }, |
| 38 | ); |
| 39 | |
| 40 | test.provider.skipIf(!runLifecycle)( |
| 41 | "create, replace, and delete a dataset", |
| 42 | (stack) => |
| 43 | Effect.gen(function* () { |
| 44 | yield* stack.destroy(); |
| 45 | |
| 46 | const created = yield* stack.deploy( |
| 47 | Effect.gen(function* () { |
| 48 | return yield* GCP.DataLabeling.Dataset("Images", { |
| 49 | displayName: "product-photos", |
| 50 | description: "sku images", |
| 51 | }); |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | expect(created.name).toContain("/datasets/"); |
| 56 | expect(created.displayName).toEqual("product-photos"); |
| 57 | expect(created.description).toEqual("sku images"); |
| 58 | |
| 59 | const fetched = yield* datalabeling.getProjectsDatasets({ |
| 60 | name: created.name, |
| 61 | }); |
| 62 | expect(fetched.name).toEqual(created.name); |
| 63 | expect(fetched.description).toContain("alchemy-id="); |
| 64 | expect(fetched.description).toContain("sku images"); |
| 65 | |
| 66 | const updated = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | return yield* GCP.DataLabeling.Dataset("Images", { |
| 69 | datasetId: created.datasetId, |
| 70 | displayName: "product-photos", |
| 71 | description: "updated sku images", |
| 72 | }); |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | expect(updated.description).toEqual("updated sku images"); |
| 77 | |
| 78 | yield* stack.destroy(); |
| 79 | const gone = yield* waitUntilGone( |
| 80 | datalabeling.getProjectsDatasets({ name: updated.name }), |
| 81 | ); |
| 82 | expect(gone).toEqual("gone"); |
| 83 | }).pipe(logLevel), |
| 84 | { |
| 85 | tags: ["provider:gcp", "provider:gcp:datalabeling", "live"], |
| 86 | timeout: 90_000, |
| 87 | }, |
| 88 | ); |