feat(web): add WebSocket transport for message event streaming with SSE fallback (#764)
* feat: add websocket message stream transport * fix: avoid false missing session directories in sidebar * fix: re-probe project root session directories * refactor: use button group for message stream transport * fix: resolve chat input hook dependency warning --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
fd8972a7d9
commit
bee9d19f3a
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
|
||||
import { createGlobalUiEventBroadcaster } from './runtime.js';
|
||||
|
||||
describe('event stream broadcaster', () => {
|
||||
it('fans out synthetic events to SSE and WS clients', () => {
|
||||
const sseEvents = [];
|
||||
const wsPayloads = [];
|
||||
const sseClient = { id: 'sse-1' };
|
||||
const wsClient = {
|
||||
readyState: 1,
|
||||
send(payload) {
|
||||
wsPayloads.push(JSON.parse(payload));
|
||||
},
|
||||
};
|
||||
|
||||
const broadcast = createGlobalUiEventBroadcaster({
|
||||
sseClients: new Set([sseClient]),
|
||||
wsClients: new Set([wsClient]),
|
||||
writeSseEvent(res, payload) {
|
||||
sseEvents.push({ res, payload });
|
||||
},
|
||||
});
|
||||
|
||||
broadcast({ type: 'openchamber:session-status' }, { eventId: 'evt-1', directory: '/tmp/project' });
|
||||
|
||||
expect(sseEvents).toEqual([
|
||||
{
|
||||
res: sseClient,
|
||||
payload: { type: 'openchamber:session-status' },
|
||||
},
|
||||
]);
|
||||
expect(wsPayloads).toEqual([
|
||||
{
|
||||
type: 'event',
|
||||
payload: { type: 'openchamber:session-status' },
|
||||
eventId: 'evt-1',
|
||||
directory: '/tmp/project',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('removes websocket clients that fail to receive a payload', () => {
|
||||
const wsClients = new Set([
|
||||
{
|
||||
readyState: 1,
|
||||
send() {
|
||||
throw new Error('socket write failed');
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const broadcast = createGlobalUiEventBroadcaster({
|
||||
sseClients: new Set(),
|
||||
wsClients,
|
||||
writeSseEvent() {
|
||||
throw new Error('should not be called');
|
||||
},
|
||||
});
|
||||
|
||||
broadcast({ type: 'openchamber:notification' });
|
||||
|
||||
expect(wsClients.size).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user