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

main
ts 38 lines 1.24 KB
Raw
1 /**
2 * `alchemy dev` end-to-end: spawns the real CLI and talks to the Flue app on
3 * its local dev server. The agent's model calls go through `env.AI`, which
4 * dev proxies to Workers AI.
5 */
6 import { afterAll, expect, test } from "bun:test";
7 import * as path from "node:path";
8 import { DevCli, fetchOk } from "@alchemy.run/test/DevCli";
9 import { createFlueClient } from "@flue/sdk";
10
11 const root = path.resolve(import.meta.dirname, "..");
12 const cli = new DevCli({ root, stage: "dev-cli-test" });
13
14 afterAll(async () => {
15 await cli.stop();
16 if (!process.env.NO_DESTROY) {
17 cli.destroy();
18 }
19 }, 180_000);
20
21 test("alchemy dev serves the app and the agent", async () => {
22 cli.destroy();
23 cli.start();
24 const url = (await cli.outputUrlWhenReady("url", { tries: 300, delayMs: 1000 })).replace(
25 /\/$/,
26 "",
27 );
28
29 const ping = await fetchOk(`${url}/api/ping`);
30 expect(await ping.json()).toEqual({ pong: true });
31
32 const client = createFlueClient({ url: `${url}/agents/assistant/dev-${crypto.randomUUID()}` });
33 const admission = await client.send({
34 message: { kind: "user", body: "Reply with the single word PONG and nothing else." },
35 });
36 const reply = await client.read(admission);
37 expect(reply.text.toUpperCase()).toContain("PONG");
38 }, 600_000);