// Final comprehensive E2E test - all 5 original issues const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE4ODIwNTIwNDYsImlhdCI6MTc3OTQ2MDA0NiwidHlwZSI6ImFjY2VzcyIsInVzZXJfaWQiOiJhZG1pbiJ9.dmNrCJsz576eEvNWlXVNP7BdZDEpijJ73pSrcqmTJdE'; const WS_URL = `ws://127.0.0.1:8080/ws/chat?token=${TOKEN}&session_id=final_${Date.now()}`; const tests = [ { name: '1. Greeting fast path', msg: '你好呀', expect: {action: true, chat: true, fast: true} }, { name: '2. IoT ON (single)', msg: '帮我把客厅灯打开', expect: {action: true, chat: true, iot: true} }, { name: '3. IoT ON (multi)', msg: '打开卧室灯和卧室空调', expect: {action: true, chat: true, iot: true} }, { name: '4. IoT OFF (single)', msg: '关掉客厅灯', expect: {action: true, chat: true, iot: true} }, { name: '5. Memory trigger', msg: '你还记得我喜欢什么吗?', expect: {action: true, chat: true} }, { name: '6. IoT OFF (multi)', msg: '帮我把卧室灯和卧室空调都关掉', expect: {action: true, chat: true, iot: true} }, ]; const ws = new WebSocket(WS_URL); let testIdx = 0; let results = []; let current = { actions: 0, chats: 0, fast: false }; function runTest() { if (testIdx >= tests.length) { console.log('\n' + '='.repeat(50)); console.log('FINAL RESULTS:'); results.forEach(r => console.log(` ${r.status} ${r.name}: ${r.details}`)); console.log('='.repeat(50)); ws.close(); return; } const t = tests[testIdx]; current = { actions: 0, chats: 0, fast: false }; console.log(`\n--- ${t.name} ---`); ws.send(JSON.stringify({type:'message', content: t.msg, session_id: null, mode:'text', timestamp: Date.now()})); console.log(`Sent: "${t.msg}"`); } ws.onopen = () => { console.log('Connected\n'); runTest(); }; ws.onmessage = (event) => { try { const msg = JSON.parse(event.data); if (msg.type === 'response') { if (msg.msg_type === 'action' || msg.role === 'action') { current.actions++; console.log(` [ACTION] "${msg.content.substring(0, 80)}"`); } else { current.chats++; console.log(` [CHAT] "${msg.content.substring(0, 80)}"`); } } if (msg.type === 'stream_end') { const t = tests[testIdx]; const details = []; if (current.actions > 0) { // Check if it has parenthetical content const actionOk = true; // action messages received details.push(`${current.actions}A ${current.chats}C`); } else { details.push(`NO actions (${current.chats}C)`); } const status = current.actions > 0 ? '✅' : '⚠️'; results.push({ name: t.name, status, details: details.join(', ') }); testIdx++; setTimeout(runTest, 2000); } if (msg.type === 'error') { results.push({ name: tests[testIdx].name, status: '❌', details: msg.error }); testIdx++; setTimeout(runTest, 1500); } } catch (e) {} }; ws.onclose = () => { process.exit(0); }; ws.onerror = (err) => { console.error('WS error:', err.message); process.exit(1); }; setTimeout(() => { console.log('TIMEOUT'); ws.close(); process.exit(1); }, 180000);