import { it, expect } from 'vitest' import { renderToStaticMarkup } from 'react-dom/server' import { QAAIWorkbench, QAAIEvidenceView } from './QAAI' import type { AIStatus, AIEvidence } from './qaAITypes' const status: AIStatus = { settings: { revision: 1, base_url: 'https://model.example.invalid/v1', model: 'fixture', key_configured: true, verification: 'verified', checked_at: null, automatic_evaluation: true, automatic_translation: false, storage_ready: true, }, worker_ready: true, queues: [{ kind: 'evaluation', queued: 2, running: 1, retry: 0, failed: 1, paused: 0, succeeded: 2, skipped: 0 }], batches: [], recent_tasks: [], recent_tasks_limited: false, } it('shows open-ended automatic queue counts without fabricating a percentage', () => { const html = renderToStaticMarkup( ) for (const value of ['AI分析', '当前已执行筛选', '后台任务', '排队 2', '执行 1', '失败 1']) expect(html).toContain(value) expect(html).not.toContain('100%') }) it('exposes persistent pause, resume and failed-only retry without claiming completion is success', () => { const batches: AIStatus['batches'] = [ { id: 'active-batch', kind: 'evaluation', state: 'active', total: 2, succeeded: 0, failed: 1, skipped: 0, running: 0, queued: 1, retry: 0, paused: 0, created_at: '2026-10-19T00:00:00Z', }, { id: 'paused-batch', kind: 'translation', state: 'paused', total: 1, succeeded: 0, failed: 0, skipped: 0, running: 0, queued: 0, retry: 0, paused: 1, created_at: '2026-10-19T00:00:00Z', }, ] const html = renderToStaticMarkup() for (const value of ['暂停批次', '恢复批次', '重试失败项', '已结束不代表全部成功', '已发出的请求完成后暂停后续请求']) expect(html).toContain(value) }) it('renders original evidence quotes, actual model/version and applied-versus-skipped provenance', () => { const evidence: AIEvidence = { id: 'w', record_id: 'r', kind: 'evaluation', state: 'succeeded', stage: 'completed', attempt: 1, error_code: '', skip_reason: '', started_at: '2026-10-19T00:00:00Z', updated_at: '2026-10-19T00:00:01Z', input_hash: 'a'.repeat(64), config_revision: 1, prompt_version: 'prompt-fixture-v1', dictionary_version: 'dict-fixture-v1', actual_model: 'actual-fixture-model', result: { fields: { product_category: { value: 'MG400', basis: 'semantic_only', reason: '原问题明确包含型号', quotes: [{ source: 'question', text: 'MG400 怎么连接?', reference_index: 0 }], }, }, }, applied_fields: { product_category: 'MG400' }, skipped_fields: {}, } const html = renderToStaticMarkup() for (const value of [ '字段结论与依据', '原问题明确包含型号', 'MG400 怎么连接?', '仅语义判断', 'actual-fixture-model', 'prompt-fixture-v1', 'dict-fixture-v1', '已回填', ]) expect(html).toContain(value) }) it('uses one AI分析 entry for combined evaluation and Chinese translation', () => { const html = renderToStaticMarkup( ) expect([...html.matchAll(/>AI分析<\/button>/g)]).toHaveLength(1) expect(html).not.toContain('补缺评估') expect(html).not.toContain('补缺中文翻译') })