// Smoke test: join the game, verify snapshots flow, movement works, // boosting drains score, and steering toward the border kills us. import WebSocket from 'ws'; const ws = new WebSocket('ws://localhost:8080/ws'); let init = null; let snaps = 0; let firstHead = null; let lastHead = null; let maxScore = 0; let died = false; let respawned = false; let phase = 0; ws.on('open', () => ws.send(JSON.stringify({ t: 'join', name: 'SmokeTest' }))); ws.on('message', (d) => { const m = JSON.parse(d); if (m.t === 'init') { init = m; console.log(`[init] id=${m.id} arena=${m.arena} pellets=${m.pellets.length}`); ws.send(JSON.stringify({ t: 'in', a: 0, b: false })); return; } if (m.t !== 'snap') return; snaps++; const me = m.snakes.find((s) => s.id === init.id); if (me) { lastHead = [me.p[0], me.p[1]]; if (!firstHead) firstHead = [...lastHead]; maxScore = Math.max(maxScore, m.you.score); } if (snaps === 30) { const moved = Math.hypot(lastHead[0] - firstHead[0], lastHead[1] - firstHead[1]); console.log(`[move] head moved ${moved.toFixed(1)}px over ~2s (${m.snakes.length} snakes, lb=${m.lb.length}, total=${m.total})`); if (moved < 50) fail('snake did not move'); // start boosting toward the border to test boost drain + border death phase = 1; ws.send(JSON.stringify({ t: 'in', a: Math.atan2(lastHead[1], lastHead[0]), b: true })); } for (const ev of m.ev) { if (ev.t === 'die' && ev.id === init.id && !died) { died = true; console.log(`[death] died as expected (score=${ev.s}, pellets sample pts=${ev.p.length / 2})`); ws.send(JSON.stringify({ t: 'respawn' })); } } if (died && me && m.you.alive && !respawned) { respawned = true; console.log(`[respawn] instant respawn OK, alive with score=${m.you.score}`); console.log('SMOKE TEST PASSED'); process.exit(0); } if (snaps === 150 && phase === 1) { console.log(`[boost] max score observed while boosting: ${maxScore}`); } }); function fail(msg) { console.error('SMOKE TEST FAILED: ' + msg); process.exit(1); } setTimeout(() => fail(`timeout (snaps=${snaps}, died=${died}, respawned=${respawned})`), 90000);