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 documentai from "@distilled.cloud/gcp/documentai_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 | const location = "us"; |
| 14 | |
| 15 | const waitUntilGone = (name: string) => |
| 16 | documentai.getProjectsLocationsProcessors({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("2 seconds"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | test.provider( |
| 27 | "getProjectsLocationsProcessors on a missing processor fails with a typed tag", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const { project } = yield* GcpEnvironment.current; |
| 31 | const parent = `projects/${project}/locations/${location}`; |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const error = yield* Effect.flip( |
| 35 | documentai.getProjectsLocationsProcessors({ |
| 36 | name: `${parent}/processors/alchemy-missing-processor`, |
| 37 | }), |
| 38 | ); |
| 39 | expect(error._tag).toEqual("NotFound"); |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | }).pipe(logLevel), |
| 43 | { |
| 44 | tags: ["provider:gcp", "provider:gcp:documentai", "live"], |
| 45 | timeout: 90_000, |
| 46 | }, |
| 47 | ); |
| 48 | |
| 49 | test.provider.skipIf(!!process.env.FAST)( |
| 50 | "create, update, and delete a processor", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | const { project } = yield* GcpEnvironment.current; |
| 54 | const parent = `projects/${project}/locations/${location}`; |
| 55 | yield* stack.destroy(); |
| 56 | |
| 57 | const created = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | return yield* GCP.DocumentAI.Processor("Ocr", { |
| 60 | location, |
| 61 | type: "OCR_PROCESSOR", |
| 62 | displayName: "ocr", |
| 63 | }); |
| 64 | }), |
| 65 | ); |
| 66 | |
| 67 | expect(created.processorId).toEqual(expect.any(String)); |
| 68 | expect(created.name).toContain("/processors/"); |
| 69 | expect(created.location).toEqual(location); |
| 70 | expect(created.type).toEqual("OCR_PROCESSOR"); |
| 71 | expect(created.displayName).toEqual("ocr"); |
| 72 | expect(created.state).toEqual("ENABLED"); |
| 73 | |
| 74 | const fetched = yield* documentai.getProjectsLocationsProcessors({ |
| 75 | name: created.name, |
| 76 | }); |
| 77 | expect(fetched.name).toEqual(created.name); |
| 78 | expect(fetched.type).toEqual("OCR_PROCESSOR"); |
| 79 | expect(fetched.displayName).toContain("ocr"); |
| 80 | expect(fetched.displayName).toMatch(/\[alc |\[alchemy /); |
| 81 | |
| 82 | const updated = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | return yield* GCP.DocumentAI.Processor("Ocr", { |
| 85 | processorId: created.processorId, |
| 86 | location, |
| 87 | type: "OCR_PROCESSOR", |
| 88 | displayName: "ocr", |
| 89 | enabled: false, |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(updated.name).toEqual(created.name); |
| 95 | expect(updated.state).toEqual("DISABLED"); |
| 96 | |
| 97 | const disabled = yield* documentai.getProjectsLocationsProcessors({ |
| 98 | name: created.name, |
| 99 | }); |
| 100 | expect(disabled.state).toEqual("DISABLED"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | const gone = yield* waitUntilGone(created.name); |
| 104 | expect(gone).toEqual("gone"); |
| 105 | }).pipe(logLevel), |
| 106 | { |
| 107 | tags: ["provider:gcp", "provider:gcp:documentai", "live"], |
| 108 | timeout: 120_000, |
| 109 | }, |
| 110 | ); |