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

main
ts 51 lines 1.91 KB
Raw
1 import { expect } from "bun:test";
2 import * as Cloudflare from "@alchemy.run/cloudflare";
3 import * as Test from "@alchemy.run/test/Bun";
4 import * as Console from "effect/Console";
5 import * as Effect from "effect/Effect";
6 import Stack from "../alchemy.run.ts";
7 import { checkAssets, checkCallables, checkMcp, checkSchedule } from "./checks.ts";
8
9 // Fresh `workers.dev` URLs transiently 404 while the route propagates.
10 // `Test.getWhenReady` retries until the Worker serves a real response.
11 const { getWhenReady } = Test;
12
13 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
14 providers: Cloudflare.providers(),
15 state: Cloudflare.state(),
16 });
17
18 const stack = beforeAll(deploy(Stack).pipe(Effect.tap(Console.log)), {
19 timeout: 600_000,
20 });
21 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
22
23 const base = Effect.gen(function* () {
24 const { url } = yield* stack;
25 if (!url) throw new Error("expected the site to expose a workers.dev url");
26 const base = String(url).replace(/\/+$/, "");
27 const res = yield* getWhenReady(base);
28 expect(res.status).toBe(200);
29 // `/` is served by static assets, which can answer before the Worker
30 // script has propagated; the agent routes then still return Cloudflare's
31 // 1042 "No Workers script was found". Wait until an agent route answers.
32 const agent = yield* getWhenReady(`${base}/agents/counter/readiness`);
33 expect(agent.status).toBe(200);
34 return base;
35 });
36
37 const check = (run: (url: string) => Promise<void>) =>
38 Effect.gen(function* () {
39 const url = yield* base;
40 yield* Effect.promise(() => run(url));
41 });
42
43 test("serves the client and static assets", check(checkAssets), { timeout: 180_000 });
44
45 test("calls the agent's callables over its WebSocket", check(checkCallables), {
46 timeout: 180_000,
47 });
48
49 test("runs the agent's scheduled callback", check(checkSchedule), { timeout: 180_000 });
50
51 test("serves the MCP agent's tools", check(checkMcp), { timeout: 180_000 });