@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, 06:00 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: 300_000 });
33
34 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
35 timeout: 180_000,
36 });
37
38 test(
39 "attaches Redis and PING's it from the Service",
40 Effect.gen(function* () {
41 const out = yield* stack;
42 expect(out.redisId).toBeString();
43 expect(out.apiUrl).toBe(`https://${out.appName}.fly.dev`);
44
45 const health = yield* fetchOk(`${out.apiUrl}/health`);
46 expect(health.status).toBe(200);
47
48 const ping = yield* fetchOk(`${out.apiUrl}/`);
49 expect(ping.status).toBe(200);
50 const body = (yield* ping.json) as { pong: boolean };
51 expect(body.pong).toBe(true);
52 }),
53 { timeout: 180_000 },
54 );