// E2E test: Multi-device IoT command const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3ODIwNTIwNDYsImlhdCI6MTc3OTQ2MDA0NiwidHlwZSI6ImFjY2VzcyIsInVzZXJfaWQiOiJhZG1pbiJ9.dmNrCJsz576eEvNWlXVNP7BdZDEpijJ73pSrcqmTJdE'; const WS_URL = `ws://127.0.0.1:8080/ws/chat?token=${TOKEN}&session_id=test_multi_${Date.now()}`; const ws = new WebSocket(WS_URL); let stage = 0; // 0=multi_iot, 1=query ws.onopen = () => { console.log('Connected\n'); console.log('=== Test 1: Multi-device IoT "打开客厅灯和卧室灯" ==='); ws.send(JSON.stringify({ type: 'message', content: '打开客厅灯和卧室灯', session_id: null, mode: 'text', timestamp: Date.now() })); }; ws.onmessage = (event) => { try { const msg = JSON.parse(event.data); if (msg.type === 'response') { const tag = msg.msg_type === 'action' ? 'ACTION' : 'CHAT'; console.log(`[${tag}] role=${msg.role} "${msg.content.substring(0, 150)}"`); } if (msg.type === 'stream_end') { if (stage === 0) { stage = 1; console.log('\n=== Test 2: Query all devices "看看家里设备状态" ==='); setTimeout(() => { ws.send(JSON.stringify({ type: 'message', content: '看看家里设备状态怎么样', session_id: null, mode: 'text', timestamp: Date.now() })); }, 2000); } else if (stage === 1) { stage = 2; console.log('\n=== Test 3: Multi-device off "帮我把卧室灯和卧室空调都关掉" ==='); setTimeout(() => { ws.send(JSON.stringify({ type: 'message', content: '帮我把卧室灯和卧室空调都关掉', session_id: null, mode: 'text', timestamp: Date.now() })); }, 1500); } else { console.log('\nAll tests done, closing...'); setTimeout(() => ws.close(), 500); } } if (msg.type === 'error') { console.log('ERROR:', msg.error); ws.close(); } } catch (e) {} }; ws.onclose = () => { console.log('Connection closed'); process.exit(0); }; ws.onerror = (err) => { console.error('WS error:', err.message); process.exit(1); }; setTimeout(() => { console.log('Timeout'); ws.close(); process.exit(1); }, 90000);