import fs from 'node:fs/promises' const url = 'ws://192.168.110.96:8301/ws/deviceStatus' const startedAt = new Date().toISOString() const frames = [] const errors = [] const socket = new WebSocket(url) const finish = async () => { socket.close() const report = { url, startedAt, endedAt: new Date().toISOString(), frames, errors, verdict: frames.some(row => row.frame.type === 'cockpitSubscribed') ? 'subscription-confirmed' : 'subscription-failed', scope: 'Read-only subscription; no authenticate, no business writes; absence of deltas is not a closed-loop verdict.' } await fs.writeFile('.scratch/cockpit-real-data-wayfinding/verify/artifacts/t18/ws-observation.json', JSON.stringify(report, null, 2)) console.log(JSON.stringify(report)) process.exit(report.verdict === 'subscription-confirmed' ? 0 : 1) } socket.addEventListener('open', () => socket.send(JSON.stringify({ type: 'cockpitSubscribe', scope: 'all' }))) socket.addEventListener('message', event => { try { frames.push({ receivedAt: new Date().toISOString(), frame: JSON.parse(String(event.data)) }) } catch { errors.push('non-json-frame') } }) socket.addEventListener('error', () => errors.push('websocket-error')) setTimeout(finish, 75000)