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

main
ts 108 lines 3.58 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 Output from "alchemy/Output";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const waitUntilGone = (name: string) =>
16 aiplatform.getProjectsLocationsBatchPredictionJobs({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsBatchPredictionJobs on a missing job fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 const { project } = yield* GcpEnvironment.current;
31 const parent = `projects/${project}/locations/us-central1`;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 aiplatform.getProjectsLocationsBatchPredictionJobs({
36 name: `${parent}/batchPredictionJobs/1234567890123456789`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40 const page = yield* aiplatform.listProjectsLocationsBatchPredictionJobs({
41 parent,
42 pageSize: 10,
43 });
44 expect((page.batchPredictionJobs ?? []).map((item) => item.name)).not.toContain(
45 `${parent}/batchPredictionJobs/1234567890123456789`,
46 );
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 {
51 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
52 timeout: 90_000,
53 },
54 );
55
56 test.provider(
57 "create and delete a batch prediction job",
58 (stack) =>
59 Effect.gen(function* () {
60 const { project } = yield* GcpEnvironment.current;
61 const parent = `projects/${project}/locations/us-central1`;
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 const bucket = yield* GCP.Storage.Bucket("BatchOut", {
67 location: "US-CENTRAL1",
68 forceDestroy: true,
69 });
70 return yield* GCP.AIPlatform.BatchPredictionJob("Nightly", {
71 location: "us-central1",
72 displayName: "alchemy-batch",
73 model: `${parent}/publishers/google/models/gemini-2.5-flash`,
74 inputConfig: {
75 instancesFormat: "jsonl",
76 gcsSource: {
77 uris: ["gs://cloud-samples-data/vertex-ai/batch.jsonl"],
78 },
79 },
80 outputConfig: {
81 predictionsFormat: "jsonl",
82 gcsDestination: {
83 outputUriPrefix: Output.interpolate`gs://${bucket.bucketName}/out/`,
84 },
85 },
86 labels: { env: "test" },
87 });
88 }),
89 );
90
91 expect(created.name).toContain("/batchPredictionJobs/");
92 expect(created.labels).toMatchObject({ env: "test" });
93
94 const fetched = yield* aiplatform.getProjectsLocationsBatchPredictionJobs({
95 name: created.name,
96 });
97 expect(fetched.name).toEqual(created.name);
98
99 yield* stack.destroy();
100
101 const gone = yield* waitUntilGone(created.name);
102 expect(gone).toEqual("gone");
103 }).pipe(logLevel),
104 {
105 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
106 timeout: 120_000,
107 },
108 );