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 aiplatform from "@distilled.cloud/gcp/aiplatform_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { UsersSource } from "./fixtures/features.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | // Bigtable-backed store provisioning takes 1-3 minutes. |
| 16 | const runLifecycle = !process.env.FAST; |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("2 seconds"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getProjectsLocationsFeatureOnlineStoresFeatureViews on a missing view fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const error = yield* Effect.flip( |
| 37 | aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ |
| 38 | name: `projects/${project}/locations/us-central1/featureOnlineStores/alchemy_missing/featureViews/alchemy_missing`, |
| 39 | }), |
| 40 | ); |
| 41 | expect(error._tag).toEqual("NotFound"); |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | }).pipe(logLevel), |
| 45 | { |
| 46 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 47 | timeout: 90_000, |
| 48 | }, |
| 49 | ); |
| 50 | |
| 51 | test.provider.skipIf(!runLifecycle)( |
| 52 | "create, update, and delete a feature online store feature view", |
| 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.AIPlatform.FeatureOnlineStore("Serving", { |
| 60 | location: "us-central1", |
| 61 | labels: { env: "test" }, |
| 62 | }); |
| 63 | const inputUri = yield* UsersSource; |
| 64 | const group = yield* GCP.AIPlatform.FeatureGroup("UserFeatures", { |
| 65 | location: "us-central1", |
| 66 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 67 | }); |
| 68 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 69 | featureGroup: group.name, |
| 70 | location: "us-central1", |
| 71 | versionColumnName: "age", |
| 72 | }); |
| 73 | const view = yield* GCP.AIPlatform.FeatureOnlineStoresFeatureView("Users", { |
| 74 | featureOnlineStore: store.name, |
| 75 | location: "us-central1", |
| 76 | labels: { env: "test" }, |
| 77 | featureRegistrySource: { |
| 78 | featureGroups: [ |
| 79 | { |
| 80 | featureGroupId: group.featureGroupId, |
| 81 | featureIds: [feature.featureId], |
| 82 | }, |
| 83 | ], |
| 84 | }, |
| 85 | syncConfig: { cron: "0 * * * *" }, |
| 86 | }); |
| 87 | return { store, view }; |
| 88 | }), |
| 89 | ); |
| 90 | |
| 91 | expect(created.view.name).toContain("/featureViews/"); |
| 92 | expect(created.view.featureOnlineStore).toEqual(created.store.name); |
| 93 | expect(created.view.labels).toMatchObject({ env: "test" }); |
| 94 | |
| 95 | const fetched = yield* aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ |
| 96 | name: created.view.name, |
| 97 | }); |
| 98 | expect(fetched.name).toEqual(created.view.name); |
| 99 | |
| 100 | const updated = yield* stack.deploy( |
| 101 | Effect.gen(function* () { |
| 102 | const store = yield* GCP.AIPlatform.FeatureOnlineStore("Serving", { |
| 103 | featureOnlineStoreId: created.store.featureOnlineStoreId, |
| 104 | location: "us-central1", |
| 105 | labels: { env: "test" }, |
| 106 | }); |
| 107 | const inputUri = yield* UsersSource; |
| 108 | const group = yield* GCP.AIPlatform.FeatureGroup("UserFeatures", { |
| 109 | location: "us-central1", |
| 110 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 111 | }); |
| 112 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 113 | featureGroup: group.name, |
| 114 | location: "us-central1", |
| 115 | versionColumnName: "age", |
| 116 | }); |
| 117 | const view = yield* GCP.AIPlatform.FeatureOnlineStoresFeatureView("Users", { |
| 118 | featureOnlineStore: store.name, |
| 119 | featureViewId: created.view.featureViewId, |
| 120 | location: "us-central1", |
| 121 | labels: { env: "prod" }, |
| 122 | featureRegistrySource: { |
| 123 | featureGroups: [ |
| 124 | { |
| 125 | featureGroupId: group.featureGroupId, |
| 126 | featureIds: [feature.featureId], |
| 127 | }, |
| 128 | ], |
| 129 | }, |
| 130 | syncConfig: { cron: "0 * * * *" }, |
| 131 | }); |
| 132 | return { store, view }; |
| 133 | }), |
| 134 | ); |
| 135 | |
| 136 | expect(updated.view.name).toEqual(created.view.name); |
| 137 | expect(updated.view.labels).toMatchObject({ env: "prod" }); |
| 138 | |
| 139 | yield* stack.destroy(); |
| 140 | const gone = yield* waitUntilGone(created.view.name); |
| 141 | expect(gone).toEqual("gone"); |
| 142 | }).pipe(logLevel), |
| 143 | { |
| 144 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 145 | timeout: 600_000, |
| 146 | }, |
| 147 | ); |