Files
姚章浩 533db535f1
build / build (push) Successful in 1m12s
feat(qaops): 接入真实模型补缺任务与总表看板
按已确认需求提供独立安全模型配置、真实探测、正式字典字段评估与原问题译中,持久批次支持只补空白、暂停恢复、有限重试、幂等和逐字段依据。覆盖固定规则、本地语言、组织关联与主表有效看板共用治理侧读模型,保留源生产和冻结历史。

验证:完整 make verify 退出0,702项Go与329项前端通过;默认118项外部/隔离集成明确跳过,另跑完整镜像及组织隔离PG竞态。12并发、输入漂移、过期租约、暂停/恢复及有限重试通过。用户授权的百炼 deepseek-v4.1-flash 完成真实后台与浏览器评估/翻译;552行、16列、11块看板及完整PNG、独立配置页测试/保存、重开恢复和零JS异常通过。仅非业务样本外发,自动处理关闭,原payload不变。

上线前治理库已做导出快照原生备份并真实恢复,60表行数与17个QA表内容哈希一致;不修改DobotAI生产或隧道。本提交时尚未部署,线上验收须独立完成。
2026-10-19 14:29:49 +08:00

54 lines
2.2 KiB
Go

package httpapi
import (
"knowledge-governance/internal/qaopsai"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestAIUnavailableDoesNotFalselyClaimNoModelCallOccurred(t *testing.T) {
response := httptest.NewRecorder()
qaAIError(response, qaopsai.ErrUnavailable)
if strings.Contains(response.Body.String(), "未调用模型") {
t.Fatal("a persistence failure after a model call was reported as no call")
}
}
func TestAIEndpointsRequireAdminAndExplicitSameOriginWriteIntent(t *testing.T) {
auth := newFakeAuthStore()
auth.sessions["fixture-ai-admin"] = "usr-boss"
auth.sessions["fixture-ai-viewer"] = "usr-eye"
handler, err := NewHandler(Config{Store: &fakeJobStore{}, Auth: &AuthConfig{Store: auth}})
if err != nil {
t.Fatal(err)
}
for _, route := range []struct{ method, path, body string }{{"GET", "/api/v1/qa-ops/ai/settings", ""}, {"GET", "/api/v1/qa-ops/ai/status", ""}, {"POST", "/api/v1/qa-ops/ai/settings", `{}`}, {"POST", "/api/v1/qa-ops/ai/settings/test", `{}`}, {"POST", "/api/v1/qa-ops/ai/previews", `{}`}, {"POST", "/api/v1/qa-ops/ai/batches", `{}`}, {"POST", "/api/v1/qa-ops/ai/automation", `{}`}, {"POST", "/api/v1/qa-ops/ai/batches/fixture/actions", `{}`}} {
for _, who := range []struct {
token string
want int
}{{"", 401}, {"fixture-ai-viewer", 403}, {"fixture-ai-admin", 503}} {
request := httptest.NewRequest(route.method, route.path, strings.NewReader(route.body))
if who.token != "" {
request.AddCookie(&http.Cookie{Name: sessionCookieName, Value: who.token})
}
request.Header.Set("X-Governance-Action", "qa-ai")
response := httptest.NewRecorder()
handler.ServeHTTP(response, request)
if response.Code != who.want {
t.Fatalf("%s %s role=%s status=%d want=%d", route.method, route.path, who.token, response.Code, who.want)
}
}
if route.method == "POST" {
request := httptest.NewRequest(route.method, route.path, strings.NewReader(route.body))
request.AddCookie(&http.Cookie{Name: sessionCookieName, Value: "fixture-ai-admin"})
response := httptest.NewRecorder()
handler.ServeHTTP(response, request)
if response.Code != 403 {
t.Fatal("write without explicit action was accepted")
}
}
}
}