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 | const waitUntilGone = (name: string) => |
| 16 | aiplatform.getProjectsLocationsFeatureGroupsFeatures({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("2 seconds"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | const groupProps = { |
| 27 | location: "us-central1" as const, |
| 28 | description: "user features", |
| 29 | labels: { env: "test" }, |
| 30 | }; |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsFeatureGroupsFeatures on a missing feature fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | aiplatform.getProjectsLocationsFeatureGroupsFeatures({ |
| 41 | name: `projects/${project}/locations/us-central1/featureGroups/alchemy_missing/features/alchemy_missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { |
| 49 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 50 | timeout: 90_000, |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | test.provider( |
| 55 | "create, update, and delete a feature group feature", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const created = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | const inputUri = yield* UsersSource; |
| 63 | const group = yield* GCP.AIPlatform.FeatureGroup("Users", { |
| 64 | ...groupProps, |
| 65 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 66 | }); |
| 67 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 68 | featureGroup: group.name, |
| 69 | location: "us-central1", |
| 70 | description: "customer age", |
| 71 | versionColumnName: "age", |
| 72 | labels: { env: "test" }, |
| 73 | }); |
| 74 | return { group, feature }; |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.feature.name).toContain("/features/"); |
| 79 | expect(created.feature.featureGroup).toEqual(created.group.name); |
| 80 | expect(created.feature.labels).toMatchObject({ env: "test" }); |
| 81 | expect(created.feature.description).toEqual("customer age"); |
| 82 | |
| 83 | const fetched = yield* aiplatform.getProjectsLocationsFeatureGroupsFeatures({ |
| 84 | name: created.feature.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.feature.name); |
| 87 | |
| 88 | const updated = yield* stack.deploy( |
| 89 | Effect.gen(function* () { |
| 90 | const inputUri = yield* UsersSource; |
| 91 | const group = yield* GCP.AIPlatform.FeatureGroup("Users", { |
| 92 | ...groupProps, |
| 93 | featureGroupId: created.group.featureGroupId, |
| 94 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 95 | }); |
| 96 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 97 | featureGroup: group.name, |
| 98 | featureId: created.feature.featureId, |
| 99 | location: "us-central1", |
| 100 | description: "customer age v2", |
| 101 | versionColumnName: "age", |
| 102 | labels: { env: "prod" }, |
| 103 | }); |
| 104 | return { group, feature }; |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | expect(updated.feature.name).toEqual(created.feature.name); |
| 109 | expect(updated.feature.description).toEqual("customer age v2"); |
| 110 | expect(updated.feature.labels).toMatchObject({ env: "prod" }); |
| 111 | |
| 112 | yield* stack.destroy(); |
| 113 | const gone = yield* waitUntilGone(created.feature.name); |
| 114 | expect(gone).toEqual("gone"); |
| 115 | }).pipe(logLevel), |
| 116 | { |
| 117 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 118 | timeout: 600_000, |
| 119 | }, |
| 120 | ); |