|
| 1 | +#!/usr/bin/env node |
| 2 | +/* Simple smoke test for /chat using DEV_NO_API=1 (offline). */ |
| 3 | +const cp = require('child_process'); |
| 4 | +const fetch = require('node-fetch'); |
| 5 | + |
| 6 | +const PORT = 8790; |
| 7 | + |
| 8 | +function sleep(ms){ return new Promise(r=>setTimeout(r, ms)); } |
| 9 | + |
| 10 | +async function waitForHealth(timeoutMs=5000){ |
| 11 | + const deadline = Date.now() + timeoutMs; |
| 12 | + while (Date.now() < deadline){ |
| 13 | + try { |
| 14 | + const r = await fetch(`http://127.0.0.1:${PORT}/health`); |
| 15 | + if (r.ok) return true; |
| 16 | + } catch {} |
| 17 | + await sleep(150); |
| 18 | + } |
| 19 | + return false; |
| 20 | +} |
| 21 | + |
| 22 | +(async () => { |
| 23 | + const child = cp.spawn(process.execPath, ['backend/index.cjs'], { |
| 24 | + env: { ...process.env, DEV_NO_API: '1', PORT: String(PORT) }, |
| 25 | + stdio: 'ignore' |
| 26 | + }); |
| 27 | + |
| 28 | + try { |
| 29 | + const ok = await waitForHealth(6000); |
| 30 | + if (!ok) throw new Error('API did not become healthy'); |
| 31 | + |
| 32 | + // !help path |
| 33 | + const helpRes = await fetch(`http://127.0.0.1:${PORT}/chat`, { |
| 34 | + method: 'POST', headers: { 'content-type': 'application/json' }, |
| 35 | + body: JSON.stringify({ prompt: '!help' }) |
| 36 | + }); |
| 37 | + if (!helpRes.ok) throw new Error('!help request failed'); |
| 38 | + const helpJson = await helpRes.json(); |
| 39 | + if (!helpJson.output || typeof helpJson.output !== 'string') throw new Error('!help output missing'); |
| 40 | + |
| 41 | + // @aiden path |
| 42 | + const aidenRes = await fetch(`http://127.0.0.1:${PORT}/chat`, { |
| 43 | + method: 'POST', headers: { 'content-type': 'application/json' }, |
| 44 | + body: JSON.stringify({ prompt: '@aiden: ping' }) |
| 45 | + }); |
| 46 | + if (!aidenRes.ok) throw new Error('@aiden request failed'); |
| 47 | + const aidenJson = await aidenRes.json(); |
| 48 | + if (!aidenJson.output || typeof aidenJson.output !== 'string') throw new Error('@aiden output missing'); |
| 49 | + |
| 50 | + process.exit(0); |
| 51 | + } catch (e){ |
| 52 | + console.error(String(e && e.message || e)); |
| 53 | + process.exit(1); |
| 54 | + } finally { |
| 55 | + child.kill('SIGTERM'); |
| 56 | + } |
| 57 | +})(); |
| 58 | + |
0 commit comments