feat(qa-ops): 交付十一项统计看板与完整图片导出
build / build (push) Successful in 1m10s

以治理库单一只读事务分开聚合累计、自然周、截止月及当前通讯录使用分母;浏览器不再读取全量长答案来构建看板。

新增迁移52与普通worker周质量冻结,保留真实冻结时点、规则和标量贡献;缺少当时快照留空。提交后冻结头与贡献不可修改、删除或追加;只读接口保留管理员、固定租户、严格JSON与输入冲突保护。

已验证:make verify退出0,686个Go用例和305个前端用例通过,必需跳过0;镜像与组织隔离PostgreSQL竞态回归退出0。真实治理副本浏览器核对第41周累计1885与新增471、十一项和完整PNG下载,390px无外溢、JS异常0;明确模拟503后不伪零且重试恢复。没有修改DobotAI原始问答、真实区域规则或生产发布门禁。
This commit is contained in:
姚章浩
2026-10-18 23:26:55 +08:00
parent 76671e0784
commit 6e67034fbd
32 changed files with 2103 additions and 356 deletions
+50
View File
@@ -0,0 +1,50 @@
package httpapi
import (
"context"
"errors"
"knowledge-governance/internal/dobotaiops"
"knowledge-governance/internal/qaopsmirror"
"knowledge-governance/internal/qaopsquality"
"net/http"
"time"
)
type qaDashboardReader interface {
ReadDashboard(context.Context, dobotaiops.RecordQuery) (qaopsmirror.Dashboard, error)
}
func qaOperationsDashboard(w http.ResponseWriter, r *http.Request, c Config) {
if !authorizeQAOps(w, r) || !authorizeQAIntent(w, r, "qa-dashboard") {
return
}
var request struct {
Start string `json:"start"`
End string `json:"end"`
Keyword string `json:"keyword"`
}
if decodeQualityJSON(w, r, &request, "start", "end") != nil {
qaOpsError(w, dobotaiops.ErrInvalidQuery)
return
}
reader, ok := c.QAOps.(qaDashboardReader)
if !ok || c.QAOpsTenantKey == "" {
qaOpsError(w, dobotaiops.ErrUnavailable)
return
}
window, e := dobotaiops.NewWindow(c.QAOpsTenantKey, request.Start, request.End, 90*24*time.Hour, c.Now())
if e != nil {
qaOpsError(w, e)
return
}
dashboard, e := reader.ReadDashboard(r.Context(), dobotaiops.RecordQuery{Window: window, Keyword: request.Keyword})
if e != nil {
if errors.Is(e, qaopsquality.ErrConflict) {
writeQualityError(w, e)
return
}
qaOpsError(w, e)
return
}
writeJSON(w, 200, map[string]any{"data": dashboard})
}
+73
View File
@@ -0,0 +1,73 @@
package httpapi
import (
"context"
"knowledge-governance/internal/dobotaiops"
"knowledge-governance/internal/qaopsmirror"
"knowledge-governance/internal/qaopsquality"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
type dashboardReaderSpy struct {
attributedReader
calls int
query dobotaiops.RecordQuery
err error
}
func (s *dashboardReaderSpy) ReadDashboard(_ context.Context, q dobotaiops.RecordQuery) (qaopsmirror.Dashboard, error) {
s.calls++
s.query = q
return qaopsmirror.Dashboard{TotalIssues: 7, NewThisWeek: 2}, s.err
}
func TestQADashboardIsFixedTenantAdminAndReadOnly(t *testing.T) {
reader := &dashboardReaderSpy{}
auth := newFakeAuthStore()
auth.sessions["dash-admin"] = "usr-boss"
auth.sessions["dash-viewer"] = "usr-eye"
h, e := NewHandler(Config{Store: &fakeJobStore{}, QAOps: reader, QAOpsTenantKey: "fixed-dashboard-tenant", Now: func() time.Time { return time.Date(2026, 10, 18, 12, 0, 0, 0, time.UTC) }, Auth: &AuthConfig{Store: auth}})
if e != nil {
t.Fatal(e)
}
good := `{"start":"2026-10-05T00:00:00+08:00","end":"2026-10-12T00:00:00+08:00","keyword":"100%_"}`
for _, c := range []struct {
token, action, origin, body string
status int
}{
{"", "qa-dashboard", "", good, 401}, {"dash-viewer", "qa-dashboard", "", good, 403}, {"dash-admin", "", "", good, 403}, {"dash-admin", "qa-dashboard", "https://untrusted.invalid", good, 403},
{"dash-admin", "qa-dashboard", "", `null`, 400}, {"dash-admin", "qa-dashboard", "", `{"start":null,"end":"2026-10-12T00:00:00+08:00"}`, 400},
{"dash-admin", "qa-dashboard", "", `{"tenant":"other","start":"2026-10-05T00:00:00+08:00","end":"2026-10-12T00:00:00+08:00"}`, 400},
{"dash-admin", "qa-dashboard", "", good, 200},
} {
r := httptest.NewRequest(http.MethodPost, "/api/v1/qa-ops/dashboard", strings.NewReader(c.body))
if c.token != "" {
r.AddCookie(&http.Cookie{Name: sessionCookieName, Value: c.token})
}
r.Header.Set("X-Governance-Action", c.action)
r.Header.Set("Origin", c.origin)
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Code != c.status {
t.Fatalf("dashboard status=%d want=%d", w.Code, c.status)
}
if w.Code == 200 && w.Header().Get("Cache-Control") != "no-store" {
t.Fatal("private dashboard response may be cached")
}
}
if reader.calls != 1 || reader.query.Window.TenantKey != "fixed-dashboard-tenant" || reader.query.Keyword != "100%_" {
t.Fatal("rejected requests reached the reader or browser controlled the tenant")
}
reader.err = qaopsquality.ErrConflict
r := httptest.NewRequest(http.MethodPost, "/api/v1/qa-ops/dashboard", strings.NewReader(good))
r.AddCookie(&http.Cookie{Name: sessionCookieName, Value: "dash-admin"})
r.Header.Set("X-Governance-Action", "qa-dashboard")
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Code != http.StatusConflict {
t.Fatalf("quality input drift status=%d want409", w.Code)
}
}
+1
View File
@@ -177,6 +177,7 @@ func NewHandler(config Config) (http.Handler, error) {
config.NewID = newID
}
mux := http.NewServeMux()
mux.HandleFunc("POST /api/v1/qa-ops/dashboard", func(w http.ResponseWriter, r *http.Request) { qaOperationsDashboard(w, r, config) })
mux.HandleFunc("POST /api/v1/qa-ops/quality/query", func(w http.ResponseWriter, r *http.Request) { qaQualityQuery(w, r, config) })
mux.HandleFunc("POST /api/v1/qa-ops/records/{id}/reviews", func(w http.ResponseWriter, r *http.Request) { qaQualityReview(w, r, config) })
mux.HandleFunc("GET /api/v1/qa-ops/records/{id}/quality/history", func(w http.ResponseWriter, r *http.Request) { qaQualityHistory(w, r, config) })