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

main
ts 87 lines 2.72 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.getProjectsLocationsTuningJobs({ 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 "getProjectsLocationsTuningJobs on a missing job fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 const parent = `projects/${project}/locations/us-central1`;
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 aiplatform.getProjectsLocationsTuningJobs({
35 name: `${parent}/tuningJobs/1234567890123456789`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39 const page = yield* aiplatform.listProjectsLocationsTuningJobs({
40 parent,
41 pageSize: 10,
42 });
43 expect((page.tuningJobs ?? []).map((item) => item.name)).not.toContain(
44 `${parent}/tuningJobs/1234567890123456789`,
45 );
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
51 timeout: 90_000,
52 },
53 );
54
55 test.provider(
56 "create and cancel a tuning job",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* GCP.AIPlatform.TuningJob("Tune", {
64 location: "us-central1",
65 baseModel: "gemini-2.5-flash",
66 supervisedTuningSpec: {
67 trainingDatasetUri:
68 "gs://cloud-samples-data/ai-platform/generative_ai/gemini/text/sft_train_data.jsonl",
69 },
70 });
71 }),
72 );
73
74 expect(created.name.length).toBeGreaterThan(0);
75 const live = yield* aiplatform.getProjectsLocationsTuningJobs({
76 name: created.name,
77 });
78 expect(live.name).toBe(created.name);
79
80 yield* stack.destroy();
81 yield* waitUntilGone(created.name);
82 }).pipe(logLevel),
83 {
84 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
85 timeout: 120_000,
86 },
87 );