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

main
ts 53 lines 1.81 KB
Raw
1 import { expect } from "bun:test";
2 import * as Fly from "@alchemy.run/fly";
3 import * as Test from "@alchemy.run/test/Bun";
4 import * as Alchemy from "alchemy";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Schedule from "effect/Schedule";
8 import Stack from "../alchemy.run.ts";
9 import { USERS } from "../src/users.ts";
10
11 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
12 providers: Fly.providers(),
13 state: Alchemy.localState(),
14 profile: process.env.ALCHEMY_PROFILE,
15 });
16
17 const getJson = (url: string) =>
18 HttpClient.get(url).pipe(
19 Effect.flatMap((res) =>
20 res.status === 200 ? res.json : Effect.fail(new Error(`HTTP ${res.status}`)),
21 ),
22 Effect.retry({
23 // Back off, but keep polling every 3s: a new fly.dev hostname can take
24 // a minute or more to start serving.
25 schedule: Schedule.min([Schedule.exponential("500 millis"), Schedule.spaced("3 seconds")]),
26 times: 35,
27 }),
28 );
29
30 const stack = beforeAll(deploy(Stack), { timeout: 400_000 });
31
32 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
33 timeout: 240_000,
34 });
35
36 test(
37 "the public gateway reaches private Services over the stack network",
38 Effect.gen(function* () {
39 const out = yield* stack;
40 expect(out.url).toMatch(/^https:\/\/.+\.fly\.dev$/);
41 expect(out.usersUrl).toBeUndefined();
42 expect(out.usersPrivateUrl).toMatch(/^http:\/\/.+\.flycast$/);
43 expect(out.ordersPrivateUrl).toMatch(/^http:\/\/.+\.flycast$/);
44 expect(out.network).toBeString();
45
46 expect((yield* getJson(`${out.url}/users`)) as unknown).toEqual(USERS);
47 const orders = (yield* getJson(`${out.url}/orders`)) as Array<{
48 user: { name: string };
49 }>;
50 expect(orders.map((order) => order.user.name)).toEqual(["Ada", "Grace"]);
51 }),
52 { timeout: 240_000 },
53 );