import test from 'node:test'; import assert from 'node:assert/strict'; import { memoryStatus } from '../src/pages/memory-status.ts'; const synced = { memory_revision: 27, viking_visible_revision: 27, privacy_epoch: 0, sync_state: 'IN_SYNC', critical_backlog: false, pending_count: 0, blocked_count: 0, upload_pending_count: 0, extracting_count: 0, synced_call_count: 27, insufficient_transcript_count: 0, }; const ready = { hasRecords: true, readState: 'ready', statusFailed: false }; test('uploads and extraction remain visible even after memory projection has completed', () => { const result = memoryStatus({ ...synced, sync_state: 'LAGGING_NORMAL', upload_pending_count: 2, extracting_count: 3, insufficient_transcript_count: 4 }, ready); assert.match(result.label, /正在上传 2 通聊天/); assert.match(result.label, /等待提取 3 通聊天/); assert.doesNotMatch(result.label, /已同步/); assert.equal(result.note, '4通聊天文字不足,未生成总结'); }); test('pending projections and lagging states never appear as synchronized', () => { assert.match(memoryStatus({ ...synced, pending_count: 2 }, ready).label, /正在同步 2 项记忆/); assert.match(memoryStatus({ ...synced, sync_state: 'LAGGING_NORMAL' }, ready).label, /仍在同步/); for (const patch of [{ sync_state: 'LAGGING_CRITICAL' }, { critical_backlog: true }, { blocked_count: 1 }, { error_code: 'VIKING_RETRIEVAL_FAILED' }]) { assert.match(memoryStatus({ ...synced, ...patch }, ready).label, /同步异常/); } }); test('failed reads override stale successful status', () => { assert.match(memoryStatus(synced, { ...ready, statusFailed: true }).label, /状态读取失败/); assert.match(memoryStatus(synced, { ...ready, readState: 'error' }).label, /记忆读取失败/); assert.match(memoryStatus(undefined, { ...ready, readState: 'loading' }).label, /正在读取/); assert.match(memoryStatus(synced, { ...ready, readState: 'loading' }).label, /正在读取/); }); test('empty records are distinct from synchronized records and unknown status', () => { assert.equal(memoryStatus(synced, ready).label, '✓ 记忆已同步'); assert.equal(memoryStatus({ ...synced, sync_state: 'EMPTY', insufficient_transcript_count: 2 }, { ...ready, hasRecords: false }).label, '暂无记忆'); assert.match(memoryStatus({ ...synced, sync_state: 'UNRECOGNIZED' }, ready).label, /待确认/); assert.equal(memoryStatus({ ...synced, insufficient_transcript_count: 2 }, ready).note, '2通聊天文字不足,未生成总结'); });