// Smoke test for the UI server: bundle mode serves /index.html, // disk mode serves /app.js, /_ui/overview returns structured JSON. // Run with: deno run --allow-all test/ui-server.smoke.ts import { UiServer } from '../ts/ui/server.ts'; import { ContainerManager } from '../ts/containers/container-manager.ts'; import { ClusterManager } from '../ts/cluster/cluster-manager.ts'; async function probe(source: 'bundle' | 'disk', port: number): Promise { const cm = new ContainerManager(); const cluster = new ClusterManager(); cluster.configure({ enabled: false, nodeName: 'test-node', role: 'standalone', bindHost: '127.0.0.1', gossipPort: 7946, heartbeatIntervalMs: 5000, seedNodes: [], }); const server = new UiServer( { enabled: true, port, host: '127.0.0.1', assetSource: source }, cm, cluster, ); await server.start(); try { const index = await fetch(`http://127.0.0.1:${port}/`); const indexBody = await index.text(); if (!index.ok || !indexBody.includes('ModelGrid')) { throw new Error(`[${source}] index.html missing expected content (status=${index.status})`); } const app = await fetch(`http://127.0.0.1:${port}/app.js`); const appBody = await app.text(); if (!app.ok || !appBody.includes('ModelGrid UI')) { throw new Error(`[${source}] app.js missing expected content (status=${app.status})`); } const spa = await fetch(`http://127.0.0.1:${port}/cluster/nodes`); const spaBody = await spa.text(); if (!spa.ok || !spaBody.includes('ModelGrid')) { throw new Error(`[${source}] SPA fallback did not return index.html (status=${spa.status})`); } const overview = await fetch(`http://127.0.0.1:${port}/_ui/overview`); const data = await overview.json(); if (!overview.ok || data.node?.name !== 'test-node' || !data.health?.status) { throw new Error(`[${source}] /_ui/overview unexpected: ${JSON.stringify(data)}`); } const missing = await fetch(`http://127.0.0.1:${port}/nope.png`); if (missing.status !== 404) { throw new Error(`[${source}] expected 404 for missing asset, got ${missing.status}`); } console.log(`ok: ${source} mode — index, app.js, SPA fallback, /_ui/overview, 404`); } finally { await server.stop(); } } await probe('bundle', 18081); await probe('disk', 18082); console.log('UI server smoke test passed');