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.getProjectsLocationsTensorboardsExperimentsRuns({ 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 "getProjectsLocationsTensorboardsExperimentsRuns on a missing run 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.getProjectsLocationsTensorboardsExperimentsRuns({
37 name: `projects/${project}/locations/us-central1/tensorboards/1234567890123456789/experiments/alchemy-missing/runs/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 run",
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-run-board",
61 labels: { env: "test" },
62 });
63 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment(
64 "Group",
65 {
66 parent: board.name,
67 displayName: "run-group",
68 labels: { env: "test" },
69 },
70 );
71 return yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
72 parent: experiment.name,
73 displayName: "pass-1",
74 description: "first",
75 labels: { env: "test" },
76 });
77 }),
78 );
79
80 expect(created.name).toContain("/runs/");
81 expect(created.labels).toMatchObject({ env: "test" });
82
83 const fetched =
84 yield* aiplatform.getProjectsLocationsTensorboardsExperimentsRuns({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
92 location: "us-central1",
93 displayName: "alchemy-run-board",
94 labels: { env: "test" },
95 });
96 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment(
97 "Group",
98 {
99 parent: board.name,
100 displayName: "run-group",
101 labels: { env: "test" },
102 },
103 );
104 return yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
105 parent: experiment.name,
106 runId: created.runId,
107 displayName: "pass-2",
108 description: "second",
109 labels: { env: "prod" },
110 });
111 }),
112 );
113
114 expect(updated.name).toEqual(created.name);
115 expect(updated.description).toEqual("second");
116 expect(updated.labels).toMatchObject({ env: "prod" });
117
118 yield* stack.destroy();
119 const gone = yield* waitUntilGone(created.name);
120 expect(gone).toEqual("gone");
121 }).pipe(logLevel),
122 {
123 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
124 timeout: 120_000,
125 },
126);