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

main
ts 120 lines 4.17 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.getProjectsLocationsTrainingPipelines({ 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 "getProjectsLocationsTrainingPipelines on a missing pipeline 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.getProjectsLocationsTrainingPipelines({
34 name: `projects/${project}/locations/us-central1/trainingPipelines/1234567890123456789`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38 const page = yield* aiplatform.listProjectsLocationsTrainingPipelines({
39 parent: `projects/${project}/locations/us-central1`,
40 pageSize: 10,
41 });
42 expect((page.trainingPipelines ?? []).map((item) => item.name)).not.toContain(
43 `projects/${project}/locations/us-central1/trainingPipelines/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, refresh, and delete a training pipeline",
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.TrainingPipeline("Train", {
63 location: "us-central1",
64 displayName: "alchemy-test-pipeline",
65 trainingTaskDefinition:
66 "gs://google-cloud-aiplatform/schema/trainingjob/definition/custom_task_1.0.0.yaml",
67 trainingTaskInputs: {
68 workerPoolSpecs: [
69 {
70 machineSpec: { machineType: "n1-standard-4" },
71 replicaCount: "1",
72 containerSpec: {
73 imageUri: "us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-12.py310:latest",
74 command: ["echo", "ok"],
75 },
76 },
77 ],
78 },
79 labels: { env: "test" },
80 });
81 }),
82 );
83
84 expect(created.name).toContain("/trainingPipelines/");
85 expect(created.trainingPipelineId).toEqual(expect.any(String));
86 expect(created.location).toEqual("us-central1");
87 expect(created.labels).toMatchObject({ env: "test" });
88
89 const fetched = yield* aiplatform.getProjectsLocationsTrainingPipelines({
90 name: created.name,
91 });
92 expect(fetched.name).toEqual(created.name);
93 expect(fetched.labels?.env).toEqual("test");
94
95 const updated = yield* stack.deploy(
96 Effect.gen(function* () {
97 return yield* GCP.AIPlatform.TrainingPipeline("Train", {
98 trainingPipelineId: created.trainingPipelineId,
99 location: "us-central1",
100 displayName: "alchemy-test-pipeline",
101 trainingTaskDefinition: created.trainingTaskDefinition ?? "",
102 trainingTaskInputs: created.trainingTaskInputs,
103 labels: { env: "prod" },
104 });
105 }),
106 );
107
108 expect(updated.name).toEqual(created.name);
109 expect(updated.trainingPipelineId).toEqual(created.trainingPipelineId);
110
111 yield* stack.destroy();
112
113 const gone = yield* waitUntilGone(created.name);
114 expect(gone).toEqual("gone");
115 }).pipe(logLevel),
116 {
117 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
118 timeout: 120_000,
119 },
120 );