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 | // Persistent training clusters take 5-15 minutes to provision and tear down. |
| 15 | const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | aiplatform.getProjectsLocationsPersistentResources({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("2 seconds"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsPersistentResources on a missing resource fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const { project } = yield* GcpEnvironment.current; |
| 33 | const parent = `projects/${project}/locations/us-central1`; |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const error = yield* Effect.flip( |
| 37 | aiplatform.getProjectsLocationsPersistentResources({ |
| 38 | name: `${parent}/persistentResources/alchemy-missing`, |
| 39 | }), |
| 40 | ); |
| 41 | expect(error._tag).toEqual("NotFound"); |
| 42 | const page = yield* aiplatform.listProjectsLocationsPersistentResources({ |
| 43 | parent, |
| 44 | pageSize: 10, |
| 45 | }); |
| 46 | expect((page.persistentResources ?? []).map((item) => item.name)).not.toContain( |
| 47 | `${parent}/persistentResources/alchemy-missing`, |
| 48 | ); |
| 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.skipIf(!runLifecycle)( |
| 59 | "create, update, and delete a persistent resource", |
| 60 | (stack) => |
| 61 | Effect.gen(function* () { |
| 62 | yield* stack.destroy(); |
| 63 | |
| 64 | const created = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | return yield* GCP.AIPlatform.PersistentResource("Train", { |
| 67 | location: "us-central1", |
| 68 | displayName: "alchemy-persistent", |
| 69 | resourcePools: [ |
| 70 | { |
| 71 | id: "worker", |
| 72 | replicaCount: "1", |
| 73 | machineSpec: { machineType: "n1-standard-4" }, |
| 74 | }, |
| 75 | ], |
| 76 | labels: { env: "test" }, |
| 77 | }); |
| 78 | }), |
| 79 | ); |
| 80 | |
| 81 | expect(created.name).toContain("/persistentResources/"); |
| 82 | expect(created.location).toEqual("us-central1"); |
| 83 | expect(created.labels).toMatchObject({ env: "test" }); |
| 84 | |
| 85 | const fetched = yield* aiplatform.getProjectsLocationsPersistentResources({ |
| 86 | name: created.name, |
| 87 | }); |
| 88 | expect(fetched.name).toEqual(created.name); |
| 89 | expect(fetched.labels?.env).toEqual("test"); |
| 90 | |
| 91 | const updated = yield* stack.deploy( |
| 92 | Effect.gen(function* () { |
| 93 | return yield* GCP.AIPlatform.PersistentResource("Train", { |
| 94 | persistentResourceId: created.persistentResourceId, |
| 95 | location: "us-central1", |
| 96 | displayName: "alchemy-persistent", |
| 97 | resourcePools: [ |
| 98 | { |
| 99 | id: "worker", |
| 100 | // Non-Ray persistent resources cannot be updated in place, |
| 101 | // so a replica change replaces the resource. |
| 102 | replicaCount: "2", |
| 103 | machineSpec: { machineType: "n1-standard-4" }, |
| 104 | }, |
| 105 | ], |
| 106 | labels: { env: "test" }, |
| 107 | }); |
| 108 | }), |
| 109 | ); |
| 110 | |
| 111 | // Replaced under the same id. |
| 112 | expect(updated.name).toEqual(created.name); |
| 113 | const scaled = yield* aiplatform.getProjectsLocationsPersistentResources({ |
| 114 | name: created.name, |
| 115 | }); |
| 116 | expect(scaled.resourcePools?.[0]?.replicaCount).toEqual("2"); |
| 117 | |
| 118 | yield* stack.destroy(); |
| 119 | |
| 120 | const gone = yield* waitUntilGone(created.name); |
| 121 | expect(gone).toEqual("gone"); |
| 122 | }).pipe(logLevel), |
| 123 | // Provisioning the worker pool takes several minutes; so does teardown. |
| 124 | { |
| 125 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 126 | timeout: 2_400_000, |
| 127 | retry: 0, |
| 128 | }, |
| 129 | ); |