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