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
19 .getProjectsLocationsTensorboardsExperimentsRunsTimeSeries({ name })
20 .pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("2 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30test.provider(
31 "getProjectsLocationsTensorboardsExperimentsRunsTimeSeries on a missing series fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 aiplatform.getProjectsLocationsTensorboardsExperimentsRunsTimeSeries({
39 name: `projects/${project}/locations/us-central1/tensorboards/1234567890123456789/experiments/alchemy-missing/runs/alchemy-missing/timeSeries/1234567890123456789`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 {
47 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
48 timeout: 90_000,
49 },
50);
51
52test.provider(
53 "create, update, and delete a tensorboard time series",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
61 location: "us-central1",
62 displayName: "alchemy-ts-board",
63 labels: { env: "test" },
64 });
65 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment(
66 "Group",
67 {
68 parent: board.name,
69 displayName: "ts-group",
70 labels: { env: "test" },
71 },
72 );
73 const run = yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
74 parent: experiment.name,
75 displayName: "ts-pass",
76 labels: { env: "test" },
77 });
78 return yield* GCP.AIPlatform.TensorboardsExperimentsRunsTimeSeries(
79 "Loss",
80 {
81 parent: run.name,
82 displayName: "loss",
83 description: "training loss",
84 valueType: "SCALAR",
85 pluginName: "scalars",
86 },
87 );
88 }),
89 );
90
91 expect(created.name).toContain("/timeSeries/");
92 expect(created.valueType).toEqual("SCALAR");
93 expect(created.description).toEqual("training loss");
94
95 const fetched =
96 yield* aiplatform.getProjectsLocationsTensorboardsExperimentsRunsTimeSeries(
97 { name: created.name },
98 );
99 expect(fetched.name).toEqual(created.name);
100 expect(fetched.description).toContain("alchemy-id=");
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
105 location: "us-central1",
106 displayName: "alchemy-ts-board",
107 labels: { env: "test" },
108 });
109 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment(
110 "Group",
111 {
112 parent: board.name,
113 displayName: "ts-group",
114 labels: { env: "test" },
115 },
116 );
117 const run = yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
118 parent: experiment.name,
119 displayName: "ts-pass",
120 labels: { env: "test" },
121 });
122 return yield* GCP.AIPlatform.TensorboardsExperimentsRunsTimeSeries(
123 "Loss",
124 {
125 parent: run.name,
126 timeSeriesId: created.timeSeriesId,
127 displayName: "loss-v2",
128 description: "training loss v2",
129 valueType: "SCALAR",
130 pluginName: "scalars",
131 },
132 );
133 }),
134 );
135
136 expect(updated.name).toEqual(created.name);
137 expect(updated.description).toEqual("training loss v2");
138
139 yield* stack.destroy();
140 const gone = yield* waitUntilGone(created.name);
141 expect(gone).toEqual("gone");
142 }).pipe(logLevel),
143 {
144 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
145 timeout: 120_000,
146 },
147);