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
| 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.getProjectsLocationsStudiesTrials({ 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 | "getProjectsLocationsStudiesTrials on a missing trial 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.getProjectsLocationsStudiesTrials({ |
| 45 | name: `projects/${project}/locations/us-central1/studies/1234567890123456789/trials/1`, |
| 46 | }), |
| 47 | ); |
| 48 | expect(error._tag).toEqual("NotFound"); |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | }).pipe(logLevel), |
| 52 | { |
| 53 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 54 | timeout: 90_000, |
| 55 | }, |
| 56 | ); |
| 57 | |
| 58 | test.provider( |
| 59 | "create and delete a user-provided vizier trial", |
| 60 | (stack) => |
| 61 | Effect.gen(function* () { |
| 62 | yield* stack.destroy(); |
| 63 | |
| 64 | const created = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const study = yield* GCP.AIPlatform.Study("Tune", { |
| 67 | location: "us-central1", |
| 68 | displayName: "trial_search", |
| 69 | studySpec, |
| 70 | }); |
| 71 | return yield* GCP.AIPlatform.StudiesTrial("Seed", { |
| 72 | parent: study.name, |
| 73 | parameters: [{ parameterId: "learning_rate", value: 0.01 }], |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.name).toContain("/trials/"); |
| 79 | expect(created.parameters[0]?.parameterId).toEqual("learning_rate"); |
| 80 | |
| 81 | const fetched = yield* aiplatform.getProjectsLocationsStudiesTrials({ |
| 82 | name: created.name, |
| 83 | }); |
| 84 | expect(fetched.name).toEqual(created.name); |
| 85 | |
| 86 | yield* stack.destroy(); |
| 87 | const gone = yield* waitUntilGone(created.name); |
| 88 | expect(gone).toEqual("gone"); |
| 89 | }).pipe(logLevel), |
| 90 | { |
| 91 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 92 | timeout: 90_000, |
| 93 | }, |
| 94 | ); |