import { describe, expect, it } from 'vitest'; import { RealtimeEventHub, type RealtimeEvent } from '../src/web/events/index.js'; import { LogBroadcaster } from '../src/web/log-broadcaster.js'; describe('LogBroadcaster realtime bridge', () => { it('publishes each log through the typed event hub', () => { const occurredAt = new Date('2026-08-08T15:00:00.000Z'); const hub = new RealtimeEventHub({ capacity: 10, clock: { now: () => occurredAt }, }); const received: RealtimeEvent[] = []; let recent: unknown; hub.subscribe((event) => received.push(event)); const broadcaster = new LogBroadcaster(hub); broadcaster.push('warn', 'Connection is stale', { attempts: 2 }); broadcaster.recent( { query: {} } as never, { json: (value: unknown) => { recent = value; } } as never, ); expect(received).toEqual([ expect.objectContaining({ type: 'log.created', payload: { level: 'warn', message: 'Connection is stale', data: { attempts: 2 }, }, }), ]); expect(recent).toEqual([ expect.objectContaining({ timestamp: occurredAt.getTime() }), ]); }); });