| 1 | import * as GCP from "@/GCP"; |
| 2 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1"; |
| 5 | import { expect } from "alchemy-test"; |
| 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( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | // Legacy Featurestore online serving provisioning takes ~6 minutes. |
| 18 | const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 19 | |
| 20 | const waitUntilGone = (name: string) => |
| 21 | aiplatform.getProjectsLocationsFeaturestores({ 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 | "getProjectsLocationsFeaturestores on a missing store fails with a typed tag", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | const { project } = yield* GcpEnvironment.current; |
| 36 | const parent = `projects/${project}/locations/us-central1`; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | aiplatform.getProjectsLocationsFeaturestores({ |
| 41 | name: `${parent}/featurestores/alchemy_missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | const page = yield* aiplatform.listProjectsLocationsFeaturestores({ |
| 46 | parent, |
| 47 | pageSize: 10, |
| 48 | }); |
| 49 | expect((page.featurestores ?? []).map((item) => item.name)).not.toContain( |
| 50 | `${parent}/featurestores/alchemy_missing`, |
| 51 | ); |
| 52 | |
| 53 | yield* stack.destroy(); |
| 54 | }).pipe(logLevel), |
| 55 | { |
| 56 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 57 | timeout: 90_000, |
| 58 | }, |
| 59 | ); |
| 60 | |
| 61 | test.provider.skipIf(!runLifecycle)( |
| 62 | "create, update, and delete a featurestore", |
| 63 | (stack) => |
| 64 | Effect.gen(function* () { |
| 65 | yield* stack.destroy(); |
| 66 | |
| 67 | const created = yield* stack.deploy( |
| 68 | Effect.gen(function* () { |
| 69 | return yield* GCP.AIPlatform.Featurestore("Features", { |
| 70 | location: "us-central1", |
| 71 | labels: { env: "test" }, |
| 72 | }); |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | expect(created.name).toContain("/featurestores/"); |
| 77 | expect(created.location).toEqual("us-central1"); |
| 78 | expect(created.labels).toMatchObject({ env: "test" }); |
| 79 | |
| 80 | const fetched = yield* aiplatform.getProjectsLocationsFeaturestores({ |
| 81 | name: created.name, |
| 82 | }); |
| 83 | expect(fetched.name).toEqual(created.name); |
| 84 | expect(fetched.labels?.env).toEqual("test"); |
| 85 | |
| 86 | const updated = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | return yield* GCP.AIPlatform.Featurestore("Features", { |
| 89 | featurestoreId: created.featurestoreId, |
| 90 | location: "us-central1", |
| 91 | labels: { env: "prod", role: "features" }, |
| 92 | }); |
| 93 | }), |
| 94 | ); |
| 95 | |
| 96 | expect(updated.name).toEqual(created.name); |
| 97 | expect(updated.labels).toMatchObject({ env: "prod", role: "features" }); |
| 98 | |
| 99 | yield* stack.destroy(); |
| 100 | |
| 101 | const gone = yield* waitUntilGone(created.name); |
| 102 | expect(gone).toEqual("gone"); |
| 103 | }).pipe(logLevel), |
| 104 | { |
| 105 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 106 | timeout: 600_000, |
| 107 | }, |
| 108 | ); |