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";
9import { UsersSource } from "./fixtures/features.ts";
10
11const { test } = Test.make({ providers: GCP.providers() });
12
13const logLevel = Effect.provideService(
14 MinimumLogLevel,
15 process.env.DEBUG ? "Debug" : "Info",
16);
17
18const waitUntilGone = (name: string) =>
19 aiplatform.getProjectsLocationsFeatureGroups({ 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
29test.provider(
30 "getProjectsLocationsFeatureGroups on a missing group fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 const parent = `projects/${project}/locations/us-central1`;
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 aiplatform.getProjectsLocationsFeatureGroups({
39 name: `${parent}/featureGroups/alchemy_missing`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43 const page = yield* aiplatform.listProjectsLocationsFeatureGroups({
44 parent,
45 pageSize: 10,
46 });
47 expect((page.featureGroups ?? []).map((item) => item.name)).not.toContain(
48 `${parent}/featureGroups/alchemy_missing`,
49 );
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
55 timeout: 90_000,
56 },
57);
58
59test.provider(
60 "create, update, and delete a feature group",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 const inputUri = yield* UsersSource;
68 return yield* GCP.AIPlatform.FeatureGroup("Users", {
69 location: "us-central1",
70 description: "user features",
71 labels: { env: "test" },
72 bigQuery: {
73 inputUri,
74 entityIdColumns: ["entity_id"],
75 },
76 });
77 }),
78 );
79
80 expect(created.name).toContain("/featureGroups/");
81 expect(created.location).toEqual("us-central1");
82 expect(created.labels).toMatchObject({ env: "test" });
83 expect(created.description).toEqual("user features");
84
85 const fetched = yield* aiplatform.getProjectsLocationsFeatureGroups({
86 name: created.name,
87 });
88 expect(fetched.name).toEqual(created.name);
89 expect(fetched.labels?.env).toEqual("test");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 const inputUri = yield* UsersSource;
94 return yield* GCP.AIPlatform.FeatureGroup("Users", {
95 featureGroupId: created.featureGroupId,
96 location: "us-central1",
97 description: "user features v2",
98 labels: { env: "prod", role: "features" },
99 bigQuery: {
100 inputUri,
101 entityIdColumns: ["entity_id"],
102 },
103 });
104 }),
105 );
106
107 expect(updated.name).toEqual(created.name);
108 expect(updated.description).toEqual("user features v2");
109 expect(updated.labels).toMatchObject({ env: "prod", role: "features" });
110
111 yield* stack.destroy();
112
113 const gone = yield* waitUntilGone(created.name);
114 expect(gone).toEqual("gone");
115 }).pipe(logLevel),
116 {
117 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
118 timeout: 600_000,
119 },
120);