feat(platform): expose missing source diagnosis

This commit is contained in:
lingniu
2026-07-04 06:00:06 +08:00
parent bf17c7437e
commit a60f87c9e7
8 changed files with 102 additions and 22 deletions

View File

@@ -253,8 +253,8 @@ func TestHandlerVehicleServiceIncludesVehicleLevelStatus(t *testing.T) {
if body.Data.ServiceStatus == nil {
t.Fatalf("vehicle service should include serviceStatus: %s", rec.Body.String())
}
if body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "部分来源离线" {
t.Fatalf("vehicle service should summarize partial source health, got %+v body=%s", body.Data.ServiceStatus, rec.Body.String())
if body.Data.ServiceStatus.Status != "degraded" || body.Data.ServiceStatus.Title != "来源不完整" {
t.Fatalf("vehicle service should prioritize missing source evidence, got %+v body=%s", body.Data.ServiceStatus, rec.Body.String())
}
if body.Data.ServiceStatus.OnlineSourceCount != 1 || body.Data.ServiceStatus.SourceCount != 3 {
t.Fatalf("vehicle service should expose source counts, got %+v body=%s", body.Data.ServiceStatus, rec.Body.String())
@@ -320,8 +320,8 @@ func TestHandlerVehicleServiceIncludesSourceConsistency(t *testing.T) {
if consistency.Status == "" || consistency.Severity == "" || consistency.Title == "" || consistency.Detail == "" {
t.Fatalf("sourceConsistency should expose actionable diagnosis, got %+v", consistency)
}
if consistency.Status != "degraded" || consistency.Title != "部分来源离线" {
t.Fatalf("sourceConsistency should diagnose partial source health, got %+v", consistency)
if consistency.Status != "degraded" || consistency.Title != "来源不完整" {
t.Fatalf("sourceConsistency should diagnose missing source evidence before offline evidence, got %+v", consistency)
}
}
@@ -354,6 +354,29 @@ func TestHandlerVehicleServiceExposesMissingSourceSlots(t *testing.T) {
}
}
func TestHandlerVehicleServiceConsistencyExposesMissingProtocols(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/vehicle-service?keyword=粤AG18312", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
var body struct {
Data struct {
SourceConsistency struct {
MissingProtocols []string `json:"missingProtocols"`
} `json:"sourceConsistency"`
} `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatalf("response JSON should decode: %v body=%s", err, rec.Body.String())
}
if !containsString(body.Data.SourceConsistency.MissingProtocols, "YUTONG_MQTT") {
t.Fatalf("sourceConsistency should expose missing source evidence, got %+v body=%s", body.Data.SourceConsistency.MissingProtocols, rec.Body.String())
}
}
func TestHandlerVehicleServiceOverviewEndpoint(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()