@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 100 lines 3.53 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.getProjectsLocationsAutoscalingPolicies({ 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 "getProjectsLocationsAutoscalingPolicies on a missing policy 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.getProjectsLocationsAutoscalingPolicies({
34 name: `projects/${project}/locations/us-central1/autoscalingPolicies/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 an autoscaling policy",
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.AutoscalingPolicy("SparkScale", {
53 location: "us-central1",
54 workerConfig: { minInstances: 2, maxInstances: 3 },
55 labels: { env: "test" },
56 });
57 }),
58 );
59
60 expect(created.name).toContain("/autoscalingPolicies/");
61 expect(created.policyId).toEqual(expect.any(String));
62 expect(created.location).toEqual("us-central1");
63 expect(created.labels).toMatchObject({ env: "test" });
64 expect(created.workerMaxInstances).toEqual(3);
65
66 const fetched = yield* dataproc.getProjectsLocationsAutoscalingPolicies({
67 name: created.name,
68 });
69 expect(fetched.name).toEqual(created.name);
70 expect(fetched.labels?.env).toEqual("test");
71 expect(fetched.workerConfig?.maxInstances).toEqual(3);
72
73 const updated = yield* stack.deploy(
74 Effect.gen(function* () {
75 return yield* GCP.Dataproc.AutoscalingPolicy("SparkScale", {
76 policyId: created.policyId,
77 location: "us-central1",
78 workerConfig: { minInstances: 2, maxInstances: 4 },
79 labels: { env: "prod", role: "scale" },
80 });
81 }),
82 );
83
84 expect(updated.name).toEqual(created.name);
85 expect(updated.workerMaxInstances).toEqual(4);
86 expect(updated.labels).toMatchObject({ env: "prod", role: "scale" });
87
88 const refetched = yield* dataproc.getProjectsLocationsAutoscalingPolicies({
89 name: created.name,
90 });
91 expect(refetched.workerConfig?.maxInstances).toEqual(4);
92 expect(refetched.labels?.env).toEqual("prod");
93
94 yield* stack.destroy();
95
96 const gone = yield* waitUntilGone(created.name);
97 expect(gone).toEqual("gone");
98 }).pipe(logLevel),
99 { tags: ["provider:gcp", "provider:gcp:dataproc", "live"], timeout: 90_000 },
100 );