修正筛选入口位置:五项条件在表头就地选择,保持完整集筛选与无感续载。 统一固定规则:未覆盖一律待确认,原问答/人工模型证据不改写,已覆盖仍保留点踩优先。 验证:行为红绿、前端/Go全套及隔离PostgreSQL全mirror竞态通过;完整本地门禁与原生备份真实恢复通过。
This commit is contained in:
@@ -97,7 +97,7 @@ func TestAICoveredPendingReassessmentUsesAuditedOverrideAndPreservesOriginal(t *
|
||||
t.Fatal("original Q&A or imported fields changed")
|
||||
}
|
||||
var count int
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*)FROM qa_ops_master_field_edits WHERE tenant_key=$1 AND record_id=$2 AND actor='system:qa-correctness-v2' AND changed_fields='{"is_correct":"是"}'::jsonb AND before_fields='{"is_correct":"待确认"}'::jsonb`, tenant, entry.Key.ID).Scan(&count); err != nil || count != 1 {
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*)FROM qa_ops_master_field_edits WHERE tenant_key=$1 AND record_id=$2 AND actor='system:qa-correctness-v2' AND changed_fields='{"is_correct":"是"}'::jsonb AND before_fields='{"is_correct":""}'::jsonb`, tenant, entry.Key.ID).Scan(&count); err != nil || count != 1 {
|
||||
t.Fatal("missing reassessment audit", err)
|
||||
}
|
||||
replay, err := ai.Start(ctx, preview.ID, strings.Repeat("r", 24), "fixture-admin")
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestDashboardUsesLifetimeWeekMonthAndDeduplicatedRegionalRoster(t *testing.
|
||||
t.Fatal(e)
|
||||
}
|
||||
current := latest[record.ID]
|
||||
if _, e = quality.Save(ctx, record, qaopsquality.SaveRequest{InputHash: current.InputHash, InputEpoch: current.InputEpoch, BaseRevision: current.Revision, Nonce: strings.Repeat("e", 32), Fields: qaopsquality.Fields{Coverage: "uncovered", Correctness: "incorrect"}, Reason: "later isolated correction, must not rewrite frozen history"}, "fixture-admin"); e != nil {
|
||||
if _, e = quality.Save(ctx, record, qaopsquality.SaveRequest{InputHash: current.InputHash, InputEpoch: current.InputEpoch, BaseRevision: current.Revision, Nonce: strings.Repeat("e", 32), Fields: qaopsquality.Fields{Coverage: "uncovered", Correctness: "pending"}, Reason: "later isolated correction, must not rewrite frozen history"}, "fixture-admin"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
repeated, e := s.FreezePreviousQualityWeek(ctx, freezeAt.Add(time.Minute))
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestMasterLiveCumulativeWeeksUseWholeLedgerAndWeeklyStrictRates(t *testing.
|
||||
if !ok || len(points) != 4 {
|
||||
t.Fatal("missing current master cumulative W40-W43; frozen snapshots are not a substitute")
|
||||
}
|
||||
expected := [][5]float64{{2, 2, 2, 1, 2}, {3, 2, 3, 2, 3}, {4, 2, 3, 2, 4}, {5, 3, 4, 2, 4}}
|
||||
expected := [][5]float64{{2, 2, 2, 1, 2}, {3, 2, 3, 1, 2}, {4, 2, 3, 1, 3}, {5, 3, 4, 1, 3}}
|
||||
for i, item := range points {
|
||||
point := item.(map[string]any)
|
||||
cov := point["coverage"].(map[string]any)
|
||||
@@ -108,7 +108,7 @@ func TestMasterLiveCumulativeWeeksUseWholeLedgerAndWeeklyStrictRates(t *testing.
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(fresh.CumulativeWeeks) != 4 || fresh.CumulativeWeeks[0].Correctness.Numerator != 0 || fresh.CumulativeWeeks[1].Correctness.Numerator != 1 || fresh.CumulativeWeeks[3].Correctness.Numerator != 1 {
|
||||
if len(fresh.CumulativeWeeks) != 4 || fresh.CumulativeWeeks[0].Correctness.Numerator != 0 || fresh.CumulativeWeeks[1].Correctness.Numerator != 0 || fresh.CumulativeWeeks[3].Correctness.Numerator != 0 {
|
||||
t.Fatal("later source feedback did not update every affected cumulative week")
|
||||
}
|
||||
filtered, e := s.ReadMasterDashboard(ctx, dobotaiops.RecordQuery{Window: dobotaiops.Window{TenantKey: s.tenant, Start: start, End: end}, Keyword: "\n"})
|
||||
|
||||
@@ -78,20 +78,20 @@ func TestMasterCalendarMonthsResetAndCrossingWeekReadsPreviousMonth(t *testing.T
|
||||
t.Fatalf("monthly rates did not reset or pending entered denominator: %v", point)
|
||||
}
|
||||
}
|
||||
assertRates(crossing["monthly_quality"], 3, 2, 3, 1, 2)
|
||||
assertRates(crossing["monthly_quality"], 3, 2, 3, 1, 1)
|
||||
months, ok := crossing["calendar_months"].([]any)
|
||||
if !ok || len(months) != 2 {
|
||||
t.Fatal("expected August and September independent month points, no October fragment")
|
||||
}
|
||||
assertRates(months[0], 1, 1, 1, 0, 1)
|
||||
assertRates(months[1], 3, 2, 3, 1, 2)
|
||||
assertRates(months[1], 3, 2, 3, 1, 1)
|
||||
inside := read("2026-10-05T00:00:00+08:00", "2026-10-12T00:00:00+08:00")
|
||||
assertRates(inside["monthly_quality"], 2, 1, 2, 1, 2)
|
||||
assertRates(inside["monthly_quality"], 2, 1, 2, 1, 1)
|
||||
if len(inside["calendar_months"].([]any)) != 3 {
|
||||
t.Fatal("missing October monthly point")
|
||||
}
|
||||
prefill, e := s.PrefillWeeklyDraft(ctx, "2026-W40", WeeklyDraftPrefillRequest{BaseRevision: 0, Nonce: "fixture_monthly_prefill_0001"}, "fixture-admin", time.Now())
|
||||
if e != nil || !strings.Contains(prefill.Draft.Markdown, "质量统计月:2026-09") || !strings.Contains(prefill.Draft.Markdown, "Coverage Rate: 66.67%") || !strings.Contains(prefill.Draft.Markdown, "Accuracy Rate: 50.00%") {
|
||||
if e != nil || !strings.Contains(prefill.Draft.Markdown, "质量统计月:2026-09") || !strings.Contains(prefill.Draft.Markdown, "Coverage Rate: 66.67%") || !strings.Contains(prefill.Draft.Markdown, "Accuracy Rate: 100.00%") {
|
||||
t.Fatal("new prefill did not use the same September rates", e)
|
||||
}
|
||||
var before string
|
||||
@@ -102,8 +102,8 @@ func TestMasterCalendarMonthsResetAndCrossingWeekReadsPreviousMonth(t *testing.T
|
||||
t.Fatal(e)
|
||||
}
|
||||
fresh := read("2026-09-28T00:00:00+08:00", "2026-10-05T00:00:00+08:00")
|
||||
assertRates(fresh["monthly_quality"], 3, 2, 3, 0, 2)
|
||||
assertRates(fresh["calendar_months"].([]any)[1], 3, 2, 3, 0, 2)
|
||||
assertRates(fresh["monthly_quality"], 3, 2, 3, 0, 1)
|
||||
assertRates(fresh["calendar_months"].([]any)[1], 3, 2, 3, 0, 1)
|
||||
saved, e := s.ReadWeeklyDraft(ctx, "2026-W40", time.Now())
|
||||
if e != nil || saved.Markdown != prefill.Draft.Markdown || saved.Revision != prefill.Draft.Revision {
|
||||
t.Fatal("live rate refresh overwrote a previously saved weekly draft", e)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package qaopsmirror
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"knowledge-governance/internal/dobotaiops"
|
||||
pg "knowledge-governance/internal/platform/postgres"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestUncoveredFixedPendingReadWriteFiltersAndCoverageTransitions(t *testing.T) {
|
||||
p := mirrorFixture(t)
|
||||
ctx := context.Background()
|
||||
s := NewStore(p, "fixture-uncovered-fixed")
|
||||
queue := pg.NewStore(p)
|
||||
entry := fixtureEntry("fixed-pending", "暂无已发布")
|
||||
var wire map[string]any
|
||||
_ = json.Unmarshal(entry.Payload, &wire)
|
||||
wire["feedback"] = map[string]any{"asker_value": "down", "up": 0, "down": 1}
|
||||
entry.Payload, _ = json.Marshal(wire)
|
||||
job := claimMirrorJob(t, s, queue, "fixed-pending-seed")
|
||||
if err := s.HandleSync(ctx, *job, func(context.Context) (Source, error) {
|
||||
return &fixtureSource{rows: []dobotaiops.MirrorRecord{entry}}, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.Exec(ctx, `UPDATE qa_ops_master_records SET local_fields=local_fields||'{"coverage":"否","is_correct":"是"}'::jsonb WHERE tenant_key=$1 AND id=$2`, s.tenant, "fixed-pending"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rec, err := s.GetMasterRecord(ctx, s.tenant, "fixed-pending")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
keys := []dobotaiops.QualityKey{{ID: rec.ID, InputHash: rec.QualityInputHash}}
|
||||
views, err := s.ReadMasterQualityViews(ctx, keys)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v := views[rec.ID]
|
||||
var original string
|
||||
if err = p.QueryRow(ctx, `SELECT md5(payload::text||original_fields::text||local_fields::text)FROM qa_ops_master_records WHERE tenant_key=$1 AND id=$2`, s.tenant, rec.ID).Scan(&original); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v.Effective.Correctness != "pending" {
|
||||
t.Fatal("uncovered stale binary value survived")
|
||||
}
|
||||
for _, value := range []string{"是", "否"} {
|
||||
q := MasterFieldPatch{InputHash: v.InputHash, InputEpoch: v.InputEpoch, BaseReviewRevision: v.Revision, Nonce: "fixture_fixed_reject_001", Fields: map[string]string{"is_correct": value}}
|
||||
if _, err = s.PatchMasterFields(ctx, rec.ID, q, "fixture-admin"); err == nil {
|
||||
t.Fatal("uncovered accepted binary inline write")
|
||||
}
|
||||
}
|
||||
q := MasterFieldPatch{InputHash: v.InputHash, InputEpoch: v.InputEpoch, BaseReviewRevision: v.Revision, Nonce: "fixture_fixed_pending_001", Fields: map[string]string{"is_correct": "待确认"}}
|
||||
receipt, err := s.PatchMasterFields(ctx, rec.ID, q, "fixture-admin")
|
||||
if err != nil || receipt.SavedRevision != 1 {
|
||||
t.Fatal("uncovered downvote prevented fixed pending", err)
|
||||
}
|
||||
q.BaseRevision = 1
|
||||
q.Nonce = "fixture_fixed_covered_001"
|
||||
q.Fields = map[string]string{"coverage": "是"}
|
||||
if _, err = s.PatchMasterFields(ctx, rec.ID, q, "fixture-admin"); err != nil {
|
||||
t.Fatal("fixed pending deadlocked transition to covered", err)
|
||||
}
|
||||
views, err = s.ReadMasterQualityViews(ctx, keys)
|
||||
if err != nil || views[rec.ID].Effective.Coverage != "covered" || views[rec.ID].Effective.Correctness != "incorrect" {
|
||||
t.Fatal("covered downvote no longer wins", err)
|
||||
}
|
||||
q.BaseRevision = 2
|
||||
q.Nonce = "fixture_fixed_uncovered_001"
|
||||
q.Fields = map[string]string{"coverage": "否", "is_correct": "待确认"}
|
||||
if _, err = s.PatchMasterFields(ctx, rec.ID, q, "fixture-admin"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
window := dobotaiops.Window{TenantKey: s.tenant, Start: rec.AskedAt.Add(-time.Hour), End: rec.AskedAt.Add(time.Hour)}
|
||||
for _, tc := range []struct {
|
||||
value string
|
||||
want int
|
||||
}{{"待确认", 1}, {"否", 0}, {"是", 0}} {
|
||||
page, err := s.ListMasterRecords(ctx, dobotaiops.RecordQuery{Window: window, Limit: 10, Filters: map[string]string{"coverage": "否", "is_correct": tc.value}})
|
||||
if err != nil || page.Total != int64(tc.want) {
|
||||
t.Fatalf("fixed pending filter mismatch value=%q total=%d err=%v", tc.value, page.Total, err)
|
||||
}
|
||||
}
|
||||
var after string
|
||||
if err = p.QueryRow(ctx, `SELECT md5(payload::text||original_fields::text||local_fields::text)FROM qa_ops_master_records WHERE tenant_key=$1 AND id=$2`, s.tenant, rec.ID).Scan(&after); err != nil || after != original {
|
||||
t.Fatal("fixed rule rewrote original Q&A or stored fields", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user