The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * `alchemy dev` end-to-end: the zone routes are emulated locally, so the |
| 3 | * single `url` output federates the API across all four Workers exactly |
| 4 | * like the deployed hostname does. |
| 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 | |
| 10 | const root = path.resolve(import.meta.dirname, ".."); |
| 11 | const cli = new DevCli({ root, stage: "dev-cli-test" }); |
| 12 | |
| 13 | afterAll(async () => { |
| 14 | await cli.stop(); |
| 15 | if (!process.env.NO_DESTROY) cli.destroy(); |
| 16 | }, 120_000); |
| 17 | |
| 18 | const json = async (response: Response) => (await response.json()) as any; |
| 19 | |
| 20 | test("one local URL routes each path to its own Worker", async () => { |
| 21 | cli.start(); |
| 22 | const url = await cli.outputUrlWhenReady("url", { tries: 120 }); |
| 23 | |
| 24 | // Unclaimed paths fall through to the custom-domain Worker. |
| 25 | expect((await json(await fetchOk(`${url}/`))).endpoints).toContain("GET /products"); |
| 26 | |
| 27 | // `/admin/*` → Admin (catalog writes). |
| 28 | const put = await fetchOk(`${url}/admin/products/widget`, { |
| 29 | method: "PUT", |
| 30 | headers: { "content-type": "application/json" }, |
| 31 | body: JSON.stringify({ name: "Widget", price: 5 }), |
| 32 | }); |
| 33 | expect(await json(put)).toEqual({ id: "widget", name: "Widget", price: 5 }); |
| 34 | |
| 35 | // `/products*` → Products (catalog reads). |
| 36 | expect(await json(await fetchOk(`${url}/products/widget`))).toEqual({ |
| 37 | id: "widget", |
| 38 | name: "Widget", |
| 39 | price: 5, |
| 40 | }); |
| 41 | |
| 42 | // `/orders*` → Orders (reads the catalog, writes orders). |
| 43 | const order = await json( |
| 44 | await fetchOk(`${url}/orders`, { |
| 45 | method: "POST", |
| 46 | headers: { "content-type": "application/json" }, |
| 47 | body: JSON.stringify({ productId: "widget", quantity: 3 }), |
| 48 | }), |
| 49 | ); |
| 50 | expect(order.total).toBe(15); |
| 51 | expect(await json(await fetchOk(`${url}/orders/${order.id}`))).toEqual(order); |
| 52 | }, 180_000); |