package qaopsmirror import ( "context" "encoding/json" "knowledge-governance/internal/dobotaiops" pg "knowledge-governance/internal/platform/postgres" "testing" "time" ) func TestMasterDashboardIncludesMasterOnlyLabelsWithoutChangingLegacyDashboard(t *testing.T) { pool := mirrorFixture(t) ctx := context.Background() s := NewStore(pool, "fixture-master-dashboard") queue := pg.NewStore(pool) entry := fixtureEntry("source-one", "已有资料") var wire map[string]any _ = json.Unmarshal(entry.Payload, &wire) wire["asked_at"] = "2026-10-06T08:00:00+08:00" entry.Payload, _ = json.Marshal(wire) job := claimMirrorJob(t, s, queue, "master-dashboard-seed") if err := s.HandleSync(ctx, *job, func(context.Context) (Source, error) { return &fixtureSource{rows: []dobotaiops.MirrorRecord{entry}}, nil }); err != nil { t.Fatal(err) } _, err := pool.Exec(ctx, `INSERT INTO qa_ops_master_records(tenant_key,id,event_key,origin,asked_at,question,status,identity,quality_hash,payload) SELECT tenant_key,'master-only',repeat('f',64),origin,asked_at,question,status,identity,repeat('e',64),payload||jsonb_build_object('id','master-only','_quality_hash',repeat('e',64),'master_fields',jsonb_build_object('coverage','是','is_correct','否','product_category','MG400','problem_type','参数')) FROM qa_ops_master_records WHERE tenant_key=$1 AND id='source-one'`, s.tenant) if err != nil { t.Fatal(err) } start, _ := time.Parse(time.RFC3339, "2026-10-05T00:00:00+08:00") q := dobotaiops.RecordQuery{Window: dobotaiops.Window{TenantKey: s.tenant, Start: start, End: start.AddDate(0, 0, 7)}} got, err := s.ReadMasterDashboard(ctx, q) if err != nil { t.Fatal(err) } if got.TotalIssues != 2 || got.NewThisWeek != 2 || got.Quality.Total != 2 || got.Quality.Rates.Coverage.Numerator != 2 || got.Quality.Rates.Correctness.Denominator != 1 { t.Fatalf("master dashboard did not use effective master scope: %+v", got) } found := false for _, row := range got.Products { if row.Label == "MG400" && row.Count == 1 { found = true } } if !found { t.Fatal("stored product labels not counted") } record, err := s.GetMasterRecord(ctx, s.tenant, "master-only") if err != nil { t.Fatal(err) } views, err := s.ReadMasterQualityViews(ctx, []dobotaiops.QualityKey{{ID: record.ID, InputHash: record.QualityInputHash}}) if err != nil { t.Fatal(err) } if views[record.ID].Effective.ProductCategory != "MG400" || views[record.ID].Effective.Correctness != "incorrect" { t.Fatal("list/summary master projection differs from dashboard") } legacy, err := s.ReadDashboard(ctx, q) if err != nil || legacy.TotalIssues != 1 { t.Fatal("master dashboard changed frozen/legacy source scope", err) } }