Files
knowledge-governance/web/src/qaWeekly.test.ts
T
姚章浩 cb9f0c389f
build / build (push) Successful in 1m10s
feat(qaops): 看板改用自然月质量指标并增加统计口径
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。
自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。

验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。
真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。
没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
2026-10-21 08:48:55 +08:00

112 lines
4.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { renderToStaticMarkup } from 'react-dom/server'
import { createElement } from 'react'
import { QAAnswerMarkdown } from './QAAnswerMarkdown'
import { buildQAWeeklyDraft, weeklyQualitySourceLabel } from './qaWeekly'
it('identifies the calendar-month prefill policy rather than labelling it unknown or weekly', () => {
expect(weeklyQualitySourceLabel('master_live_calendar_month_v1')).toBe('自然月累计质量指标(跨月周按上月)')
expect(weeklyQualitySourceLabel('reported-history')).toBe('历史上报指标')
})
import type { QARecordPage, QAQuery } from './qaOps'
import type { QualitySummary } from './qaQuality'
const query: QAQuery = { start: '2026-10-11T16:00:00Z', end: '2026-10-18T10:00:00Z', keyword: '', cursor: '' }
const page = {
items: [
{
id: 'fixture',
status: 'succeeded',
time_source: 'request_message.created_at',
asker: 'fixture person',
trigger_person: '',
department: '',
region: '',
references: [],
media: [],
source_coverage: { verdict: '', reason_code: '', evaluator_version: '' },
question: '=HYPERLINK("https://example.invalid")',
answer: '暂无已发布',
asked_at: '2026-10-14T00:00:00Z',
coverage: {
verdict: 'uncovered',
state: 'checked',
rule_version: 'governance-answer-substring-v1',
matched_text: '暂无已发布',
},
feedback: { asker_value: '', up: 0, down: 0 },
},
],
columns: [],
total: 1,
has_more: false,
next_cursor: '',
as_of: query.end,
local_revision: 1,
} as QARecordPage
const quality = {
start: query.start,
end: query.end,
keyword: '',
as_of: query.end,
scope: 'whole_filter',
ai_state: 'not_configured',
summary: {
total: 1,
reviewed: 0,
unreviewed: 1,
stale: 0,
pending_confirmation: 0,
rule_uncovered: 1,
rates: {
policy_version: 'quality-rates-human-first-v1',
coverage: { numerator: 0, denominator: 1, percent: 0 },
correctness: { numerator: 0, denominator: 0, percent: null },
breakdown: {
covered: 0,
uncovered: 1,
partial: 0,
pending: 0,
unassessed: 0,
excluded: 0,
stale: 0,
covered_correct: 0,
covered_incorrect: 0,
covered_pending: 0,
covered_unassessed: 0,
},
},
},
} as QualitySummary
describe('weekly draft export', () => {
it('builds preview and downloadable evidence from the same complete query without invented correctness', () => {
const d = buildQAWeeklyDraft(page, query, quality, '2026-10-18T10:00:00Z')
expect(d.questions).toBe(1)
expect(d.revision).toBe(1)
expect(d.markdown).toContain('周报(草稿)')
expect(d.markdown).toContain('正确率:—')
expect(renderToStaticMarkup(createElement(QAAnswerMarkdown, { answer: d.markdown }))).toContain('<table')
expect(d.csv.charCodeAt(0)).toBe(0xfeff)
expect(d.markdown.split(String.fromCharCode(10)).length).toBeGreaterThan(10)
expect(d.csv.split(String.fromCharCode(13, 10)).length).toBe(2)
expect(d.csv).toContain('原始问题')
expect(d.csv).toContain("'=HYPERLINK")
})
it('escapes source question Markdown and line breaks rather than injecting a report link or row', () => {
const input = {
...page,
items: page.items.map((r) => ({
...r,
question: '中文 [链接](https://example.invalid) **危险**' + String.fromCharCode(10) + '第二行',
})),
}
const d = buildQAWeeklyDraft(input, query, quality, query.end)
const html = renderToStaticMarkup(createElement(QAAnswerMarkdown, { answer: d.markdown }))
expect(html).not.toContain('>链接</a>')
expect(html).not.toContain('<strong>危险</strong>')
expect(d.markdown).not.toContain(String.fromCharCode(10) + '第二行')
})
it('refuses incomplete ranges or statistics from another scope', () => {
expect(() => buildQAWeeklyDraft({ ...page, has_more: true }, query, quality, query.end)).toThrow()
expect(() => buildQAWeeklyDraft(page, query, { ...quality, keyword: 'other' }, query.end)).toThrow()
})
})