@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 48 lines 1.51 KB
Raw
1 import { expect } from "@alchemy.run/test";
2 import * as Effect from "effect/Effect";
3 import * as HttpClient from "effect/http/HttpClient";
4 import * as Schedule from "effect/Schedule";
5
6 const readinessSchedule = Schedule.min([
7 Schedule.exponential("500 millis"),
8 Schedule.spaced("3 seconds"),
9 ]);
10
11 /**
12 * Drive the sqlreach probe image: DATABASE_URL is a single rewritten-or-cloud
13 * value, and a TCP connect from inside the container succeeds.
14 */
15 export const expectDatabaseReachable = (
16 baseUrl: string,
17 assertHost: (hostname: string, url: URL) => void,
18 ) =>
19 Effect.gen(function* () {
20 const client = yield* HttpClient.HttpClient;
21 const get = (path: string) =>
22 client.get(new URL(path, baseUrl)).pipe(
23 Effect.flatMap((r) =>
24 r.status !== 200 ? Effect.fail(new Error(`not ready: ${r.status}`)) : r.text,
25 ),
26 Effect.timeout("30 seconds"),
27 Effect.retry({ schedule: readinessSchedule, times: 30 }),
28 );
29
30 const env = JSON.parse(yield* get("/env")) as {
31 DATABASE_URL: string;
32 databaseUrlCount?: number;
33 };
34 const databaseUrl = new URL(env.DATABASE_URL);
35 assertHost(databaseUrl.hostname, databaseUrl);
36 if (env.databaseUrlCount !== undefined) {
37 expect(env.databaseUrlCount).toBe(1);
38 }
39
40 const probe = JSON.parse(yield* get("/probe")) as {
41 ok?: boolean;
42 host?: string;
43 error?: string;
44 };
45 expect(probe.error).toBeUndefined();
46 expect(probe.ok).toBe(true);
47 expect(probe.host).toBe(databaseUrl.hostname);
48 });