@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 121 lines 4.48 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 waitUntilGone = (project: string, httpsHealthCheck: string) =>
14 compute.getHttpsHealthChecks({ project, httpsHealthCheck }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, replace, and delete an HTTPS health check",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.Compute.HttpsHealthCheck("Api", {
33 description: "frontend probe",
34 port: 443,
35 requestPath: "/health",
36 });
37 }),
38 );
39
40 expect(created.httpsHealthCheckName).toEqual(expect.any(String));
41 expect(created.description).toEqual("frontend probe");
42 expect(created.port).toEqual(443);
43 expect(created.requestPath).toEqual("/health");
44 expect(created.checkIntervalSec).toEqual(5);
45 expect(created.healthyThreshold).toEqual(2);
46
47 const fetched = yield* compute.getHttpsHealthChecks({
48 project: created.project,
49 httpsHealthCheck: created.httpsHealthCheckName,
50 });
51 expect(fetched.name).toEqual(created.httpsHealthCheckName);
52 expect(fetched.port).toEqual(443);
53 expect(fetched.requestPath).toEqual("/health");
54 expect(fetched.description).toContain("[alchemy ");
55 expect(fetched.description).toContain("frontend probe");
56
57 const updated = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.Compute.HttpsHealthCheck("Api", {
60 httpsHealthCheckName: created.httpsHealthCheckName,
61 description: "ready probe",
62 checkIntervalSec: 10,
63 timeoutSec: 5,
64 healthyThreshold: 3,
65 port: 8443,
66 requestPath: "/ready",
67 host: "ready.example",
68 });
69 }),
70 );
71
72 expect(updated.httpsHealthCheckName).toEqual(created.httpsHealthCheckName);
73 expect(updated.description).toEqual("ready probe");
74 expect(updated.checkIntervalSec).toEqual(10);
75 expect(updated.healthyThreshold).toEqual(3);
76 expect(updated.port).toEqual(8443);
77 expect(updated.requestPath).toEqual("/ready");
78 expect(updated.host).toEqual("ready.example");
79
80 const refetched = yield* compute.getHttpsHealthChecks({
81 project: updated.project,
82 httpsHealthCheck: updated.httpsHealthCheckName,
83 });
84 expect(refetched.requestPath).toEqual("/ready");
85 expect(refetched.checkIntervalSec).toEqual(10);
86 expect(refetched.port).toEqual(8443);
87 expect(refetched.host).toEqual("ready.example");
88
89 const nextName = `r${created.httpsHealthCheckName}`.slice(0, 63).replace(/-+$/, "x");
90 const replaced = yield* stack.deploy(
91 Effect.gen(function* () {
92 return yield* GCP.Compute.HttpsHealthCheck("Api", {
93 httpsHealthCheckName: nextName,
94 description: "replaced probe",
95 requestPath: "/live",
96 });
97 }),
98 );
99
100 expect(replaced.httpsHealthCheckName).toEqual(nextName);
101 expect(replaced.description).toEqual("replaced probe");
102 expect(replaced.requestPath).toEqual("/live");
103 expect(replaced.port).toEqual(443);
104
105 const afterReplace = yield* compute.getHttpsHealthChecks({
106 project: replaced.project,
107 httpsHealthCheck: replaced.httpsHealthCheckName,
108 });
109 expect(afterReplace.name).toEqual(nextName);
110 expect(afterReplace.requestPath).toEqual("/live");
111
112 const oldGone = yield* waitUntilGone(created.project, created.httpsHealthCheckName);
113 expect(oldGone).toEqual("gone");
114
115 yield* stack.destroy();
116
117 const gone = yield* waitUntilGone(replaced.project, replaced.httpsHealthCheckName);
118 expect(gone).toEqual("gone");
119 }).pipe(logLevel),
120 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
121 );