@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 112 lines 3.87 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.getProjectsLocationsNotebookRuntimeTemplates({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsNotebookRuntimeTemplates on a missing template fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 const parent = `projects/${project}/locations/us-central1`;
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 aiplatform.getProjectsLocationsNotebookRuntimeTemplates({
35 name: `${parent}/notebookRuntimeTemplates/alchemy-missing`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39 const page = yield* aiplatform.listProjectsLocationsNotebookRuntimeTemplates({
40 parent,
41 pageSize: 10,
42 });
43 expect((page.notebookRuntimeTemplates ?? []).map((item) => item.name)).not.toContain(
44 `${parent}/notebookRuntimeTemplates/alchemy-missing`,
45 );
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
51 timeout: 90_000,
52 },
53 );
54
55 test.provider(
56 "create, update, and delete a notebook runtime template",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* GCP.AIPlatform.NotebookRuntimeTemplate("Runtime", {
64 location: "us-central1",
65 displayName: "alchemy-colab",
66 description: "colab default",
67 machineSpec: { machineType: "e2-standard-4" },
68 networkSpec: { enableInternetAccess: true },
69 labels: { env: "test" },
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/notebookRuntimeTemplates/");
75 expect(created.location).toEqual("us-central1");
76 expect(created.labels).toMatchObject({ env: "test" });
77 expect(created.description).toEqual("colab default");
78
79 const fetched = yield* aiplatform.getProjectsLocationsNotebookRuntimeTemplates({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.labels?.env).toEqual("test");
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 return yield* GCP.AIPlatform.NotebookRuntimeTemplate("Runtime", {
88 notebookRuntimeTemplateId: created.notebookRuntimeTemplateId,
89 location: "us-central1",
90 displayName: "alchemy-colab-v2",
91 description: "colab default",
92 machineSpec: { machineType: "e2-standard-4" },
93 networkSpec: { enableInternetAccess: true },
94 labels: { env: "test" },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.displayName).toEqual("alchemy-colab-v2");
101 expect(updated.labels).toMatchObject({ env: "test" });
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
110 timeout: 180_000,
111 },
112 );