@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 110 lines 3.41 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.getProjectsLocationsStudies({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 const studySpec = {
26 metrics: [{ metricId: "accuracy", goal: "MAXIMIZE" as const }],
27 parameters: [
28 {
29 parameterId: "learning_rate",
30 doubleValueSpec: { minValue: 0.001, maxValue: 0.1 },
31 },
32 ],
33 algorithm: "RANDOM_SEARCH" as const,
34 };
35
36 test.provider(
37 "getProjectsLocationsStudies on a missing study fails with a typed tag",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 aiplatform.getProjectsLocationsStudies({
45 name: `projects/${project}/locations/us-central1/studies/1234567890123456789`,
46 }),
47 );
48 expect(error._tag).toEqual("NotFound");
49 const page = yield* aiplatform.listProjectsLocationsStudies({
50 parent: `projects/${project}/locations/us-central1`,
51 pageSize: 10,
52 });
53 expect((page.studies ?? []).map((item) => item.name)).not.toContain(
54 `projects/${project}/locations/us-central1/studies/1234567890123456789`,
55 );
56
57 yield* stack.destroy();
58 }).pipe(logLevel),
59 {
60 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
61 timeout: 90_000,
62 },
63 );
64
65 test.provider(
66 "create and delete a vizier study",
67 (stack) =>
68 Effect.gen(function* () {
69 yield* stack.destroy();
70
71 const created = yield* stack.deploy(
72 Effect.gen(function* () {
73 return yield* GCP.AIPlatform.Study("Tune", {
74 location: "us-central1",
75 displayName: "accuracy_search",
76 studySpec,
77 });
78 }),
79 );
80
81 expect(created.name).toContain("/studies/");
82 expect(created.displayName).toEqual("accuracy_search");
83 expect(created.studySpec?.metrics?.[0]?.metricId).toEqual("accuracy");
84
85 const fetched = yield* aiplatform.getProjectsLocationsStudies({
86 name: created.name,
87 });
88 expect(fetched.name).toEqual(created.name);
89 expect(fetched.displayName).toContain("accuracy_search_alchemy_");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.AIPlatform.Study("Tune", {
94 location: "us-central1",
95 displayName: "accuracy_search",
96 studySpec,
97 });
98 }),
99 );
100 expect(updated.name).toEqual(created.name);
101
102 yield* stack.destroy();
103 const gone = yield* waitUntilGone(created.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel),
106 {
107 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
108 timeout: 90_000,
109 },
110 );