fix(dashboard): deduplicate realtime log replay
This commit is contained in:
1 parent
e003b0d8b2
commit
89f7376b1b
4 files changed
+49
-9
No files matched your search
@@ -38,4 +38,19 @@ describe('live console state', () => {
|
||||
expect(state.entries.map(({ id }) => id)).toEqual(['3', '4']);
|
||||
expect(state.pendingEntries).toEqual([]);
|
||||
});
|
||||
|
||||
it('deduplicates the same log delivered by the initial snapshot and SSE replay', () => {
|
||||
let state = createLiveConsoleState();
|
||||
state = reduceLiveConsoleState(state, {
|
||||
type: 'append',
|
||||
entry: entry('initial-1', 'info', 'Database initialized'),
|
||||
});
|
||||
state = reduceLiveConsoleState(state, {
|
||||
type: 'append',
|
||||
entry: entry('realtime-1', 'info', 'Database initialized'),
|
||||
});
|
||||
|
||||
expect(state.entries).toHaveLength(1);
|
||||
expect(state.entries[0]?.id).toBe('initial-1');
|
||||
});
|
||||
});
|
||||
@@ -4,12 +4,21 @@ import { LogBroadcaster } from '../src/web/log-broadcaster.js';
|
||||
|
||||
describe('LogBroadcaster realtime bridge', () => {
|
||||
it('publishes each log through the typed event hub', () => {
|
||||
const hub = new RealtimeEventHub({ capacity: 10 });
|
||||
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({
|
||||
@@ -21,5 +30,8 @@ describe('LogBroadcaster realtime bridge', () => {
|
||||
},
|
||||
}),
|
||||
]);
|
||||
expect(recent).toEqual([
|
||||
expect.objectContaining({ timestamp: occurredAt.getTime() }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user