// @ts-expect-error The test runner provides Node; the browser bundle intentionally omits @types/node.
import { readFileSync } from 'node:fs'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { QAOperationsTabs, QAOperationsView } from './QAOperations'
import type { QARecord, QARecordPage } from './qaOps'
import { restoreWorkspace } from './workspace'
const item: QARecord = {
id: 'fixture',
status: 'succeeded',
question: '',
answer: '当前暂无已发布的权威知识。',
asked_at: '2026-10-14T03:00:00Z',
time_source: 'request_message.created_at',
asker: '测试人员',
trigger_person: '测试昵称',
department: '',
region: '',
references: [{ title: '测试引用' }],
media: [],
feedback: { asker_value: 'down', up: 0, down: 1 },
source_coverage: { verdict: 'covered', reason_code: 'covered_has_references', evaluator_version: 'v5' },
coverage: {
verdict: 'uncovered',
state: 'checked',
rule_version: 'governance-answer-substring-v1',
matched_text: '暂无已发布',
},
is_correct: false,
}
const page: QARecordPage = {
items: [item],
columns: ['answer', 'coverage', 'is_correct', 'asked_at', 'asker', 'question', 'feedback'],
total: 1,
has_more: false,
next_cursor: '',
as_of: '2026-10-14T04:00:00Z',
}
const props = {
page,
status: null,
loading: false,
error: null,
detail: null,
detailLoading: false,
detailError: null,
onSelect: vi.fn(),
onCloseDetail: vi.fn(),
onLoadMore: vi.fn(),
onRetry: vi.fn(),
}
describe('QA operations workbench', () => {
it('shows each persisted AI task in the existing operation cell and explains positive master coverage', () => {
const withTasks = {
...item,
background_tasks: [
{
id: 'w',
record_id: item.id,
kind: 'evaluation' as const,
state: 'running' as const,
stage: 'request',
attempt: 1,
error_code: '',
skip_reason: '',
started_at: '2026-10-19T00:00:00Z',
updated_at: '2026-10-19T00:00:01Z',
},
],
}
const detail = {
...item,
record_origin: 'dobotai_2_0' as const,
coverage: { state: 'checked' as const, verdict: 'covered' as const, rule_version: 'master-answer-substring-v2' },
}
const html = renderToStaticMarkup(
)
expect(html).toContain('字段分析:执行中')
expect(html).toContain('已覆盖:成功读取且非空答案未包含')
expect(html).toContain('字段结论与依据')
})
it('hides only the two requested advisory warnings, not real errors', () => {
const html = renderToStaticMarkup(
)
expect(html).not.toContain('数据库仍允许临时对象')
expect(html).not.toContain('数据库连接未启用 TLS')
expect(html).toContain('数据源有待审核的安全告警')
expect(html).toContain('fixture real read failure')
})
it('removes workflow personnel from details while preserving the record data', () => {
const detail = { ...item, trigger_person: JSON.stringify({ name: '示例姓名', unionId: 'fixture-union' }) }
const html = renderToStaticMarkup()
const drawer = html.slice(html.indexOf('