-
Notifications
You must be signed in to change notification settings - Fork 584
Expand file tree
/
Copy pathlifecycle.test.ts
More file actions
76 lines (61 loc) · 2.51 KB
/
lifecycle.test.ts
File metadata and controls
76 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Layer 1 — Lifecycle integration tests (no API keys required).
*
* Verifies proxy health, model listing, stats, and 404 handling.
* These tests always run regardless of wallet funding.
*/
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { startTestProxy, stopTestProxy, getTestProxyUrl } from "./setup.js";
describe("ClawRouter proxy lifecycle", () => {
beforeAll(async () => {
await startTestProxy();
});
afterAll(async () => {
await stopTestProxy();
});
it("GET /health returns 200 with status ok and valid wallet address", async () => {
const res = await fetch(`${getTestProxyUrl()}/health`);
expect(res.status).toBe(200);
const body = (await res.json()) as { status: string; wallet: string };
expect(body.status).toBe("ok");
expect(body.wallet).toMatch(/^0x[0-9a-fA-F]{40}$/);
});
it("GET /health?full=true includes balance info", async () => {
const res = await fetch(`${getTestProxyUrl()}/health?full=true`);
expect(res.status).toBe(200);
const body = (await res.json()) as Record<string, unknown>;
expect(body.status).toBe("ok");
// Full health check includes either balance or balanceError
const hasBalanceInfo = "balance" in body || "balanceError" in body;
expect(hasBalanceInfo).toBe(true);
});
it("GET /v1/models returns model list with routing profiles", async () => {
const res = await fetch(`${getTestProxyUrl()}/v1/models`);
expect(res.status).toBe(200);
const body = (await res.json()) as {
object: string;
data: Array<{ id: string; object: string }>;
};
expect(body.object).toBe("list");
expect(body.data.length).toBeGreaterThan(0);
const modelIds = body.data.map((m) => m.id);
// Routing profile models are registered without "blockrun/" prefix in BLOCKRUN_MODELS
expect(modelIds).toContain("auto");
expect(modelIds).toContain("eco");
expect(modelIds).toContain("free");
expect(modelIds).toContain("premium");
});
it("GET /nonexistent returns 404", async () => {
const res = await fetch(`${getTestProxyUrl()}/nonexistent`);
expect(res.status).toBe(404);
const body = (await res.json()) as { error: string };
expect(body.error).toBe("Not found");
});
it("GET /stats returns stats JSON", async () => {
const res = await fetch(`${getTestProxyUrl()}/stats`);
expect(res.status).toBe(200);
const body = (await res.json()) as Record<string, unknown>;
expect(typeof body).toBe("object");
expect(body).not.toBeNull();
});
});