The best way to control Claude Code, Codex and more from any computer or phone
| 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, healthCheckName: string) => |
| 14 | compute.getHealthChecks({ project, healthCheck: healthCheckName }).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, and delete a 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.HealthCheck("Api", { |
| 33 | description: "frontend probe", |
| 34 | httpHealthCheck: { port: 80, requestPath: "/health" }, |
| 35 | }); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | expect(created.healthCheckName).toEqual(expect.any(String)); |
| 40 | expect(created.type).toEqual("HTTP"); |
| 41 | expect(created.description).toEqual("frontend probe"); |
| 42 | expect(created.httpHealthCheck?.requestPath).toEqual("/health"); |
| 43 | expect(created.checkIntervalSec).toEqual(5); |
| 44 | |
| 45 | const fetched = yield* compute.getHealthChecks({ |
| 46 | project: created.project, |
| 47 | healthCheck: created.healthCheckName, |
| 48 | }); |
| 49 | expect(fetched.name).toEqual(created.healthCheckName); |
| 50 | expect(fetched.type).toEqual("HTTP"); |
| 51 | expect(fetched.httpHealthCheck?.requestPath).toEqual("/health"); |
| 52 | expect(fetched.description).toContain("[alchemy "); |
| 53 | expect(fetched.description).toContain("frontend probe"); |
| 54 | |
| 55 | const updated = yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | return yield* GCP.Compute.HealthCheck("Api", { |
| 58 | healthCheckName: created.healthCheckName, |
| 59 | description: "ready probe", |
| 60 | checkIntervalSec: 10, |
| 61 | timeoutSec: 5, |
| 62 | healthyThreshold: 3, |
| 63 | httpHealthCheck: { port: 80, requestPath: "/ready" }, |
| 64 | }); |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | expect(updated.healthCheckName).toEqual(created.healthCheckName); |
| 69 | expect(updated.type).toEqual("HTTP"); |
| 70 | expect(updated.description).toEqual("ready probe"); |
| 71 | expect(updated.checkIntervalSec).toEqual(10); |
| 72 | expect(updated.healthyThreshold).toEqual(3); |
| 73 | expect(updated.httpHealthCheck?.requestPath).toEqual("/ready"); |
| 74 | |
| 75 | const refetched = yield* compute.getHealthChecks({ |
| 76 | project: updated.project, |
| 77 | healthCheck: updated.healthCheckName, |
| 78 | }); |
| 79 | expect(refetched.type).toEqual("HTTP"); |
| 80 | expect(refetched.httpHealthCheck?.requestPath).toEqual("/ready"); |
| 81 | expect(refetched.checkIntervalSec).toEqual(10); |
| 82 | |
| 83 | const replaced = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* GCP.Compute.HealthCheck("Api", { |
| 86 | healthCheckName: created.healthCheckName, |
| 87 | description: "tcp probe", |
| 88 | type: "TCP", |
| 89 | tcpHealthCheck: { port: 8080 }, |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(replaced.healthCheckName).toEqual(created.healthCheckName); |
| 95 | expect(replaced.type).toEqual("TCP"); |
| 96 | expect(replaced.description).toEqual("tcp probe"); |
| 97 | expect(replaced.tcpHealthCheck?.port).toEqual(8080); |
| 98 | |
| 99 | const afterReplace = yield* compute.getHealthChecks({ |
| 100 | project: replaced.project, |
| 101 | healthCheck: replaced.healthCheckName, |
| 102 | }); |
| 103 | expect(afterReplace.type).toEqual("TCP"); |
| 104 | expect(afterReplace.tcpHealthCheck?.port).toEqual(8080); |
| 105 | expect(afterReplace.httpHealthCheck).toBeUndefined(); |
| 106 | |
| 107 | yield* stack.destroy(); |
| 108 | |
| 109 | const gone = yield* waitUntilGone(created.project, created.healthCheckName); |
| 110 | expect(gone).toEqual("gone"); |
| 111 | }).pipe(logLevel), |
| 112 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 113 | ); |