The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Hetzner from "@alchemy.run/hetzner"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as HttpClient from "effect/http/HttpClient"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { materializeIsolatedProject, removeIsolatedProject } from "../IsolatedProject.ts"; |
| 9 | import IsolatedProjectApi, { project } from "./fixtures/isolated-project-service.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: Hetzner.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const hasHetznerCreds = !!process.env.HCLOUD_TOKEN; |
| 16 | |
| 17 | // Live proof that the Hetzner bun bootstrap boots when the service's `main` |
| 18 | // lives in an isolated project (see test/IsolatedProject.ts) — the bundle |
| 19 | // `cwd` resolves none of alchemy's dependencies, so the bootstrap's |
| 20 | // `@effect/platform-bun` / `alchemy/*` imports must be bundled by the |
| 21 | // virtual-entry plugin rather than found from the project root. With them |
| 22 | // left external bun dies at module load under systemd and the port never |
| 23 | // answers. |
| 24 | test.provider.skipIf(!hasHetznerCreds)( |
| 25 | "service bundled from an isolated project serves HTTP", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* materializeIsolatedProject(project); |
| 29 | yield* stack.destroy(); |
| 30 | |
| 31 | try { |
| 32 | const deployed = yield* stack.deploy( |
| 33 | Effect.gen(function* () { |
| 34 | return yield* IsolatedProjectApi; |
| 35 | }), |
| 36 | ); |
| 37 | expect(deployed.url).toBeTruthy(); |
| 38 | |
| 39 | const health = yield* HttpClient.get(new URL("/health", deployed.url!)).pipe( |
| 40 | Effect.flatMap((res) => |
| 41 | res.status === 200 |
| 42 | ? res.json |
| 43 | : Effect.fail(new Error(`/health returned ${res.status}`)), |
| 44 | ), |
| 45 | Effect.retry({ schedule: Schedule.spaced("2 seconds"), times: 20 }), |
| 46 | ); |
| 47 | expect(health).toEqual({ ok: true }); |
| 48 | |
| 49 | yield* stack.destroy(); |
| 50 | } finally { |
| 51 | yield* removeIsolatedProject(project); |
| 52 | } |
| 53 | }).pipe(logLevel), |
| 54 | { |
| 55 | tags: ["provider:hetzner", "provider:hetzner:server", "provider:hetzner:service", "live"], |
| 56 | timeout: 180_000, |
| 57 | exclusive: "hetzner", |
| 58 | }, |
| 59 | ); |