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

main
ts 59 lines 2.13 KB
Raw
1 import * as Docker from "@alchemy.run/docker";
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 * as Schedule from "effect/Schedule";
7 import { materializeIsolatedProject, removeIsolatedProject } from "../IsolatedProject.ts";
8 import IsolatedProjectService, {
9 SERVICE_EXTERNAL_PORT,
10 project,
11 } from "./fixtures/isolated-project-service.ts";
12 import { ensureDockerSwarm } from "./Runtime.ts";
13
14 const { test } = Test.make({ providers: Docker.providers() });
15
16 // Proof on the local engine that the Docker.Service bun bootstrap boots when
17 // the service's `main` lives in an isolated project (see
18 // test/IsolatedProject.ts) — the bundle `cwd` resolves none of alchemy's
19 // dependencies, so the bootstrap's `@effect/platform-bun` / `alchemy/*`
20 // imports must be bundled by the virtual-entry plugin rather than found from
21 // the project root. With them left external bun dies at module load and the
22 // swarm task never listens.
23 test.provider(
24 "service bundled from an isolated project serves HTTP",
25 (stack) =>
26 Effect.gen(function* () {
27 yield* ensureDockerSwarm;
28 yield* materializeIsolatedProject(project);
29 yield* stack.destroy();
30
31 try {
32 const service = yield* stack.deploy(
33 Effect.gen(function* () {
34 return yield* IsolatedProjectService;
35 }),
36 );
37 expect(service.replicas).toBe(1);
38
39 const base = `http://localhost:${SERVICE_EXTERNAL_PORT}`;
40 const health = yield* HttpClient.get(`${base}/health`).pipe(
41 Effect.flatMap((res) =>
42 res.status === 200
43 ? res.json
44 : Effect.fail(new Error(`/health returned ${res.status}`)),
45 ),
46 Effect.retry({ schedule: Schedule.spaced("2 seconds"), times: 30 }),
47 );
48 expect(health).toEqual({ ok: true });
49
50 yield* stack.destroy();
51 } finally {
52 yield* removeIsolatedProject(project);
53 }
54 }),
55 {
56 tags: ["provider:docker", "provider:docker:service", "local"],
57 timeout: 420_000,
58 },
59 );