Files
knowledge-governance/web/src/qaCumulativeTrend.test.ts
姚章浩 1580ebd826
build / build (push) Successful in 1m8s
feat(qaops): 增加第40至43周实时累计趋势及受控回填依据
按北京时间各自然周截止对整张统计总表累计计数,字段取当前有效结论。
覆盖和正确各按周报是除以是加否,保留历史上报与冻结并优先展示动态累计。
新增30秒顺序刷新、本地规则和历史复用非模型依据,保护当前原问答与人工字段。

验证:完整make verify通过;隔离PostgreSQL全量mirror race通过;
恢复库与真实周报calc_metrics四点对拍、源点踩自然刷新、桌面/390px及PNG通过。
新增源同步成员变化、人工版本保护及跨策略标签间距回归已通过。
模型全量语义风险审核及正式业务回填尚未完成,未部署本版本。
2026-10-20 11:09:47 +08:00

70 lines
2.8 KiB
TypeScript

import { it, expect } from 'vitest'
import { parseQADashboard } from './qaDashboardData'
import { dashboardFixture } from './qaDashboard.fixture'
import { historicalTrend } from './qaHistoricalTrend'
it('rejects a closed-week cumulative point silently cut short before its required cutoff', () => {
const broken = structuredClone(live)
broken[1].cutoff_at = '2026-10-11T23:59:59+08:00'
expect(() => parseQADashboard({ ...dashboardFixture, cumulative_weeks: broken })).toThrow()
})
const rates = (n: number, d: number) => ({ numerator: n, denominator: d, percent: d ? (100 * n) / d : null })
const live = [
{
week: '2026WK40',
week_start: '2026-09-28T00:00:00+08:00',
week_end: '2026-10-05T00:00:00+08:00',
cutoff_at: '2026-10-05T00:00:00+08:00',
calculated_at: '2026-10-18T10:00:00Z',
records: 2,
coverage: rates(1, 2),
correctness: rates(1, 2),
source: 'master_live_cumulative_v1',
policy_version: 'weekly-strict-yes-over-yes-no-v1',
},
{
week: '2026WK41',
week_start: '2026-10-05T00:00:00+08:00',
week_end: '2026-10-12T00:00:00+08:00',
cutoff_at: '2026-10-12T00:00:00+08:00',
calculated_at: '2026-10-18T10:00:00Z',
records: 3,
coverage: rates(1, 3),
correctness: rates(2, 3),
source: 'master_live_cumulative_v1',
policy_version: 'weekly-strict-yes-over-yes-no-v1',
},
]
it('prioritizes live cumulative weeks over an overlapping report without mutating historical evidence', () => {
const wire = {
...dashboardFixture,
cumulative_weeks: live,
reported_weeks: [
{
week: '2026WK40',
week_start: live[0].week_start,
week_end: live[0].week_end,
coverage_percent: 99,
correctness_percent: 99,
source: 'user_provided_history',
},
],
}
const before = JSON.stringify(wire),
parsed = parseQADashboard(wire)
expect(historicalTrend(parsed, false)[0].source).toBe('master_live_cumulative_v1')
expect(historicalTrend(parsed, false)[0].value).toBe(50)
expect(parsed.reported_weeks[0].coverage_percent).toBe(99)
expect(JSON.stringify(wire)).toBe(before)
})
it('shows current cumulative counts instead of substituting old frozen-week values', () => {
const wire = { ...dashboardFixture, cumulative_weeks: live }
const before = JSON.stringify(wire)
const parsed = parseQADashboard(wire)
expect((parsed as unknown as { cumulative_weeks: unknown[] }).cumulative_weeks).toHaveLength(2)
expect(historicalTrend(parsed, false).map((p) => p.value)).toEqual([50, 100 / 3])
expect(historicalTrend(parsed, true).map((p) => p.value)).toEqual([50, 200 / 3])
expect(historicalTrend(parsed, true)[1].source).toBe('master_live_cumulative_v1')
expect(historicalTrend(parsed, true)[1].hint).toContain('2/3')
expect(JSON.stringify(wire)).toBe(before)
})