fix(qa): 无法判定的判错结论不再计入正确率分母
build / build (push) Successful in 1m18s

根因为“结果不清”或未归因的判错记录移出正确率分母,并以 unjudged 单独返回,覆盖率口径不变。
统计规则版本升到 calendar-month-strict-yes-over-yes-no-v2,前端严格解析同步接受该字段。
This commit is contained in:
hermes
2026-10-25 23:11:12 +08:00
parent 1d880a0f49
commit 1d33ff6976
5 changed files with 74 additions and 11 deletions
+21 -1
View File
@@ -2,11 +2,12 @@ package qaopsmirror
import (
"knowledge-governance/internal/qaopsquality"
"strings"
"time"
)
const dashboardMonthlySource = "master_live_calendar_month_v1"
const dashboardMonthlyPolicy = "calendar-month-strict-yes-over-yes-no-v1"
const dashboardMonthlyPolicy = "calendar-month-strict-yes-over-yes-no-v2"
type DashboardQualityPeriod struct {
Month string `json:"month"`
@@ -20,6 +21,7 @@ type DashboardStrictQuality struct {
Records int `json:"records"`
Coverage qaopsquality.Rate `json:"coverage"`
Correctness qaopsquality.Rate `json:"correctness"`
Unjudged int `json:"unjudged"`
}
type DashboardMonth struct {
Month string `json:"month"`
@@ -52,6 +54,14 @@ func dashboardStrictQuality(records []dashboardTimedQuality, start, end time.Tim
case "uncovered":
uncovered++
}
// An answer whose correctness cannot be established is not a wrong answer:
// "结果不清" and a missing root cause both mean the judge could not attribute a
// concrete defect, so they leave the correctness denominator and are surfaced
// separately instead of silently inflating the error count.
if dashboardUnjudged(r.view) {
out.Unjudged++
continue
}
switch r.view.Effective.Correctness {
case "correct":
correct++
@@ -64,6 +74,16 @@ func dashboardStrictQuality(records []dashboardTimedQuality, start, end time.Tim
return out
}
func dashboardUnjudged(v qaopsquality.View) bool {
if v.State == "stale" || v.Effective.Correctness != "incorrect" {
return false
}
cause := strings.TrimSpace(v.Effective.RootCause)
return cause == "" || cause == dashboardUnclearCause
}
const dashboardUnclearCause = "结果不清"
func dashboardCalendarMonths(records []dashboardTimedQuality, end, now time.Time) []DashboardMonth {
out := []DashboardMonth{}
cutoff := end
@@ -1,6 +1,7 @@
package qaopsmirror
import (
"knowledge-governance/internal/qaopsquality"
"testing"
"time"
)
@@ -31,3 +32,32 @@ func TestQualityMonthCrossingWeekIsPreviousMonthReport(t *testing.T) {
})
}
}
func TestStrictQualityLeavesUnjudgeableAnswersOutOfTheCorrectnessDenominator(t *testing.T) {
start := monthlyTestTime(t, "2026-10-01T00:00:00+08:00")
end := monthlyTestTime(t, "2026-11-01T00:00:00+08:00")
at := start.Add(time.Hour)
view := func(coverage, correctness, cause string) qaopsquality.View {
return qaopsquality.View{State: "unreviewed", Effective: qaopsquality.Fields{Coverage: coverage, Correctness: correctness, RootCause: cause}}
}
records := []dashboardTimedQuality{
{id: "correct", at: at, view: view("covered", "correct", "")},
{id: "real-error", at: at, view: view("covered", "incorrect", "答案生成错误")},
{id: "unclear", at: at, view: view("covered", "incorrect", dashboardUnclearCause)},
{id: "unlabelled", at: at, view: view("covered", "incorrect", "")},
{id: "pending", at: at, view: view("uncovered", "pending", "")},
}
got := dashboardStrictQuality(records, start, end)
if got.Correctness.Numerator != 1 || got.Correctness.Denominator != 2 {
t.Fatalf("correctness = %d/%d, want 1/2 (only genuinely judged answers)", got.Correctness.Numerator, got.Correctness.Denominator)
}
if got.Unjudged != 2 {
t.Fatalf("unjudged = %d, want 2 (结果不清 + missing root cause)", got.Unjudged)
}
if got.Coverage.Numerator != 4 || got.Coverage.Denominator != 5 {
t.Fatalf("coverage = %d/%d, want 4/5 unchanged by the correctness rule", got.Coverage.Numerator, got.Coverage.Denominator)
}
if dashboardMonthlyPolicy != "calendar-month-strict-yes-over-yes-no-v2" {
t.Fatal("policy version must change when the denominator changes")
}
}