2c0bb32183
build / build (push) Successful in 1m11s
通过持久来源关联读取最新本地反馈,强制总表有效正确性为否,保留原问答和人工证据。统一列表、详情、指标和两阶段读取的反馈快照,拒绝冲突选择并保留其他字段编辑。已通过完整本地门禁、隔离PG竞态和真实恢复库52条点踩逐条读回、桌面及手机验收;未调用模型或连接源生产库。
54 lines
2.4 KiB
Go
54 lines
2.4 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"knowledge-governance/internal/dobotaiops"
|
|
"knowledge-governance/internal/qaopsquality"
|
|
"testing"
|
|
)
|
|
|
|
type downvoteSnapshotReader struct {
|
|
QAOpsReader
|
|
view qaopsquality.View
|
|
}
|
|
|
|
func (s downvoteSnapshotReader) ReadStoredQuality(context.Context, []dobotaiops.QualityKey) (map[string]qaopsquality.View, error) {
|
|
return map[string]qaopsquality.View{"fixture-feedback-race": s.view}, nil
|
|
}
|
|
|
|
func TestMasterQualityEnrichmentUsesOneFeedbackDecisionEvenWhenVoteChangesBetweenReads(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
old, current dobotaiops.RecordFeedback
|
|
label, correctness, rule string
|
|
}{
|
|
{"new-downvote", dobotaiops.RecordFeedback{}, dobotaiops.RecordFeedback{Down: 1}, "否", "incorrect", "downvote-is-incorrect-v1"},
|
|
{"withdrawn-current-vote", dobotaiops.RecordFeedback{Down: 1}, dobotaiops.RecordFeedback{}, "是", "correct", ""},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
view := qaopsquality.View{EffectiveSource: "master-effective-fields-v1", FeedbackRule: test.rule, Effective: qaopsquality.Fields{Correctness: test.correctness}, MasterFeedback: &test.current}
|
|
c := Config{QAOps: downvoteSnapshotReader{view: view}, QAQuality: &qualityFake{}}
|
|
item := dobotaiops.Record{ID: "fixture-feedback-race", RecordOrigin: "dobotai_2_0", Feedback: test.old, MasterFields: map[string]string{"is_correct": "待确认"}}
|
|
if err := enrichQAQualityRecord(context.Background(), c, &item); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if item.Feedback != test.current || item.MasterFields["is_correct"] != test.label {
|
|
t.Fatal("detail combines an old feedback snapshot with a newer quality decision")
|
|
}
|
|
page := dobotaiops.RecordPage{Items: []dobotaiops.Record{{ID: item.ID, RecordOrigin: item.RecordOrigin, Feedback: test.old, MasterFields: map[string]string{"is_correct": "待确认"}}}}
|
|
// The common projection must be shared by the list and detail enrichment paths.
|
|
if err := enrichQAQualityPage(context.Background(), c, &page); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if page.Items[0].Feedback != test.current || page.Items[0].MasterFields["is_correct"] != test.label {
|
|
t.Fatal("list combines an old feedback snapshot with a newer quality decision")
|
|
}
|
|
var quality map[string]any
|
|
if json.Unmarshal(item.Quality, &quality) != nil {
|
|
t.Fatal("quality response missing")
|
|
}
|
|
})
|
|
}
|
|
}
|