feat(qa-ops): 建立独立正式主表并保真导入历史问答
build / build (push) Successful in 1m7s

将可维护总表与可替换2.0镜像分离,稳定来源关联和原始事件键保留;
源端更新/删除不覆盖主表或人工复核。首次收录保留原评估审计,
主表输入/复核独立持久化;历史原标注不冒充新AI或冻结证据。

历史导入绑定源哈希、逐行批准清单与真实恢复备份;三字段精确去重,
批次及原字段留档,重复执行不覆盖后续修改。仅操作本地治理库。

验证:完整make verify退出0;镜像与区域两组隔离PG race退出0;
真实恢复数据隔离导入12522、跳过792、暂缓1,总表15050;
重放保留模拟修改,结构down拒绝丢历史;真实浏览器第41周551条完整,
历史原标注和独立主表复核读回通过,移动布局及JS异常0。
This commit is contained in:
姚章浩
2026-10-19 08:49:18 +08:00
parent 6e67034fbd
commit f5e0f8d20f
22 changed files with 1350 additions and 41 deletions
+38
View File
@@ -0,0 +1,38 @@
import { afterEach, expect, it, vi } from 'vitest'
import { fetchQARecords, parseQARecord, qaCellValue } from './qaOps'
import { fixtureRecord } from './qaOps.test'
afterEach(() => vi.unstubAllGlobals())
it('keeps imported historical labels and genuine missing values instead of replacing them with new rule labels', () => {
const raw = {
...fixtureRecord,
record_origin: 'historical_excel',
master_fields: {
question_chinese: '',
coverage: '是',
is_correct: '待确认',
product_category: '原分类',
problem_type: '',
root_cause: '',
language: 'en',
},
}
const item = parseQARecord(raw)
expect(qaCellValue(item, 'coverage')).toBe('是')
expect(qaCellValue(item, 'is_correct')).toBe('待确认')
expect(qaCellValue(item, 'question_chinese')).toBeNull()
expect(qaCellValue(item, 'product_category')).toBe('原分类')
for (const bad of [null, [], { coverage: 123 }, { unapproved: 'x' }])
expect(() => parseQARecord({ ...raw, master_fields: bad })).toThrow('响应无效')
})
it('selects the durable master explicitly and leaves original 2.0 callers on their existing dataset', async () => {
const page = { items: [], columns: [], total: 0, has_more: false, next_cursor: '', as_of: '2026-10-19T00:00:00Z' }
const mocked = vi
.fn()
.mockImplementation(() => Promise.resolve(new Response(JSON.stringify({ data: page }), { status: 200 })))
vi.stubGlobal('fetch', mocked)
const query = { start: '2026-10-05T00:00:00Z', end: '2026-10-12T00:00:00Z', keyword: '', cursor: '' }
await fetchQARecords({ ...query, dataset: 'master' } as Parameters<typeof fetchQARecords>[0])
await fetchQARecords(query)
expect(String(mocked.mock.calls[0][0])).toContain('/api/v1/qa-ops/master/records?')
expect(String(mocked.mock.calls[1][0])).toContain('/api/v1/qa-ops/records?')
})