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