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 discoveryengine from "@distilled.cloud/gcp/discoveryengine_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { quotaTolerant } from "./parent.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | // Identity mapping stores need a workforce identity provider configured for |
| 16 | // the project (BadRequest "IdP must be configured before creating an Identity |
| 17 | // Mapping Store"). Set GCP_TEST_DISCOVERYENGINE_IDP=1 once one is configured. |
| 18 | const runLifecycle = !!process.env.GCP_TEST_DISCOVERYENGINE_IDP; |
| 19 | |
| 20 | const waitUntilGone = (name: string) => |
| 21 | discoveryengine.getProjectsLocationsIdentityMappingStores({ name }).pipe( |
| 22 | Effect.as("found" as const), |
| 23 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 24 | Effect.repeat({ |
| 25 | schedule: Schedule.spaced("2 seconds"), |
| 26 | until: (status) => status === "gone", |
| 27 | times: 10, |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | test.provider( |
| 32 | "getProjectsLocationsIdentityMappingStores on a missing store fails with a typed tag", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | const { project } = yield* GcpEnvironment.current; |
| 36 | |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | discoveryengine.getProjectsLocationsIdentityMappingStores({ |
| 41 | name: `projects/${project}/locations/global/identityMappingStores/alchemy-ims-missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel, quotaTolerant), |
| 48 | { |
| 49 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 50 | timeout: 90_000, |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | test.provider( |
| 55 | "createProjectsLocationsIdentityMappingStores without an IdP is rejected with a typed tag", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | const { project } = yield* GcpEnvironment.current; |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const error = yield* Effect.flip( |
| 63 | discoveryengine.createProjectsLocationsIdentityMappingStores({ |
| 64 | parent: `projects/${project}/locations/global`, |
| 65 | identityMappingStoreId: "alchemyimismissing", |
| 66 | disableCmek: true, |
| 67 | body: { |
| 68 | name: `projects/${project}/locations/global/identityMappingStores/alchemyimismissing`, |
| 69 | }, |
| 70 | }), |
| 71 | ); |
| 72 | expect(error._tag).toEqual("IdentityProviderNotConfigured"); |
| 73 | |
| 74 | yield* stack.destroy(); |
| 75 | }).pipe(logLevel, quotaTolerant), |
| 76 | { |
| 77 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 78 | timeout: 90_000, |
| 79 | }, |
| 80 | ); |
| 81 | |
| 82 | test.provider.skipIf(!runLifecycle)( |
| 83 | "create and delete an identity mapping store", |
| 84 | (stack) => |
| 85 | Effect.gen(function* () { |
| 86 | yield* stack.destroy(); |
| 87 | |
| 88 | const created = yield* stack.deploy( |
| 89 | Effect.gen(function* () { |
| 90 | return yield* GCP.DiscoveryEngine.IdentityMappingStore("Users", { |
| 91 | location: "global", |
| 92 | disableCmek: true, |
| 93 | }); |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | expect(created.name).toContain("/identityMappingStores/"); |
| 98 | expect(created.identityMappingStoreId.startsWith("alch")).toEqual(true); |
| 99 | expect(created.location).toEqual("global"); |
| 100 | |
| 101 | const fetched = yield* discoveryengine.getProjectsLocationsIdentityMappingStores({ |
| 102 | name: created.name, |
| 103 | }); |
| 104 | expect(fetched.name).toEqual(created.name); |
| 105 | |
| 106 | yield* stack.destroy(); |
| 107 | |
| 108 | const gone = yield* waitUntilGone(created.name); |
| 109 | expect(gone).toEqual("gone"); |
| 110 | }).pipe(logLevel, quotaTolerant), |
| 111 | { |
| 112 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 113 | timeout: 120_000, |
| 114 | }, |
| 115 | ); |