@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 103 lines 3.6 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 dataproc from "@distilled.cloud/gcp/dataproc_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 dataproc.getProjectsLocationsSessionTemplates({ 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 test.provider(
26 "getProjectsLocationsSessionTemplates on a missing template fails with NotFound",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 dataproc.getProjectsLocationsSessionTemplates({
34 name: `projects/${project}/locations/us-central1/sessionTemplates/alchemy-dataproc-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 90_000 },
42 );
43
44 test.provider(
45 "create, update, and delete a session template",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const created = yield* stack.deploy(
51 Effect.gen(function* () {
52 return yield* GCP.Dataproc.SessionTemplate("Notebook", {
53 location: "us-central1",
54 description: "template a",
55 jupyterSession: { kernel: "PYTHON" },
56 labels: { env: "test" },
57 });
58 }),
59 );
60
61 expect(created.name).toContain("/sessionTemplates/");
62 expect(created.templateId).toEqual(expect.any(String));
63 expect(created.location).toEqual("us-central1");
64 expect(created.description).toEqual("template a");
65 expect(created.jupyterKernel).toEqual("PYTHON");
66 expect(created.labels).toMatchObject({ env: "test" });
67
68 const fetched = yield* dataproc.getProjectsLocationsSessionTemplates({
69 name: created.name,
70 });
71 expect(fetched.name).toEqual(created.name);
72 expect(fetched.labels?.env).toEqual("test");
73 expect(fetched.description).toEqual("template a");
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.Dataproc.SessionTemplate("Notebook", {
78 templateId: created.templateId,
79 location: "us-central1",
80 description: "template b",
81 jupyterSession: { kernel: "PYTHON" },
82 labels: { env: "prod", role: "nb" },
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.description).toEqual("template b");
89 expect(updated.labels).toMatchObject({ env: "prod", role: "nb" });
90
91 const refetched = yield* dataproc.getProjectsLocationsSessionTemplates({
92 name: created.name,
93 });
94 expect(refetched.description).toEqual("template b");
95 expect(refetched.labels?.env).toEqual("prod");
96
97 yield* stack.destroy();
98
99 const gone = yield* waitUntilGone(created.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 90_000 },
103 );