| 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 | "getProjectsAnnotationSpecSets on a missing set 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.getProjectsAnnotationSpecSets({ |
| 26 | name: `projects/${project}/annotationSpecSets/alchemy-missing-specs`, |
| 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 an annotation spec set", |
| 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.AnnotationSpecSet("Classes", { |
| 49 | displayName: "pets", |
| 50 | description: "companion animals", |
| 51 | annotationSpecs: [{ displayName: "dog" }, { displayName: "cat" }], |
| 52 | }); |
| 53 | }), |
| 54 | ); |
| 55 | |
| 56 | expect(created.name).toContain("/annotationSpecSets/"); |
| 57 | expect(created.displayName).toEqual("pets"); |
| 58 | expect(created.description).toEqual("companion animals"); |
| 59 | expect(created.annotationSpecs.map((spec) => spec.displayName)).toEqual([ |
| 60 | "dog", |
| 61 | "cat", |
| 62 | ]); |
| 63 | |
| 64 | const fetched = yield* datalabeling.getProjectsAnnotationSpecSets({ |
| 65 | name: created.name, |
| 66 | }); |
| 67 | expect(fetched.name).toEqual(created.name); |
| 68 | expect(fetched.description).toContain("alchemy-id="); |
| 69 | expect(fetched.description).toContain("companion animals"); |
| 70 | |
| 71 | const updated = yield* stack.deploy( |
| 72 | Effect.gen(function* () { |
| 73 | return yield* GCP.DataLabeling.AnnotationSpecSet("Classes", { |
| 74 | annotationSpecSetId: created.annotationSpecSetId, |
| 75 | displayName: "pets", |
| 76 | description: "updated companion animals", |
| 77 | annotationSpecs: [{ displayName: "dog" }, { displayName: "cat" }], |
| 78 | }); |
| 79 | }), |
| 80 | ); |
| 81 | |
| 82 | expect(updated.description).toEqual("updated companion animals"); |
| 83 | |
| 84 | yield* stack.destroy(); |
| 85 | const gone = yield* waitUntilGone( |
| 86 | datalabeling.getProjectsAnnotationSpecSets({ name: updated.name }), |
| 87 | ); |
| 88 | expect(gone).toEqual("gone"); |
| 89 | }).pipe(logLevel), |
| 90 | { |
| 91 | tags: ["provider:gcp", "provider:gcp:datalabeling", "live"], |
| 92 | timeout: 90_000, |
| 93 | }, |
| 94 | ); |