@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 135 lines 4.74 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 compute from "@distilled.cloud/gcp/compute_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 // Health Check as a Service is allowlisted; without it insert fails with
15 // `BadRequest: Invalid resource usage: 'HealthCheck as a Service feature is
16 // not available for this project.'`. Set GCP_TEST_HCAAS=1 on an allowlisted
17 // project.
18 const runLifecycle = !!process.env.GCP_TEST_HCAAS && !process.env.FAST;
19
20 const region = "us-central1";
21
22 const waitUntilGone = (project: string, regionName: string, healthCheckService: string) =>
23 compute
24 .getRegionHealthCheckServices({
25 project,
26 region: regionName,
27 healthCheckService,
28 })
29 .pipe(
30 Effect.as("found" as const),
31 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
32 Effect.repeat({
33 schedule: Schedule.spaced("1 second"),
34 until: (status) => status === "gone",
35 times: 10,
36 }),
37 );
38
39 test.provider(
40 "insertRegionHealthCheckServices without the feature fails with HealthCheckServiceNotAvailable",
41 () =>
42 Effect.gen(function* () {
43 const { project } = yield* GcpEnvironment.current;
44 const error = yield* Effect.flip(
45 compute.insertRegionHealthCheckServices({
46 project,
47 region,
48 body: {
49 name: "alchemy-hcss-probe",
50 description: "alchemy entitlement probe",
51 healthChecks: [`projects/${project}/regions/${region}/healthChecks/does-not-exist`],
52 },
53 }),
54 );
55 expect(error._tag).toEqual("HealthCheckServiceNotAvailable");
56 }).pipe(logLevel),
57 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 },
58 );
59
60 test.provider.skipIf(!runLifecycle)(
61 "create, update, and delete a region health check service",
62 (stack) =>
63 Effect.gen(function* () {
64 yield* stack.destroy();
65
66 const created = yield* stack.deploy(
67 Effect.gen(function* () {
68 const check = yield* GCP.Compute.RegionHealthCheck("Api", {
69 region,
70 httpHealthCheck: {
71 port: 80,
72 portSpecification: "USE_FIXED_PORT",
73 requestPath: "/health",
74 },
75 });
76 return yield* GCP.Compute.RegionHealthCheckService("Hcss", {
77 region,
78 healthChecks: [check.selfLink.as<string>()],
79 description: "endpoint health",
80 });
81 }),
82 );
83
84 expect(created.serviceName).toEqual(expect.any(String));
85 expect(created.region).toEqual(region);
86 expect(created.description).toEqual("endpoint health");
87 expect(created.healthChecks.length).toBeGreaterThan(0);
88 expect(created.healthStatusAggregationPolicy).toEqual("NO_AGGREGATION");
89
90 const fetched = yield* compute.getRegionHealthCheckServices({
91 project: created.project,
92 region,
93 healthCheckService: created.serviceName,
94 });
95 expect(fetched.name).toEqual(created.serviceName);
96 expect(fetched.description).toContain("[alchemy ");
97 expect(fetched.description).toContain("endpoint health");
98 expect(fetched.healthChecks?.length).toBeGreaterThan(0);
99
100 const updated = yield* stack.deploy(
101 Effect.gen(function* () {
102 const check = yield* GCP.Compute.RegionHealthCheck("Api", {
103 region,
104 httpHealthCheck: {
105 port: 80,
106 portSpecification: "USE_FIXED_PORT",
107 requestPath: "/health",
108 },
109 });
110 return yield* GCP.Compute.RegionHealthCheckService("Hcss", {
111 serviceName: created.serviceName,
112 region,
113 healthChecks: [check.selfLink.as<string>()],
114 description: "updated health",
115 });
116 }),
117 );
118
119 expect(updated.serviceName).toEqual(created.serviceName);
120 expect(updated.description).toEqual("updated health");
121
122 const refetched = yield* compute.getRegionHealthCheckServices({
123 project: updated.project,
124 region,
125 healthCheckService: updated.serviceName,
126 });
127 expect(refetched.description).toContain("updated health");
128
129 yield* stack.destroy();
130
131 const gone = yield* waitUntilGone(created.project, region, created.serviceName);
132 expect(gone).toEqual("gone");
133 }).pipe(logLevel),
134 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
135 );