@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 4.02 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), need TPU quota, and take
17 // several minutes to provision; set 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.getProjectsLocationsNodes({ 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 "getProjectsLocationsNodes on a missing node 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.getProjectsLocationsNodes({
40 name: `projects/${project}/locations/us-central1-c/nodes/alchemy-tpu-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, update, and delete a TPU node",
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.Node("Trainer", {
59 location: "us-central1-c",
60 acceleratorType: "v2-8",
61 runtimeVersion: "tpu-ubuntu2204-base",
62 description: "alchemy-test-tpu",
63 labels: { env: "test" },
64 });
65 }),
66 );
67
68 expect(created.name).toContain("/nodes/");
69 expect(created.nodeId).toEqual(expect.any(String));
70 expect(created.location).toEqual("us-central1-c");
71 expect(created.acceleratorType).toEqual("v2-8");
72 expect(created.description).toEqual("alchemy-test-tpu");
73 expect(created.labels).toMatchObject({ env: "test" });
74
75 const fetched = yield* tpu.getProjectsLocationsNodes({
76 name: created.name,
77 });
78 expect(fetched.name).toEqual(created.name);
79 expect(fetched.acceleratorType).toEqual("v2-8");
80 expect(fetched.description).toEqual("alchemy-test-tpu");
81 expect(fetched.labels?.env).toEqual("test");
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.TPU.Node("Trainer", {
86 nodeId: created.nodeId,
87 location: "us-central1-c",
88 acceleratorType: "v2-8",
89 runtimeVersion: "tpu-ubuntu2204-base",
90 description: "alchemy-prod-tpu",
91 labels: { env: "prod", role: "tpu" },
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.description).toEqual("alchemy-prod-tpu");
98 expect(updated.labels).toMatchObject({ env: "prod", role: "tpu" });
99
100 const refetched = yield* tpu.getProjectsLocationsNodes({
101 name: created.name,
102 });
103 expect(refetched.description).toEqual("alchemy-prod-tpu");
104 expect(refetched.labels?.env).toEqual("prod");
105 expect(refetched.labels?.role).toEqual("tpu");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(created.name);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:tpu", "live"], timeout: 120_000 },
113 );