diff --git a/frontend/src/stores/realtime.spec.ts b/frontend/src/stores/realtime.spec.ts index 9a0a5c5..463e28e 100644 --- a/frontend/src/stores/realtime.spec.ts +++ b/frontend/src/stores/realtime.spec.ts @@ -53,6 +53,22 @@ describe('useRealtimeStore', () => { expect(store.lastStats).toMatchObject({ total_packages: 42, total_size: 1024 }) }) + it('unwraps the server stats_update shape {stats, timestamp}', () => { + const store = useRealtimeStore() + store.ingest( + makeEvent('stats_update', { + stats: { total_packages: 1454, total_size: 980870617, total_downloads: 5376, scanned_packages: 1451 }, + timestamp: '2026-11-23T16:00:00Z', + }), + ) + expect(store.lastStats).toMatchObject({ + total_packages: 1454, + total_size: 980870617, + total_downloads: 5376, + scanned_packages: 1451, + }) + }) + it('exposes filtered computed slices', () => { const store = useRealtimeStore() store.ingest(makeEvent('package_cached')) diff --git a/frontend/src/stores/realtime.ts b/frontend/src/stores/realtime.ts index d46940b..4539dde 100644 --- a/frontend/src/stores/realtime.ts +++ b/frontend/src/stores/realtime.ts @@ -55,7 +55,9 @@ export const useRealtimeStore = defineStore('realtime', () => { events.value.splice(0, events.value.length - EVENTS_CAP) } if (event.type === 'stats_update') { - lastStats.value = event.payload as RealtimeStats + // The server nests the counters under `stats`; reading the payload flat shows zeros. + const nested = event.payload.stats + lastStats.value = (nested && typeof nested === 'object' ? nested : event.payload) as RealtimeStats } }