The best way to control Claude Code, Codex and more from any computer or phone

main
ts 98 lines 3.45 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as compute from "@distilled.cloud/gcp/compute_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const region = "us-central1";
14
15 const waitUntilGone = (project: string, regionName: string, healthAggregationPolicy: string) =>
16 compute
17 .getRegionHealthAggregationPolicies({
18 project,
19 region: regionName,
20 healthAggregationPolicy,
21 })
22 .pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("1 second"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "create, update, and delete a region health aggregation policy",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 return yield* GCP.Compute.RegionHealthAggregationPolicy("Agg", {
41 region,
42 description: "backend rollup",
43 minHealthyThreshold: 1,
44 healthyPercentThreshold: 60,
45 });
46 }),
47 );
48
49 expect(created.policyName).toEqual(expect.any(String));
50 expect(created.region).toEqual(region);
51 expect(created.policyType).toEqual("BACKEND_SERVICE_POLICY");
52 expect(created.description).toEqual("backend rollup");
53 expect(created.minHealthyThreshold).toEqual(1);
54 expect(created.healthyPercentThreshold).toEqual(60);
55
56 const fetched = yield* compute.getRegionHealthAggregationPolicies({
57 project: created.project,
58 region,
59 healthAggregationPolicy: created.policyName,
60 });
61 expect(fetched.name).toEqual(created.policyName);
62 expect(fetched.policyType).toEqual("BACKEND_SERVICE_POLICY");
63 expect(fetched.description).toContain("[alchemy ");
64 expect(fetched.description).toContain("backend rollup");
65
66 const updated = yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* GCP.Compute.RegionHealthAggregationPolicy("Agg", {
69 policyName: created.policyName,
70 region,
71 description: "updated rollup",
72 minHealthyThreshold: 2,
73 healthyPercentThreshold: 80,
74 });
75 }),
76 );
77
78 expect(updated.policyName).toEqual(created.policyName);
79 expect(updated.description).toEqual("updated rollup");
80 expect(updated.minHealthyThreshold).toEqual(2);
81 expect(updated.healthyPercentThreshold).toEqual(80);
82
83 const refetched = yield* compute.getRegionHealthAggregationPolicies({
84 project: updated.project,
85 region,
86 healthAggregationPolicy: updated.policyName,
87 });
88 expect(refetched.description).toContain("updated rollup");
89 expect(refetched.minHealthyThreshold).toEqual(2);
90 expect(refetched.healthyPercentThreshold).toEqual(80);
91
92 yield* stack.destroy();
93
94 const gone = yield* waitUntilGone(created.project, region, created.policyName);
95 expect(gone).toEqual("gone");
96 }).pipe(logLevel),
97 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
98 );