| 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.getProjectsLocationsDataStores({ 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 | "getProjectsLocationsDataStores 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.getProjectsLocationsDataStores({ |
| 41 | name: `projects/${project}/locations/global/dataStores/alchemy-ds-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.skipIf(!runLifecycle)( |
| 55 | "create, update, and delete a data store", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const created = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | return yield* GCP.DiscoveryEngine.DataStore("Docs", { |
| 63 | location: "global", |
| 64 | displayName: "docs", |
| 65 | industryVertical: "GENERIC", |
| 66 | contentConfig: "NO_CONTENT", |
| 67 | solutionTypes: ["SOLUTION_TYPE_SEARCH"], |
| 68 | disableCmek: true, |
| 69 | }); |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.name).toContain("/dataStores/"); |
| 74 | expect(created.location).toEqual("global"); |
| 75 | expect(created.displayName).toEqual("docs"); |
| 76 | expect(created.industryVertical).toEqual("GENERIC"); |
| 77 | |
| 78 | const fetched = yield* discoveryengine.getProjectsLocationsDataStores({ |
| 79 | name: created.name, |
| 80 | }); |
| 81 | expect(fetched.name).toEqual(created.name); |
| 82 | expect(fetched.displayName).toEqual("docs"); |
| 83 | |
| 84 | const updated = yield* stack.deploy( |
| 85 | Effect.gen(function* () { |
| 86 | return yield* GCP.DiscoveryEngine.DataStore("Docs", { |
| 87 | dataStoreId: created.dataStoreId, |
| 88 | location: "global", |
| 89 | displayName: "docs-prod", |
| 90 | industryVertical: "GENERIC", |
| 91 | contentConfig: "NO_CONTENT", |
| 92 | solutionTypes: ["SOLUTION_TYPE_SEARCH"], |
| 93 | disableCmek: true, |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(updated.name).toEqual(created.name); |
| 99 | expect(updated.displayName).toEqual("docs-prod"); |
| 100 | |
| 101 | yield* stack.destroy(); |
| 102 | |
| 103 | const gone = yield* waitUntilGone(created.name); |
| 104 | expect(gone).toEqual("gone"); |
| 105 | }).pipe(logLevel, quotaTolerant), |
| 106 | { |
| 107 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 108 | timeout: 120_000, |
| 109 | }, |
| 110 | ); |