@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 70 lines 2.32 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 { SECRET_NAME } from "../src/shared.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 fetchOk = (url: string) =>
18 Effect.gen(function* () {
19 const client = yield* HttpClient.HttpClient;
20 return yield* client.get(url).pipe(
21 Effect.flatMap((res) =>
22 res.status === 200 ? Effect.succeed(res) : Effect.fail(new Error(`HTTP ${res.status}`)),
23 ),
24 Effect.retry({
25 // Back off, but keep polling every 3s: a new fly.dev hostname can
26 // take a minute or more to start serving.
27 schedule: Schedule.min([Schedule.exponential("500 millis"), Schedule.spaced("3 seconds")]),
28 times: 35,
29 }),
30 );
31 });
32
33 const stack = beforeAll(deploy(Stack), { timeout: 300_000 });
34
35 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
36 timeout: 180_000,
37 });
38
39 test(
40 "deploys Api + Worker and serves /health over fly.dev",
41 Effect.gen(function* () {
42 const out = yield* stack;
43 expect(out.appName).toBeString();
44 expect(out.apiUrl).toBe(`https://${out.appName}.fly.dev`);
45 expect(out.ip).toBeString();
46 expect(out.secretName).toBe(SECRET_NAME);
47 expect(out.workerMounts[0]?.volumeId).toBeString();
48 expect(out.apiMachineId).not.toBe(out.workerMachineId);
49
50 const health = yield* fetchOk(`${out.apiUrl}/health`);
51 expect(health.status).toBe(200);
52 const body = (yield* health.json) as { ok: boolean; name: string };
53 expect(body.ok).toBe(true);
54 expect(body.name).toBe(SECRET_NAME);
55 }),
56 { timeout: 180_000 },
57 );
58
59 test(
60 "Fly.Secret is injected as env and present on /secret",
61 Effect.gen(function* () {
62 const out = yield* stack;
63 const response = yield* fetchOk(`${out.apiUrl}/secret`);
64 expect(response.status).toBe(200);
65 const body = (yield* response.json) as { ok: boolean; name: string };
66 expect(body.ok).toBe(true);
67 expect(body.name).toBe(SECRET_NAME);
68 }),
69 { timeout: 60_000 },
70 );