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.getProjectsLocationsTensorboardsExperiments({ 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 "getProjectsLocationsTensorboardsExperiments on a missing experiment 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.getProjectsLocationsTensorboardsExperiments({
37 name: `projects/${project}/locations/us-central1/tensorboards/1234567890123456789/experiments/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 tensorboard experiment",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
59 location: "us-central1",
60 displayName: "alchemy-exp-board",
61 labels: { env: "test" },
62 });
63 return yield* GCP.AIPlatform.TensorboardsExperiment("Group", {
64 parent: board.name,
65 displayName: "baseline",
66 description: "first",
67 labels: { env: "test" },
68 });
69 }),
70 );
71
72 expect(created.name).toContain("/experiments/");
73 expect(created.labels).toMatchObject({ env: "test" });
74 expect(created.description).toEqual("first");
75
76 const fetched =
77 yield* aiplatform.getProjectsLocationsTensorboardsExperiments({
78 name: created.name,
79 });
80 expect(fetched.name).toEqual(created.name);
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
85 location: "us-central1",
86 displayName: "alchemy-exp-board",
87 labels: { env: "test" },
88 });
89 return yield* GCP.AIPlatform.TensorboardsExperiment("Group", {
90 parent: board.name,
91 experimentId: created.experimentId,
92 displayName: "baseline-v2",
93 description: "second",
94 labels: { env: "prod" },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.description).toEqual("second");
101 expect(updated.labels).toMatchObject({ env: "prod" });
102
103 yield* stack.destroy();
104 const gone = yield* waitUntilGone(created.name);
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 {
108 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
109 timeout: 120_000,
110 },
111);