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

main
ts 101 lines 3.08 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.getProjectsLocationsPipelineJobs({ 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 const pipelineSpec = {
26 pipelineInfo: { name: "alchemy-echo" },
27 schemaVersion: "2.1.0",
28 sdkVersion: "kfp-2.0.0",
29 components: {},
30 root: { dag: { tasks: {} } },
31 };
32
33 test.provider(
34 "getProjectsLocationsPipelineJobs on a missing job fails with a typed tag",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 const parent = `projects/${project}/locations/us-central1`;
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 aiplatform.getProjectsLocationsPipelineJobs({
43 name: `${parent}/pipelineJobs/alchemy-missing`,
44 }),
45 );
46 expect(error._tag).toEqual("NotFound");
47 const page = yield* aiplatform.listProjectsLocationsPipelineJobs({
48 parent,
49 pageSize: 10,
50 });
51 expect((page.pipelineJobs ?? []).map((item) => item.name)).not.toContain(
52 `${parent}/pipelineJobs/alchemy-missing`,
53 );
54
55 yield* stack.destroy();
56 }).pipe(logLevel),
57 {
58 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
59 timeout: 90_000,
60 },
61 );
62
63 test.provider(
64 "create and delete a pipeline job",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 return yield* GCP.AIPlatform.PipelineJob("Train", {
72 location: "us-central1",
73 displayName: "alchemy-pipeline",
74 pipelineSpec,
75 runtimeConfig: {
76 gcsOutputDirectory: "gs://alchemy-aiplatform-test/pipeline-out",
77 },
78 labels: { env: "test" },
79 });
80 }),
81 );
82
83 expect(created.name).toContain("/pipelineJobs/");
84 expect(created.location).toEqual("us-central1");
85 expect(created.labels).toMatchObject({ env: "test" });
86
87 const fetched = yield* aiplatform.getProjectsLocationsPipelineJobs({
88 name: created.name,
89 });
90 expect(fetched.name).toEqual(created.name);
91
92 yield* stack.destroy();
93
94 const gone = yield* waitUntilGone(created.name);
95 expect(gone).toEqual("gone");
96 }).pipe(logLevel),
97 {
98 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
99 timeout: 180_000,
100 },
101 );