fix(qaops): 点踩问题统一判为不正确
build / build (push) Successful in 1m11s

通过持久来源关联读取最新本地反馈,强制总表有效正确性为否,保留原问答和人工证据。统一列表、详情、指标和两阶段读取的反馈快照,拒绝冲突选择并保留其他字段编辑。已通过完整本地门禁、隔离PG竞态和真实恢复库52条点踩逐条读回、桌面及手机验收;未调用模型或连接源生产库。
This commit is contained in:
姚章浩
2026-10-20 08:18:03 +08:00
parent 87f97a2f9b
commit 2c0bb32183
22 changed files with 403 additions and 35 deletions
+12 -2
View File
@@ -65,16 +65,23 @@ export function QAInlineFields({
{editableFieldKeys.map((field) => {
const value = pending?.field === field ? pending.value : editableFieldValue(record, field)
const rootNotNeeded = field === 'root_cause' && editableFieldValue(record, 'is_correct') === '是'
const downvoteLocked = field === 'is_correct' && record.quality?.feedback_rule === 'downvote-is-incorrect-v1'
return (
<div key={field} data-quality-field={field}>
<label>
<span>{qaColumns.find((c) => c.key === field)!.label}</span>
<select
aria-label={`修改${qaColumns.find((c) => c.key === field)!.label}`}
title="选择后自动保存"
title={downvoteLocked ? '已点踩,是否正确固定为否' : '选择后自动保存'}
value={rootNotNeeded ? '' : value}
disabled={
saving || !!pending || !options || !record.record_origin || !record.quality || rootNotNeeded
saving ||
!!pending ||
!options ||
!record.record_origin ||
!record.quality ||
rootNotNeeded ||
downvoteLocked
}
style={qaFieldColors(field, value || '—')}
onChange={(e) => {
@@ -107,6 +114,9 @@ export function QAInlineFields({
)
})}
</div>
{record.quality?.feedback_rule === 'downvote-is-incorrect-v1' ? (
<p className="qa-inline-save">已点踩,是否正确固定为否</p>
) : null}
{saving || notice ? (
<p className="qa-inline-save" role="status" aria-live="polite">
{saving ? '保存中…' : notice}
+43
View File
@@ -0,0 +1,43 @@
import { expect, it } from 'vitest'
import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { parseQARecord, qaCellValue } from './qaOps'
import { fixtureRecord } from './qaOps.test'
import { fields, qualityFixture } from './qaQuality.fixture'
import { QAInlineFields } from './QAInlineFields'
const downvoted = {
...fixtureRecord,
record_origin: 'dobotai_2_0',
master_fields: { is_correct: '否' },
quality: {
...qualityFixture,
effective_source: 'master-effective-fields-v1',
feedback_rule: 'downvote-is-incorrect-v1',
effective: { ...fields, correctness: 'incorrect' },
},
}
it('accepts the explicit downvote rule while retaining the original positive human evidence', () => {
const row = parseQARecord(downvoted)
expect(qaCellValue(row, 'is_correct')).toBe('否')
expect(row.quality?.latest_review?.fields.correctness).toBe('correct')
})
it('does not accept a fabricated downvote rule or use it to change unrelated human fields', () => {
expect(() => parseQARecord({ ...downvoted, feedback: { asker_value: '', up: 0, down: 0 } })).toThrow()
expect(() => parseQARecord({ ...downvoted, record_origin: undefined })).toThrow()
expect(() => parseQARecord({ ...downvoted, quality: { ...downvoted.quality, feedback_rule: 'unknown' } })).toThrow()
expect(() =>
parseQARecord({
...downvoted,
quality: { ...downvoted.quality, effective: { ...fields, correctness: 'incorrect', coverage: 'uncovered' } },
})
).toThrow()
})
it('explains the fixed negative correctness without restoring the removed review form', () => {
const row = parseQARecord(downvoted)
const html = renderToStaticMarkup(
createElement(QAInlineFields, { record: row, onSaved: () => {}, onReload: () => {} })
)
expect(html).toContain('已点踩,是否正确固定为否')
expect(html).not.toContain('人工复核反馈')
})
+5 -1
View File
@@ -185,7 +185,11 @@ export function parseQARecord(value: unknown): QARecord {
...(row.quality === undefined
? {}
: {
quality: parseQAQuality(row.quality, ['dobotai_2_0', 'historical_excel'].includes(String(row.record_origin))),
quality: parseQAQuality(
row.quality,
['dobotai_2_0', 'historical_excel'].includes(String(row.record_origin)),
askerValue === 'down' || count(feedback.down) > 0
),
}),
id: text(row.id),
status: text(row.status),
+11 -2
View File
@@ -26,6 +26,7 @@ export interface QualityReview {
}
export interface QAQuality {
effective_source?: 'master-effective-fields-v1'
feedback_rule?: 'downvote-is-incorrect-v1'
input_hash: string
input_epoch: number
revision: number
@@ -192,7 +193,7 @@ function review(value: unknown): QualityReview {
created_at: stamp(v.created_at),
}
}
export function parseQAQuality(value: unknown, allowMasterProjection = false): QAQuality {
export function parseQAQuality(value: unknown, allowMasterProjection = false, hasDownvote = false): QAQuality {
const v = obj(value),
state = text(v.state)
if (!['unreviewed', 'reviewed', 'stale'].includes(state)) return bad()
@@ -219,11 +220,18 @@ export function parseQAQuality(value: unknown, allowMasterProjection = false): Q
state === 'reviewed' ? latest_review!.fields : { ...emptyQualityFields, coverage: automatic.result.verdict || '' }
const master = v.effective_source === 'master-effective-fields-v1'
if (v.effective_source !== undefined && (!master || !allowMasterProjection)) return bad()
const downvoteRule = v.feedback_rule === 'downvote-is-incorrect-v1'
if (
v.feedback_rule !== undefined &&
(!downvoteRule || !master || !allowMasterProjection || !hasDownvote || effective.correctness !== 'incorrect')
)
return bad()
for (const key of Object.keys(expected) as (keyof QualityFields)[]) {
// The versioned master layer may fill missing fields, but never change an explicit human decision.
// Only the explicit feedback rule may override correctness; the human evidence stays intact.
if (master) {
if (
state === 'reviewed' &&
!(downvoteRule && key === 'correctness') &&
(expected[key] !== '' || (key === 'root_cause' && expected.correctness === 'correct')) &&
expected[key] !== effective[key]
)
@@ -239,6 +247,7 @@ export function parseQAQuality(value: unknown, allowMasterProjection = false): Q
latest_review,
effective,
...(master ? { effective_source: 'master-effective-fields-v1' as const } : {}),
...(downvoteRule ? { feedback_rule: 'downvote-is-incorrect-v1' as const } : {}),
}
}
function qualityRate(value: unknown): QualityRate {