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.getProjectsLocationsMetadataStoresExecutions({ 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 "getProjectsLocationsMetadataStoresExecutions on a missing execution 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.getProjectsLocationsMetadataStoresExecutions({
37 name: `projects/${project}/locations/us-central1/metadataStores/alchemy-missing/executions/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 execution",
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 execution = yield* GCP.AIPlatform.MetadataStoresExecution(
63 "Train",
64 {
65 metadataStore: store.name,
66 displayName: "train-step",
67 description: "first",
68 state: "RUNNING",
69 labels: { env: "test" },
70 },
71 );
72 return { store, execution };
73 }),
74 );
75
76 expect(created.execution.name).toContain("/executions/");
77 expect(created.execution.metadataStore).toEqual(created.store.name);
78 expect(created.execution.displayName).toEqual("train-step");
79 expect(created.execution.labels).toMatchObject({ env: "test" });
80
81 const fetched =
82 yield* aiplatform.getProjectsLocationsMetadataStoresExecutions({
83 name: created.execution.name,
84 });
85 expect(fetched.name).toEqual(created.execution.name);
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 const store = yield* GCP.AIPlatform.MetadataStore("Mlmd", {
90 metadataStoreId: created.store.metadataStoreId,
91 location: "us-central1",
92 description: "pipeline metadata",
93 });
94 const execution = yield* GCP.AIPlatform.MetadataStoresExecution(
95 "Train",
96 {
97 metadataStore: store.name,
98 executionId: created.execution.executionId,
99 displayName: "train-step-v2",
100 description: "second",
101 state: "COMPLETE",
102 labels: { env: "prod" },
103 },
104 );
105 return { store, execution };
106 }),
107 );
108
109 expect(updated.execution.name).toEqual(created.execution.name);
110 expect(updated.execution.displayName).toEqual("train-step-v2");
111 expect(updated.execution.labels).toMatchObject({ env: "prod" });
112
113 yield* stack.destroy();
114 const gone = yield* waitUntilGone(created.execution.name);
115 expect(gone).toEqual("gone");
116 }).pipe(logLevel),
117 {
118 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
119 timeout: 180_000,
120 },
121);