@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 95 lines 3.44 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 tpu from "@distilled.cloud/gcp/tpu_v2";
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 // Cloud TPU is disabled on the testing project (ServiceDisabled "Cloud TPU API
15 // has not been used in project ...") and TPU VMs bill by the hour (dollars
16 // per run) and need TPU quota; set
17 // GCP_TEST_TPU=1 to opt in.
18 const runLifecycle = !!process.env.GCP_TEST_TPU && !process.env.FAST;
19
20 const waitUntilGone = (name: string) =>
21 tpu.getProjectsLocationsQueuedResources({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsLocationsQueuedResources on a missing resource fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 tpu.getProjectsLocationsQueuedResources({
40 name: `projects/${project}/locations/us-central1-c/queuedResources/alchemy-tpu-qr-missing`,
41 }),
42 );
43 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:tpu", "live"], timeout: 90_000 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create and delete a TPU queued resource",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 return yield* GCP.TPU.QueuedResource("Trainer", {
59 location: "us-central1-c",
60 nodeSpec: [
61 {
62 node: {
63 acceleratorType: "v2-8",
64 runtimeVersion: "tpu-ubuntu2204-base",
65 description: "alchemy-test-qr",
66 labels: { env: "test" },
67 },
68 },
69 ],
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/queuedResources/");
75 expect(created.queuedResourceId).toEqual(expect.any(String));
76 expect(created.location).toEqual("us-central1-c");
77 expect(created.nodeSpec.length).toBeGreaterThan(0);
78 expect(created.nodeSpec[0]?.node?.acceleratorType).toEqual("v2-8");
79 expect(created.nodeSpec[0]?.node?.description).toEqual("alchemy-test-qr");
80 expect(created.nodeSpec[0]?.node?.labels).toMatchObject({ env: "test" });
81
82 const fetched = yield* tpu.getProjectsLocationsQueuedResources({
83 name: created.name,
84 });
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.tpu?.nodeSpec?.[0]?.node?.acceleratorType).toEqual("v2-8");
87 expect(fetched.tpu?.nodeSpec?.[0]?.node?.labels?.env).toEqual("test");
88
89 yield* stack.destroy();
90
91 const gone = yield* waitUntilGone(created.name);
92 expect(gone).toEqual("gone");
93 }).pipe(logLevel),
94 { tags: ["provider:gcp", "provider:gcp:tpu", "live"], timeout: 120_000 },
95 );