The best way to control Claude Code, Codex and more from any computer or phone

main
ts 129 lines 4.53 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (name: string) =>
15 aiplatform.getProjectsLocationsTensorboardsExperimentsRunsTimeSeries({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsTensorboardsExperimentsRunsTimeSeries on a missing series fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 aiplatform.getProjectsLocationsTensorboardsExperimentsRunsTimeSeries({
34 name: `projects/${project}/locations/us-central1/tensorboards/1234567890123456789/experiments/alchemy-missing/runs/alchemy-missing/timeSeries/1234567890123456789`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a tensorboard time series",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
56 location: "us-central1",
57 displayName: "alchemy-ts-board",
58 labels: { env: "test" },
59 });
60 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment("Group", {
61 parent: board.name,
62 displayName: "ts-group",
63 labels: { env: "test" },
64 });
65 const run = yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
66 parent: experiment.name,
67 displayName: "ts-pass",
68 labels: { env: "test" },
69 });
70 return yield* GCP.AIPlatform.TensorboardsExperimentsRunsTimeSeries("Loss", {
71 parent: run.name,
72 displayName: "loss",
73 description: "training loss",
74 valueType: "SCALAR",
75 pluginName: "scalars",
76 });
77 }),
78 );
79
80 expect(created.name).toContain("/timeSeries/");
81 expect(created.valueType).toEqual("SCALAR");
82 expect(created.description).toEqual("training loss");
83
84 const fetched = yield* aiplatform.getProjectsLocationsTensorboardsExperimentsRunsTimeSeries({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.description).toContain("alchemy-id=");
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 const board = yield* GCP.AIPlatform.Tensorboard("Board", {
93 location: "us-central1",
94 displayName: "alchemy-ts-board",
95 labels: { env: "test" },
96 });
97 const experiment = yield* GCP.AIPlatform.TensorboardsExperiment("Group", {
98 parent: board.name,
99 displayName: "ts-group",
100 labels: { env: "test" },
101 });
102 const run = yield* GCP.AIPlatform.TensorboardsExperimentsRun("Pass", {
103 parent: experiment.name,
104 displayName: "ts-pass",
105 labels: { env: "test" },
106 });
107 return yield* GCP.AIPlatform.TensorboardsExperimentsRunsTimeSeries("Loss", {
108 parent: run.name,
109 timeSeriesId: created.timeSeriesId,
110 displayName: "loss-v2",
111 description: "training loss v2",
112 valueType: "SCALAR",
113 pluginName: "scalars",
114 });
115 }),
116 );
117
118 expect(updated.name).toEqual(created.name);
119 expect(updated.description).toEqual("training loss v2");
120
121 yield* stack.destroy();
122 const gone = yield* waitUntilGone(created.name);
123 expect(gone).toEqual("gone");
124 }).pipe(logLevel),
125 {
126 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
127 timeout: 120_000,
128 },
129 );