t18-ws-observe.mjs 1.2 KB

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