feat: 修复 AI 风险语义并隔离 Mock 数据

This commit is contained in:
weijuesen
2026-08-14 01:16:50 +08:00
parent 839ba91354
commit 74d1948d68
29 changed files with 650 additions and 113 deletions
+29 -1
View File
@@ -24,7 +24,11 @@ func TestAIClientDetectParsesResult(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"model": "mock",
"model": "mock",
"modelVersion": "silk-yolo-2026.08.1",
"isMock": true,
"status": "abnormal",
"abnormalProbability": 0.93,
"detections": []map[string]any{
{"bbox": map[string]float64{"x": 1, "y": 2, "w": 3, "h": 4}, "class": "sick", "confidence": 0.93},
},
@@ -40,6 +44,15 @@ func TestAIClientDetectParsesResult(t *testing.T) {
if res.Model != "mock" {
t.Errorf("model = %s, want mock", res.Model)
}
if res.ModelVersion != "silk-yolo-2026.08.1" {
t.Errorf("modelVersion = %s, want silk-yolo-2026.08.1", res.ModelVersion)
}
if !res.IsMock {
t.Error("isMock 应解析为 true")
}
if res.Status != "abnormal" || res.AbnormalProbability != 0.93 {
t.Errorf("AI 语义字段解析不正确: %+v", res)
}
if len(res.Detections) != 1 {
t.Fatalf("detections 数量 = %d, want 1", len(res.Detections))
}
@@ -49,6 +62,21 @@ func TestAIClientDetectParsesResult(t *testing.T) {
}
}
func TestAIDetectionStatus(t *testing.T) {
if got := AIDetectionStatus(nil); got != "unknown" {
t.Errorf("空检测应为 unknown,实际 %s", got)
}
if got := AIDetectionStatus([]AIDetection{{ClassName: "healthy"}}); got != "healthy" {
t.Errorf("全健康应为 healthy,实际 %s", got)
}
if got := AIDetectionStatus([]AIDetection{{ClassName: "unknown"}}); got != "unknown" {
t.Errorf("unknown 应为 unknown,实际 %s", got)
}
if got := AIDetectionStatus([]AIDetection{{ClassName: "sick"}}); got != "abnormal" {
t.Errorf("异常类别应为 abnormal,实际 %s", got)
}
}
func TestAIClientDetectServerError(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "boom", http.StatusInternalServerError)