@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 54 lines 1.72 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
10 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
11 providers: Fly.providers(),
12 state: Alchemy.localState(),
13 profile: process.env.ALCHEMY_PROFILE,
14 });
15
16 const fetchOk = (url: string) =>
17 Effect.gen(function* () {
18 const client = yield* HttpClient.HttpClient;
19 return yield* client.get(url).pipe(
20 Effect.flatMap((res) =>
21 res.status === 200 ? Effect.succeed(res) : Effect.fail(new Error(`HTTP ${res.status}`)),
22 ),
23 Effect.retry({
24 // Back off, but keep polling every 3s: a new fly.dev hostname can
25 // take a minute or more to start serving.
26 schedule: Schedule.min([Schedule.exponential("500 millis"), Schedule.spaced("3 seconds")]),
27 times: 35,
28 }),
29 );
30 });
31
32 const stack = beforeAll(deploy(Stack), { timeout: 180_000 });
33
34 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
35 timeout: 120_000,
36 });
37
38 test(
39 "deploys an effectful Sprite and serves HTTP",
40 Effect.gen(function* () {
41 const out = yield* stack;
42 expect(out.spriteId).toBeString();
43 expect(out.name).toBeString();
44 expect(out.url).toBeString();
45 expect(out.url).toContain("sprites.app");
46 expect(out.urlAuth).toBe("public");
47
48 const health = yield* fetchOk(`${out.url}/health`);
49 expect(health.status).toBe(200);
50 const body = (yield* health.json) as { ok: boolean };
51 expect(body.ok).toBe(true);
52 }),
53 { timeout: 120_000 },
54 );