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.getProjectsLocationsPipelineJobs({ 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
28const pipelineSpec = {
29 pipelineInfo: { name: "alchemy-echo" },
30 schemaVersion: "2.1.0",
31 sdkVersion: "kfp-2.0.0",
32 components: {},
33 root: { dag: { tasks: {} } },
34};
35
36test.provider(
37 "getProjectsLocationsPipelineJobs on a missing job fails with a typed tag",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 const parent = `projects/${project}/locations/us-central1`;
42 yield* stack.destroy();
43
44 const error = yield* Effect.flip(
45 aiplatform.getProjectsLocationsPipelineJobs({
46 name: `${parent}/pipelineJobs/alchemy-missing`,
47 }),
48 );
49 expect(error._tag).toEqual("NotFound");
50 const page = yield* aiplatform.listProjectsLocationsPipelineJobs({
51 parent,
52 pageSize: 10,
53 });
54 expect((page.pipelineJobs ?? []).map((item) => item.name)).not.toContain(
55 `${parent}/pipelineJobs/alchemy-missing`,
56 );
57
58 yield* stack.destroy();
59 }).pipe(logLevel),
60 {
61 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
62 timeout: 90_000,
63 },
64);
65
66test.provider(
67 "create and delete a pipeline job",
68 (stack) =>
69 Effect.gen(function* () {
70 yield* stack.destroy();
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.AIPlatform.PipelineJob("Train", {
75 location: "us-central1",
76 displayName: "alchemy-pipeline",
77 pipelineSpec,
78 runtimeConfig: {
79 gcsOutputDirectory: "gs://alchemy-aiplatform-test/pipeline-out",
80 },
81 labels: { env: "test" },
82 });
83 }),
84 );
85
86 expect(created.name).toContain("/pipelineJobs/");
87 expect(created.location).toEqual("us-central1");
88 expect(created.labels).toMatchObject({ env: "test" });
89
90 const fetched = yield* aiplatform.getProjectsLocationsPipelineJobs({
91 name: created.name,
92 });
93 expect(fetched.name).toEqual(created.name);
94
95 yield* stack.destroy();
96
97 const gone = yield* waitUntilGone(created.name);
98 expect(gone).toEqual("gone");
99 }).pipe(logLevel),
100 {
101 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
102 timeout: 180_000,
103 },
104);