Reference implementation for the Phoenix Architecture. Work in progress.
aicoding.leaflet.pub/
ai
coding
crazy
1/**
2 * Server — Generated Tests
3 *
4 * AUTO-GENERATED by Phoenix VCS
5 * Tests module structure, server health, and Phoenix traceability.
6 */
7
8import { describe, it, expect, afterAll } from 'vitest';
9import { startServer } from '../server.js';
10
11import * as connectionHandling from '../connection-handling.js';
12import * as rooms from '../rooms.js';
13
14describe('Server modules', () => {
15 describe('Connection Handling', () => {
16 it('exports Phoenix traceability metadata', () => {
17 expect(connectionHandling._phoenix).toBeDefined();
18 expect(connectionHandling._phoenix.name).toBe('Connection Handling');
19 expect(connectionHandling._phoenix.risk_tier).toBeTruthy();
20 });
21
22 it('has exported functions', () => {
23 const exports = Object.keys(connectionHandling).filter(k => k !== '_phoenix');
24 expect(exports.length).toBeGreaterThan(0);
25 });
26 });
27
28 describe('Rooms', () => {
29 it('exports Phoenix traceability metadata', () => {
30 expect(rooms._phoenix).toBeDefined();
31 expect(rooms._phoenix.name).toBe('Rooms');
32 expect(rooms._phoenix.risk_tier).toBeTruthy();
33 });
34
35 it('has exported functions', () => {
36 const exports = Object.keys(rooms).filter(k => k !== '_phoenix');
37 expect(exports.length).toBeGreaterThan(0);
38 });
39 });
40
41});
42
43describe('Server server', () => {
44 const instance = startServer(0); // random port
45
46 afterAll(() => new Promise<void>(resolve => instance.server.close(() => resolve())));
47
48 it('GET /health returns 200', async () => {
49 await instance.ready;
50 const res = await fetch(`http://localhost:${instance.port}/health`);
51 expect(res.status).toBe(200);
52 const body = await res.json() as Record<string, unknown>;
53 expect(body.status).toBe('ok');
54 expect(body.service).toBe('Server');
55 });
56
57 it('GET /metrics returns request counts', async () => {
58 await instance.ready;
59 const res = await fetch(`http://localhost:${instance.port}/metrics`);
60 expect(res.status).toBe(200);
61 const body = await res.json() as Record<string, unknown>;
62 expect(typeof body.requests_total).toBe('number');
63 });
64
65 it('GET /modules lists all registered modules', async () => {
66 await instance.ready;
67 const res = await fetch(`http://localhost:${instance.port}/modules`);
68 expect(res.status).toBe(200);
69 const body = await res.json() as Array<Record<string, unknown>>;
70 expect(body.length).toBe(2);
71 });
72
73 it('GET /unknown returns 404', async () => {
74 await instance.ready;
75 const res = await fetch(`http://localhost:${instance.port}/unknown`);
76 expect(res.status).toBe(404);
77 });
78});