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.getProjectsLocationsTuningJobs({ 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 "getProjectsLocationsTuningJobs on a missing job fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 const parent = `projects/${project}/locations/us-central1`;
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 aiplatform.getProjectsLocationsTuningJobs({
38 name: `${parent}/tuningJobs/1234567890123456789`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42 const page = yield* aiplatform.listProjectsLocationsTuningJobs({
43 parent,
44 pageSize: 10,
45 });
46 expect((page.tuningJobs ?? []).map((item) => item.name)).not.toContain(
47 `${parent}/tuningJobs/1234567890123456789`,
48 );
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 {
53 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
54 timeout: 90_000,
55 },
56);
57
58test.provider(
59 "create and cancel a tuning job",
60 (stack) =>
61 Effect.gen(function* () {
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.AIPlatform.TuningJob("Tune", {
67 location: "us-central1",
68 baseModel: "gemini-2.5-flash",
69 supervisedTuningSpec: {
70 trainingDatasetUri:
71 "gs://cloud-samples-data/ai-platform/tuning/sft_train.jsonl",
72 },
73 });
74 }),
75 );
76
77 expect(created.name.length).toBeGreaterThan(0);
78 const live = yield* aiplatform.getProjectsLocationsTuningJobs({
79 name: created.name,
80 });
81 expect(live.name).toBe(created.name);
82
83 yield* stack.destroy();
84 yield* waitUntilGone(created.name);
85 }).pipe(logLevel),
86 {
87 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
88 timeout: 120_000,
89 },
90);