cb9f0c389f
build / build (push) Successful in 1m10s
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。 自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。 验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。 真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。 没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
90 lines
5.0 KiB
Go
90 lines
5.0 KiB
Go
package qaopsmirror
|
|
|
|
import (
|
|
"encoding/json"
|
|
"knowledge-governance/internal/qaopsquality"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWeeklyTemplateCalendarMonthOverridesOnlyNewPrefillNotHistoricalEvidence(t *testing.T) {
|
|
now := monthlyTestTime(t, "2026-10-21T08:00:00+08:00")
|
|
start, end, e := weeklyDraftBounds("2026-W40", now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
data := Dashboard{Start: start, End: end, MonthStart: monthlyTestTime(t, "2026-10-01T00:00:00+08:00"), ReportedWeeks: []DashboardReported{{Week: "2026WK40", WeekStart: start, WeekEnd: end, CoveragePercent: 57.23, CorrectnessPercent: 92.34, Source: "user_provided_history"}}, QualityPeriod: &DashboardQualityPeriod{Month: "2026-09", Start: monthlyTestTime(t, "2026-09-01T00:00:00+08:00"), CutoffAt: monthlyTestTime(t, "2026-10-01T00:00:00+08:00"), CalculatedAt: now, Source: dashboardMonthlySource, PolicyVersion: dashboardMonthlyPolicy}, MonthlyQuality: &DashboardStrictQuality{Records: 3, Coverage: dashboardRate(2, 3), Correctness: dashboardRate(1, 2)}}
|
|
md, seed, e := renderWeeklyTemplate("2026-W40", data, now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
var meta map[string]any
|
|
_ = json.Unmarshal(seed, &meta)
|
|
if !strings.Contains(md, "Coverage Rate: 66.67%") || !strings.Contains(md, "Accuracy Rate: 50.00%") || !strings.Contains(md, "质量统计月:2026-09") || meta["quality_source"] != dashboardMonthlySource {
|
|
t.Fatal("new weekly prefill still uses historical/week quality instead of the selected calendar month", md)
|
|
}
|
|
if data.ReportedWeeks[0].CoveragePercent != 57.23 {
|
|
t.Fatal("historical reported evidence changed")
|
|
}
|
|
if strings.Count(md, "\n## ") != 12 {
|
|
t.Fatal("changed approved bilingual six-section template")
|
|
}
|
|
period, ok := meta["quality_period"].(map[string]any)
|
|
if !ok || period["month"] != "2026-09" {
|
|
t.Fatal("monthly prefill provenance missing")
|
|
}
|
|
}
|
|
|
|
func TestWeeklyTemplateHistoricalRatesKeepSourceWeekKeyAndUseMatchingBoundaries(t *testing.T) {
|
|
now := time.Date(2026, 10, 19, 12, 0, 0, 0, time.UTC)
|
|
start, end, e := weeklyDraftBounds("2026-W40", now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
data := Dashboard{Start: start, End: end, MonthStart: dashboardDay(end.Add(-time.Second)), ReportedWeeks: []DashboardReported{{Week: "2026WK40", WeekStart: start, WeekEnd: end, CoveragePercent: 57.23, CorrectnessPercent: 92.34, Source: "user_provided_history"}}}
|
|
md, seed, e := renderWeeklyTemplate("2026-W40", data, now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
var meta map[string]any
|
|
if json.Unmarshal(seed, &meta) != nil {
|
|
t.Fatal("invalid seed")
|
|
}
|
|
if !strings.Contains(md, "Coverage Rate: 57.23%") || !strings.Contains(md, "Accuracy Rate: 92.34%") || meta["quality_source"] != "reported-history" || meta["quality_source_week_key"] != "2026WK40" {
|
|
t.Fatalf("historical source key must remain verbatim and match by real week boundaries: %s", md)
|
|
}
|
|
if data.ReportedWeeks[0].Week != "2026WK40" {
|
|
t.Fatal("rewrote source week identifier")
|
|
}
|
|
}
|
|
|
|
func TestWeeklyTemplateUsesExactBilingualSixSectionsAndRealMetricValues(t *testing.T) {
|
|
now := time.Date(2026, 10, 19, 12, 0, 0, 0, time.UTC)
|
|
start, end, e := weeklyDraftBounds("2026-W41", now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
p := func(v float64) *float64 { return &v }
|
|
data := Dashboard{Start: start, End: end, MonthStart: time.Date(2026, 10, 1, 0, 0, 0, 0, dashboardLocation), TotalIssues: 1234, NewThisWeek: 12, Quality: qaopsquality.Summary{Rates: qaopsquality.Rates{Coverage: qaopsquality.Rate{Percent: p(0)}, Correctness: qaopsquality.Rate{}}}, Regions: []DashboardRegion{{ID: "a", Name: "APAC", Frequency: p(0), UsageCoverage: qaopsquality.Rate{Percent: p(10)}}, {ID: "b", Name: "America", Frequency: p(2), UsageCoverage: qaopsquality.Rate{Percent: p(5)}}, {ID: "c", Name: "unassigned\n## fake", Frequency: nil}}}
|
|
md, seed, e := renderWeeklyTemplate("2026-W41", data, now)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if strings.Count(md, "\n## ") != 12 || !strings.HasPrefix(md, "# Knowledge Base Weekly Report - 2026 WK41") || strings.Index(md, "## 6. Next Week Priorities") > strings.Index(md, "# 知识库周报") || !strings.Contains(md, "问题总数:1234") || !strings.Contains(md, "New This Week: 12") || !strings.Contains(md, "Coverage Rate: 0.00%") || !strings.Contains(md, "Accuracy Rate: —") || strings.Contains(md, "{{") || strings.Contains(md, "\n## fake") {
|
|
t.Fatalf("skill template, trusted values or escaping missing: %s", md)
|
|
}
|
|
if !strings.Contains(md, "[待填写]") || !strings.Contains(md, "[To be completed]") {
|
|
t.Fatal("invented authored highlights instead of leaving placeholders")
|
|
}
|
|
average := md[strings.Index(md, "Regional Average"):strings.Index(md, "## 4.")]
|
|
coverage := md[strings.Index(md, "Regional Usage Coverage"):strings.Index(md, "## 5.")]
|
|
if strings.Index(average, "Americas") > strings.Index(average, "APAC") || strings.Index(coverage, "APAC") > strings.Index(coverage, "Americas") {
|
|
t.Fatal("regional rankings not sorted independently")
|
|
}
|
|
var meta map[string]any
|
|
if json.Unmarshal(seed, &meta) != nil || meta["quality_source"] != "live-week" {
|
|
t.Fatal("prefill provenance missing")
|
|
}
|
|
}
|