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

main
ts 111 lines 3.62 KB
Raw
1 import { expect } from "bun:test";
2 import * as Railway from "@alchemy.run/railway";
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: Railway.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 schedule: Schedule.exponential("500 millis"),
26 times: 10,
27 }),
28 );
29 });
30
31 const stack = beforeAll(deploy(Stack), { timeout: 480_000 });
32
33 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
34 timeout: 180_000,
35 });
36
37 test(
38 "deploys the full graph and serves /health",
39 Effect.gen(function* () {
40 const out = yield* stack;
41 expect(out.projectId).toBeString();
42 expect(out.environmentId).toBeString();
43 expect(out.stagingId).toBeString();
44 expect(out.stagingName).toBe("staging");
45 expect(out.secretName).toBeString();
46 expect(out.volumeId).toBeString();
47 expect(out.postgresServiceId).toBeString();
48 expect(out.postgresPublic).toBeString();
49 expect(out.mysqlServiceId).toBeString();
50 expect(out.mysqlName).toBeString();
51 expect(out.databaseUrlName).toBe("APP_DATABASE_URL");
52 expect(out.pingUrl).toMatch(/^https:\/\/.+\.up\.railway\.app$/);
53 expect(out.groupId).toBeString();
54 expect(out.redisServiceId).toBeString();
55 expect(out.redisProxy).toContain(":");
56 expect(out.bucketId).toBeString();
57 expect(out.echoUrl).toMatch(/^https:\/\/.+\.up\.railway\.app$/);
58 expect(out.apiUrl).toMatch(/^https:\/\/.+\.up\.railway\.app$/);
59 expect(out.workerServiceId).toBeString();
60 expect(out.workspaceId).toBeString();
61
62 const health = yield* fetchOk(`${out.apiUrl}/health`);
63 expect(health.status).toBe(200);
64 const body = (yield* health.json) as { rows: unknown };
65 expect(body.rows).toBeDefined();
66
67 expect(out.pingUrl).toEqual(expect.any(String));
68 const ping = yield* fetchOk(out.pingUrl!);
69 expect(ping.status).toBe(200);
70 const pingBody = (yield* ping.json) as { rows: unknown };
71 expect(pingBody.rows).toBeDefined();
72 }),
73 { timeout: 180_000 },
74 );
75
76 test(
77 "Variable is injected as env on /secret",
78 Effect.gen(function* () {
79 const out = yield* stack;
80 const response = yield* fetchOk(`${out.apiUrl}/secret`);
81 expect(response.status).toBe(200);
82 const body = (yield* response.json) as { ok: boolean; name: string };
83 expect(body.ok).toBe(true);
84 expect(body.name).toBe(SECRET_NAME);
85 }),
86 { timeout: 60_000 },
87 );
88
89 test(
90 "ReadWriteRedis round-trips a key on /redis",
91 Effect.gen(function* () {
92 const out = yield* stack;
93 const response = yield* fetchOk(`${out.apiUrl}/redis`);
94 expect(response.status).toBe(200);
95 const body = (yield* response.json) as { ok: boolean };
96 expect(body.ok).toBe(true);
97 }),
98 { timeout: 60_000 },
99 );
100
101 test(
102 "Bucket Put/Get/Head/List/Delete on /bucket",
103 Effect.gen(function* () {
104 const out = yield* stack;
105 const response = yield* fetchOk(`${out.apiUrl}/bucket`);
106 expect(response.status).toBe(200);
107 const body = (yield* response.json) as { ok: boolean };
108 expect(body.ok).toBe(true);
109 }),
110 { timeout: 60_000 },
111 );