@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 113 lines 3.32 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.getProjectsLocationsNasJobs({ 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 nasJobSpec = {
26 searchSpaceSpec: "{}",
27 multiTrialAlgorithmSpec: {
28 metric: { metricId: "accuracy", goal: "MAXIMIZE" as const },
29 searchTrialSpec: {
30 maxTrialCount: 1,
31 maxParallelTrialCount: 1,
32 searchTrialJobSpec: {
33 workerPoolSpecs: [
34 {
35 machineSpec: { machineType: "n1-standard-4" },
36 replicaCount: "1",
37 containerSpec: {
38 imageUri: "us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-12.py310:latest",
39 command: ["echo", "ok"],
40 },
41 },
42 ],
43 },
44 },
45 },
46 };
47
48 test.provider(
49 "getProjectsLocationsNasJobs on a missing job fails with a typed tag",
50 (stack) =>
51 Effect.gen(function* () {
52 const { project } = yield* GcpEnvironment.current;
53 const parent = `projects/${project}/locations/us-central1`;
54 yield* stack.destroy();
55
56 const error = yield* Effect.flip(
57 aiplatform.getProjectsLocationsNasJobs({
58 name: `${parent}/nasJobs/1234567890123456789`,
59 }),
60 );
61 expect(error._tag).toEqual("NotFound");
62 const page = yield* aiplatform.listProjectsLocationsNasJobs({
63 parent,
64 pageSize: 10,
65 });
66 expect((page.nasJobs ?? []).map((item) => item.name)).not.toContain(
67 `${parent}/nasJobs/1234567890123456789`,
68 );
69
70 yield* stack.destroy();
71 }).pipe(logLevel),
72 {
73 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
74 timeout: 90_000,
75 },
76 );
77
78 test.provider(
79 "create and delete a nas job",
80 (stack) =>
81 Effect.gen(function* () {
82 yield* stack.destroy();
83
84 const created = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* GCP.AIPlatform.NasJob("Search", {
87 location: "us-central1",
88 displayName: "alchemy-nas",
89 nasJobSpec,
90 labels: { env: "test" },
91 });
92 }),
93 );
94
95 expect(created.name).toContain("/nasJobs/");
96 expect(created.location).toEqual("us-central1");
97 expect(created.labels).toMatchObject({ env: "test" });
98
99 const fetched = yield* aiplatform.getProjectsLocationsNasJobs({
100 name: created.name,
101 });
102 expect(fetched.name).toEqual(created.name);
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 {
110 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
111 timeout: 180_000,
112 },
113 );