import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it, vi } from 'vitest' import { WeKnoraMonitorView } from './WeKnoraMonitor' import type { MonitorTaskPage } from './monitorTasks' const page: MonitorTaskPage = { items: [ { id: 'tp-1', title: '维护手册.pdf', path: '产品/维护', node_id: 'node-1', parent_node_id: 'folder-1', source_id: 's1', source_name: '技术资料', target_scope: 'internal', target_kb: 'test-kb', action: 'update', stage: 'parsing', status: 'attention', detail: 'remote_parse_failed', updated_at: '2026-10-27T02:00:00Z', retry_kind: 'upload', failure_id: '', retry_count: 2, version_id: 'v1', }, { id: 'tp-2', title: '过期资料.pdf', path: '历史', node_id: 'node-2', parent_node_id: 'folder-2', source_id: 's1', source_name: '技术资料', target_scope: 'external', target_kb: 'test-public', action: 'remove', stage: 'finished', status: 'completed', detail: '已从测试库移除;来源文件保留', updated_at: '2026-10-27T02:01:00Z', retry_kind: '', failure_id: '', retry_count: 0, version_id: 'v2', }, ], total: 145, limit: 20, offset: 0, sources: [{ id: 's1', name: '技术资料' }], targets: [], bindings: { internal: '', external: '' }, retryable: 1, } const props = { overview: null, metrics: null, page, loading: false, error: '', message: '', filters: { q: '', source: '', scope: '', target: '', action: '', status: 'active', stage: '', since: '', until: '' }, selected: [], busy: false, canOperate: true, onFilters: vi.fn(), onPage: vi.fn(), onSelection: vi.fn(), onSelectAll: vi.fn(), onRetry: vi.fn(), onDetail: vi.fn(), onRefresh: vi.fn(), } describe('unified monitor', () => { it('shows metric cards before a single server-paginated file table without manual start or lane tabs', () => { const html = renderToStaticMarkup() expect(html).toContain('monitor-metric-grid') expect(html.indexOf('monitor-metric-grid')).toBeLessThan(html.indexOf('

文件处理

')) expect(html.match(/ { const html = renderToStaticMarkup() expect(html).toContain('无法读取运行指标') expect(html).not.toContain('100%') expect(html).toContain('尚未取得服务状态') }) it('keeps removal semantics and does not offer retry for completed rows', () => { const html = renderToStaticMarkup() expect(html).toContain('已从测试库移除;来源文件保留') expect(html).toContain('aria-label="选择维护手册.pdf"') expect(html).not.toContain('aria-label="选择过期资料.pdf"') }) }) describe('target identity and probe attribution', () => { it('labels same-named targets with short id and current/history state', () => { const current = '0c84a098-d3ed-4b82-a165-e6de9691d6a8' const historical = 'sc-ed1f812c4e5fabe817fc6351104938c4' const withTargets = { ...page, items: [ { ...page.items[0], target_kb: current }, { ...page.items[1], target_kb: historical }, ], targets: [ { id: current, name: current, scope: 'internal' }, { id: historical, name: historical, scope: 'internal' }, ], bindings: { internal: current, external: '' }, } const html = renderToStaticMarkup() expect(html).toContain('0c84a098') expect(html).toContain('当前绑定') expect(html).toContain('sc-ed1f8') expect(html).toContain('历史') expect(html).toContain('产品/维护') }) it('shows liveness and the sanitized probe target separately from readiness', () => { const overview = { mode: 'real', simulated: false, observed_at: '2026-11-05T02:00:00Z', host: { cpu_percent: 1, memory_used_bytes: 1, memory_total_bytes: 2, disk_used_bytes: 1, disk_total_bytes: 2, gpu_state: 'none', gpu_detail: '', simulated: false, }, services: [], knowledge_bases: [], health: [ { key: 'weknora', name: 'WeKnora API', liveness: 'up', readiness: 'blocked', reason: 'WeKnora 探测目标知识库不存在(实例 weknora.test · 知识库 1b52c140)', latency_ms: 3, observed_at: '2026-11-05T02:00:00Z', last_success_at: null, consecutive_failures: 1, probe_target: '实例 weknora.test · 知识库 1b52c140', configured: true, applicable: true, }, ], } const html = renderToStaticMarkup() expect(html).toContain('存活 up') expect(html).toContain('探测对象 实例 weknora.test · 知识库 1b52c140') }) })