| 1 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 2 | import * as GCP from "@/GCP"; |
| 3 | import { quotaTolerant } from "./parent.ts"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as discoveryengine from "@distilled.cloud/gcp/discoveryengine_v1"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService( |
| 14 | MinimumLogLevel, |
| 15 | process.env.DEBUG ? "Debug" : "Info", |
| 16 | ); |
| 17 | |
| 18 | const runLifecycle = !process.env.FAST; |
| 19 | |
| 20 | const waitUntilGone = (name: string) => |
| 21 | discoveryengine.getProjectsLocationsCollectionsDataStores({ 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 | "getProjectsLocationsCollectionsDataStores on a missing store fails with a typed tag", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | const { project } = yield* GcpEnvironment.current; |
| 36 | const collectionParent = `projects/${project}/locations/global/collections/default_collection`; |
| 37 | |
| 38 | yield* stack.destroy(); |
| 39 | |
| 40 | const error = yield* Effect.flip( |
| 41 | discoveryengine.getProjectsLocationsCollectionsDataStores({ |
| 42 | name: `${collectionParent}/dataStores/alchemy-cds-missing`, |
| 43 | }), |
| 44 | ); |
| 45 | expect(error._tag).toEqual("NotFound"); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | }).pipe(logLevel, quotaTolerant), |
| 49 | { |
| 50 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 51 | timeout: 90_000, |
| 52 | }, |
| 53 | ); |
| 54 | |
| 55 | test.provider.skipIf(!runLifecycle)( |
| 56 | "create, update, and delete a collection data store", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | yield* stack.destroy(); |
| 60 | |
| 61 | const created = yield* stack.deploy( |
| 62 | Effect.gen(function* () { |
| 63 | return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 64 | location: "global", |
| 65 | displayName: "docs", |
| 66 | industryVertical: "GENERIC", |
| 67 | contentConfig: "NO_CONTENT", |
| 68 | solutionTypes: ["SOLUTION_TYPE_SEARCH"], |
| 69 | disableCmek: true, |
| 70 | }); |
| 71 | }), |
| 72 | ); |
| 73 | |
| 74 | expect(created.name).toContain("/collections/"); |
| 75 | expect(created.name).toContain("/dataStores/"); |
| 76 | expect(created.location).toEqual("global"); |
| 77 | expect(created.displayName).toEqual("docs"); |
| 78 | expect(created.industryVertical).toEqual("GENERIC"); |
| 79 | |
| 80 | const fetched = |
| 81 | yield* discoveryengine.getProjectsLocationsCollectionsDataStores({ |
| 82 | name: created.name, |
| 83 | }); |
| 84 | expect(fetched.name).toEqual(created.name); |
| 85 | expect(fetched.displayName).toEqual("docs"); |
| 86 | |
| 87 | const updated = yield* stack.deploy( |
| 88 | Effect.gen(function* () { |
| 89 | return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 90 | dataStoreId: created.dataStoreId, |
| 91 | location: "global", |
| 92 | collection: created.collection, |
| 93 | displayName: "prod", |
| 94 | industryVertical: "GENERIC", |
| 95 | contentConfig: "NO_CONTENT", |
| 96 | solutionTypes: ["SOLUTION_TYPE_SEARCH"], |
| 97 | disableCmek: true, |
| 98 | }); |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(updated.name).toEqual(created.name); |
| 103 | expect(updated.displayName).toEqual("prod"); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | const gone = yield* waitUntilGone(created.name); |
| 108 | expect(gone).toEqual("gone"); |
| 109 | }).pipe(logLevel, quotaTolerant), |
| 110 | { |
| 111 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 112 | timeout: 120_000, |
| 113 | }, |
| 114 | ); |