1import * as GCP from "@/GCP";
2import { GcpEnvironment } from "@/GCP/Environment";
3import * as Test from "@/Test/Alchemy";
4import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { MinimumLogLevel } from "effect/References";
8import * as Schedule from "effect/Schedule";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17// Bigtable-backed store provisioning takes 1-3 minutes.
18const runLifecycle = !process.env.FAST;
19
20const waitUntilGone = (name: string) =>
21 aiplatform.getProjectsLocationsFeatureOnlineStores({ 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
31test.provider(
32 "getProjectsLocationsFeatureOnlineStores 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.getProjectsLocationsFeatureOnlineStores({
41 name: `${parent}/featureOnlineStores/alchemy_missing`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45 const page = yield* aiplatform.listProjectsLocationsFeatureOnlineStores({
46 parent,
47 pageSize: 10,
48 });
49 expect(
50 (page.featureOnlineStores ?? []).map((item) => item.name),
51 ).not.toContain(`${parent}/featureOnlineStores/alchemy_missing`);
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 {
56 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
57 timeout: 90_000,
58 },
59);
60
61test.provider.skipIf(!runLifecycle)(
62 "create, update, and delete a feature online store",
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.FeatureOnlineStore("Serving", {
70 location: "us-central1",
71 labels: { env: "test" },
72 });
73 }),
74 );
75
76 expect(created.name).toContain("/featureOnlineStores/");
77 expect(created.location).toEqual("us-central1");
78 expect(created.labels).toMatchObject({ env: "test" });
79
80 const fetched = yield* aiplatform.getProjectsLocationsFeatureOnlineStores(
81 {
82 name: created.name,
83 },
84 );
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.labels?.env).toEqual("test");
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.AIPlatform.FeatureOnlineStore("Serving", {
91 featureOnlineStoreId: created.featureOnlineStoreId,
92 location: "us-central1",
93 labels: { env: "prod", role: "serving" },
94 });
95 }),
96 );
97
98 expect(updated.name).toEqual(created.name);
99 expect(updated.labels).toMatchObject({ env: "prod", role: "serving" });
100
101 yield* stack.destroy();
102
103 const gone = yield* waitUntilGone(created.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel),
106 {
107 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
108 timeout: 600_000,
109 },
110);