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

main
ts 105 lines 3.48 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.getProjectsLocationsTensorboards({ 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 "getProjectsLocationsTensorboards on a missing tensorboard 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.getProjectsLocationsTensorboards({
34 name: `projects/${project}/locations/us-central1/tensorboards/1234567890123456789`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38 const page = yield* aiplatform.listProjectsLocationsTensorboards({
39 parent: `projects/${project}/locations/us-central1`,
40 pageSize: 10,
41 });
42 expect((page.tensorboards ?? []).map((item) => item.name)).not.toContain(
43 `projects/${project}/locations/us-central1/tensorboards/1234567890123456789`,
44 );
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider(
55 "create, update, and delete a tensorboard",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const created = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.AIPlatform.Tensorboard("Metrics", {
63 location: "us-central1",
64 displayName: "alchemy-tb",
65 description: "metrics",
66 labels: { env: "test" },
67 });
68 }),
69 );
70
71 expect(created.name).toContain("/tensorboards/");
72 expect(created.location).toEqual("us-central1");
73 expect(created.labels).toMatchObject({ env: "test" });
74 expect(created.description).toEqual("metrics");
75
76 const fetched = yield* aiplatform.getProjectsLocationsTensorboards({
77 name: created.name,
78 });
79 expect(fetched.name).toEqual(created.name);
80 expect(fetched.labels?.env).toEqual("test");
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.AIPlatform.Tensorboard("Metrics", {
85 location: "us-central1",
86 displayName: "alchemy-tb",
87 description: "metrics-v2",
88 labels: { env: "prod", role: "metrics" },
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.description).toEqual("metrics-v2");
95 expect(updated.labels).toMatchObject({ env: "prod", role: "metrics" });
96
97 yield* stack.destroy();
98 const gone = yield* waitUntilGone(created.name);
99 expect(gone).toEqual("gone");
100 }).pipe(logLevel),
101 {
102 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
103 timeout: 120_000,
104 },
105 );