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 | const runLifecycle = !process.env.FAST; |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | discoveryengine.getProjectsLocationsCollectionsEnginesServingConfigs({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("2 seconds"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsCollectionsEnginesServingConfigs on a missing config fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const { project } = yield* GcpEnvironment.current; |
| 33 | |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const error = yield* Effect.flip( |
| 37 | discoveryengine.getProjectsLocationsCollectionsEnginesServingConfigs({ |
| 38 | name: `projects/${project}/locations/global/collections/default_collection/engines/alchemy-missing/servingConfigs/alchemy-missing`, |
| 39 | }), |
| 40 | ); |
| 41 | expect(error._tag).toEqual("NotFound"); |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | }).pipe(logLevel, quotaTolerant), |
| 45 | { |
| 46 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 47 | timeout: 90_000, |
| 48 | }, |
| 49 | ); |
| 50 | |
| 51 | test.provider.skipIf(!runLifecycle)( |
| 52 | "create, update, and delete an engine serving config", |
| 53 | (stack) => |
| 54 | Effect.gen(function* () { |
| 55 | yield* stack.destroy(); |
| 56 | |
| 57 | const created = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 60 | location: "global", |
| 61 | displayName: "serving-docs", |
| 62 | }); |
| 63 | const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", { |
| 64 | location: "global", |
| 65 | dataStoreIds: [store.dataStoreId], |
| 66 | displayName: "serving engine", |
| 67 | }); |
| 68 | const serving = yield* GCP.DiscoveryEngine.CollectionsEnginesServingConfig("Primary", { |
| 69 | engine: engine.name, |
| 70 | displayName: "primary", |
| 71 | solutionType: "SOLUTION_TYPE_SEARCH", |
| 72 | }); |
| 73 | return { store, engine, serving }; |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | expect(created.serving.name).toContain("/servingConfigs/"); |
| 78 | expect(created.serving.engine).toEqual(created.engine.name); |
| 79 | expect(created.serving.displayName).toEqual("primary"); |
| 80 | |
| 81 | const fetched = yield* discoveryengine.getProjectsLocationsCollectionsEnginesServingConfigs({ |
| 82 | name: created.serving.name, |
| 83 | }); |
| 84 | expect(fetched.name).toEqual(created.serving.name); |
| 85 | expect(fetched.displayName).toEqual("primary"); |
| 86 | |
| 87 | const updated = yield* stack.deploy( |
| 88 | Effect.gen(function* () { |
| 89 | const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 90 | dataStoreId: created.store.dataStoreId, |
| 91 | location: "global", |
| 92 | displayName: "serving-docs", |
| 93 | }); |
| 94 | const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", { |
| 95 | engineId: created.engine.engineId, |
| 96 | location: "global", |
| 97 | dataStoreIds: [store.dataStoreId], |
| 98 | displayName: "serving engine", |
| 99 | }); |
| 100 | const serving = yield* GCP.DiscoveryEngine.CollectionsEnginesServingConfig("Primary", { |
| 101 | engine: engine.name, |
| 102 | servingConfigId: created.serving.servingConfigId, |
| 103 | displayName: "primary-prod", |
| 104 | solutionType: "SOLUTION_TYPE_SEARCH", |
| 105 | }); |
| 106 | return { store, engine, serving }; |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | expect(updated.serving.name).toEqual(created.serving.name); |
| 111 | expect(updated.serving.displayName).toEqual("primary-prod"); |
| 112 | |
| 113 | yield* stack.destroy(); |
| 114 | |
| 115 | const gone = yield* waitUntilGone(created.serving.name); |
| 116 | expect(gone).toEqual("gone"); |
| 117 | }).pipe(logLevel, quotaTolerant), |
| 118 | { |
| 119 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 120 | timeout: 120_000, |
| 121 | }, |
| 122 | ); |