fix(qa): 首批即显并统一五字段后端筛选
build / build (push) Successful in 1m19s

列表正文改为按需读取;保留完整导出、版本隔离和有效标签筛选。
验证:前端全量、Go全量及隔离PG全mirror竞态通过;覆盖首批回调、续载失败与筛选分页。
This commit is contained in:
姚章浩
2026-10-25 12:45:31 +08:00
parent 65653e5c01
commit 00c4c13283
26 changed files with 836 additions and 39 deletions
+5 -4
View File
@@ -19,9 +19,10 @@ func qaOperationsDashboard(w http.ResponseWriter, r *http.Request, c Config) {
return
}
var request struct {
Start string `json:"start"`
End string `json:"end"`
Keyword string `json:"keyword"`
Start string `json:"start"`
End string `json:"end"`
Keyword string `json:"keyword"`
Filters map[string]string `json:"filters,omitempty"`
}
if decodeQualityJSON(w, r, &request, "start", "end") != nil {
qaOpsError(w, dobotaiops.ErrInvalidQuery)
@@ -37,7 +38,7 @@ func qaOperationsDashboard(w http.ResponseWriter, r *http.Request, c Config) {
qaOpsError(w, e)
return
}
dashboard, e := reader.ReadMasterDashboard(r.Context(), dobotaiops.RecordQuery{Window: window, Keyword: request.Keyword})
dashboard, e := reader.ReadMasterDashboard(r.Context(), dobotaiops.RecordQuery{Window: window, Keyword: request.Keyword, Filters: request.Filters})
if e != nil {
if errors.Is(e, qaopsquality.ErrConflict) {
writeQualityError(w, e)
+25 -2
View File
@@ -82,7 +82,10 @@ func listQAOpsRecords(w http.ResponseWriter, r *http.Request, config Config) {
return
}
values := r.URL.Query()
allowed := map[string]bool{"start": true, "end": true, "keyword": true, "cursor": true, "limit": true}
allowed := map[string]bool{"start": true, "end": true, "keyword": true, "cursor": true, "limit": true, "projection": true}
for _, key := range dobotaiops.QualityFilterKeys {
allowed[key] = true
}
for key, items := range values {
if !allowed[key] || len(items) != 1 {
qaOpsError(w, dobotaiops.ErrInvalidQuery)
@@ -102,12 +105,27 @@ func listQAOpsRecords(w http.ResponseWriter, r *http.Request, config Config) {
return
}
}
filters := map[string]string{}
for _, key := range dobotaiops.QualityFilterKeys {
if value := values.Get(key); value != "" {
filters[key] = value
}
}
if !dobotaiops.ValidQualityFilters(filters) {
qaOpsError(w, dobotaiops.ErrInvalidQuery)
return
}
mode := values.Get("projection")
if mode != "" && mode != "summary" && mode != "full" {
qaOpsError(w, dobotaiops.ErrInvalidQuery)
return
}
projection, err := recordAttribution(r.Context(), config)
if err != nil {
qaOpsError(w, err)
return
}
page, err := config.QAOps.ListRecords(r.Context(), dobotaiops.RecordQuery{Window: window, Keyword: values.Get("keyword"), Cursor: values.Get("cursor"), Limit: limit})
page, err := config.QAOps.ListRecords(r.Context(), dobotaiops.RecordQuery{Window: window, Keyword: values.Get("keyword"), Cursor: values.Get("cursor"), Limit: limit, Summary: mode == "summary", Filters: filters})
if err != nil {
qaOpsError(w, err)
return
@@ -117,6 +135,11 @@ func listQAOpsRecords(w http.ResponseWriter, r *http.Request, config Config) {
writeQualityError(w, err)
return
}
if mode == "summary" {
for i := range page.Items {
page.Items[i] = qaRecordPreview(page.Items[i])
}
}
writeJSON(w, http.StatusOK, map[string]any{"data": page})
}
+29
View File
@@ -0,0 +1,29 @@
package httpapi
import "knowledge-governance/internal/dobotaiops"
func qaPreviewText(s string) string {
r := []rune(s)
if len(r) > 400 {
return string(r[:400]) + "…"
}
return s
}
// Summaries never replace immutable business content or a full export response.
func qaRecordPreview(item dobotaiops.Record) dobotaiops.Record {
item.ContentProjection = "summary"
item.Question = qaPreviewText(item.Question)
item.Answer = qaPreviewText(item.Answer)
fields := make(map[string]string, len(item.MasterFields))
for key, value := range item.MasterFields {
if key == "question" || key == "answer" || key == "question_chinese" {
value = qaPreviewText(value)
}
fields[key] = value
}
item.MasterFields = fields
item.References = nil
item.Media = nil
return item
}
+93
View File
@@ -0,0 +1,93 @@
package httpapi
import (
"context"
"encoding/json"
"knowledge-governance/internal/dobotaiops"
"net/http"
"net/http/httptest"
"strings"
"testing"
"unicode/utf8"
)
type qaPreviewSpy struct {
qaOpsSpy
record dobotaiops.Record
}
func (s *qaPreviewSpy) ListRecords(_ context.Context, q dobotaiops.RecordQuery) (dobotaiops.RecordPage, error) {
s.query = q
return dobotaiops.RecordPage{Items: []dobotaiops.Record{s.record}, Total: 1}, nil
}
func TestQALightweightListPreservesFullRecordAndRejectsUnknownProjection(t *testing.T) {
full := strings.Repeat("长😀", 900)
spy := &qaPreviewSpy{record: dobotaiops.Record{ID: "preview-fixture", Question: full, Answer: full, MasterFields: map[string]string{"question_chinese": full, "product_category": "MG400"}, References: json.RawMessage(`[{"content":"private-reference-body"}]`), Media: json.RawMessage(`[{"url":"private-media"}]`)}}
auth := newFakeAuthStore()
auth.sessions["admin-qa-fixture"] = "usr-boss"
h, err := NewHandler(Config{Store: &fakeJobStore{}, QAOps: spy, QAOpsTenantKey: "approved-tenant", Auth: &AuthConfig{Store: auth}})
if err != nil {
t.Fatal(err)
}
base := "/api/v1/qa-ops/records?start=2026-10-14T00:00:00Z&end=2026-10-15T00:00:00Z"
for _, mode := range []string{"summary", "full", "invalid"} {
req := httptest.NewRequest("GET", base+"&projection="+mode, nil)
req.AddCookie(&http.Cookie{Name: sessionCookieName, Value: "admin-qa-fixture"})
out := httptest.NewRecorder()
h.ServeHTTP(out, req)
if mode == "invalid" {
if out.Code != 400 {
t.Fatal("unknown projection accepted")
}
continue
}
if out.Code != 200 {
t.Fatalf("projection %s status %d", mode, out.Code)
}
var data struct{ Data dobotaiops.RecordPage }
if json.Unmarshal(out.Body.Bytes(), &data) != nil || len(data.Data.Items) != 1 {
t.Fatal("invalid page")
}
row := data.Data.Items[0]
if mode == "summary" {
if utf8.RuneCountInString(row.Answer) > 401 || row.Answer == full || strings.Contains(out.Body.String(), "private-reference-body") || strings.Contains(out.Body.String(), "private-media") {
t.Fatal("summary leaked full content")
}
} else if row.Answer != full || !strings.Contains(out.Body.String(), "private-reference-body") {
t.Fatal("full export content changed")
}
}
if spy.record.Answer != full || spy.record.MasterFields["question_chinese"] != full {
t.Fatal("preview mutated original")
}
_ = http.StatusOK
}
func TestQARecordsAcceptFiveExactFiltersAndRejectUnsupportedValues(t *testing.T) {
spy := &qaOpsSpy{}
auth := newFakeAuthStore()
auth.sessions["admin-qa-fixture"] = "usr-boss"
h, err := NewHandler(Config{Store: &fakeJobStore{}, QAOps: spy, QAOpsTenantKey: "approved-tenant", Auth: &AuthConfig{Store: auth}})
if err != nil {
t.Fatal(err)
}
base := "/api/v1/qa-ops/records?start=2026-10-14T00:00:00Z&end=2026-10-15T00:00:00Z"
for _, suffix := range []string{"&coverage=是&is_correct=否&product_category=MG400&problem_type=参数&root_cause=知识缺失", "&root_cause=__empty__"} {
req := httptest.NewRequest("GET", base+suffix, nil)
req.AddCookie(&http.Cookie{Name: sessionCookieName, Value: "admin-qa-fixture"})
out := httptest.NewRecorder()
h.ServeHTTP(out, req)
if out.Code != 200 || len(spy.query.Filters) == 0 {
t.Fatalf("filter not forwarded: %d", out.Code)
}
}
for _, suffix := range []string{"&coverage=invalid", "&is_correct=是&is_correct=否", "&product_category=" + strings.Repeat("x", 501)} {
req := httptest.NewRequest("GET", base+suffix, nil)
req.AddCookie(&http.Cookie{Name: sessionCookieName, Value: "admin-qa-fixture"})
out := httptest.NewRecorder()
h.ServeHTTP(out, req)
if out.Code != 400 {
t.Fatal("invalid filters accepted")
}
}
}