4
0
Эх сурвалжийг харах

fix(alerts): align frontend default config with the backend (#1672) (#1673)

Nacho 1 сар өмнө
parent
commit
2373ef4bbc

+ 6 - 13
app/src/data/alertConfig.ts

@@ -20,11 +20,15 @@ export const ALERT_CATEGORIES: readonly AlertCategory[] = [
 
 export const ALERT_CONFIG_LEVELS: readonly AlertConfigLevel[] = ['urgent', 'all', 'none']
 
-/** Defaults del SPEC §2 (mismo JSON que `alerts.config.v1` en el backend). */
+/**
+ * Defaults del SPEC §2. Deben coincidir con `DefaultConfig()` del backend
+ * (`server-go/internal/alerts/alerts.go`), que es la fuente de verdad: el test
+ * `TestFrontendDefaultsMatchBackend` falla si las dos copias se separan (#1672).
+ */
 export const DEFAULT_ALERTS_CONFIG: AlertsConfig = {
   router: 'urgent',
   internet: 'urgent',
-  clients: 'urgent',
+  clients: 'all',
   signal: 'none',
   vpn: 'none',
   system: 'all',
@@ -66,17 +70,6 @@ export function saveDemoAlertsConfig(cfg: AlertsConfig): void {
   }
 }
 
-/**
- * ¿Pasa un evento el filtro de su categoría? (semántica §2: none descarta,
- * urgent solo deja los urgentes). Categoría desconocida → 'all' (no esconder).
- */
-export function passesAlertConfig(ev: Pick<AlertEvent, 'category' | 'urgent'>, cfg: AlertsConfig): boolean {
-  const level: AlertConfigLevel = cfg[ev.category] ?? 'all'
-  if (level === 'none') return false
-  if (level === 'urgent') return ev.urgent
-  return true
-}
-
 /**
  * Nivel "none" = la categoría no existe para el operador: el servidor no la
  * registra ni la sirve (#1659). Es distinto de "urgent", que solo limita los

+ 51 - 0
server-go/internal/alerts/frontend_defaults_test.go

@@ -0,0 +1,51 @@
+package alerts
+
+import (
+	"os"
+	"path/filepath"
+	"regexp"
+	"strings"
+	"testing"
+)
+
+// La config por defecto vive duplicada: DefaultConfig() aqui y
+// DEFAULT_ALERTS_CONFIG en el frontend. Si una copia cambia sin la otra, el
+// panel de ajustes del demo y el fallback live arrancan con niveles que el
+// servidor no usa (#1672).
+func TestFrontendDefaultsMatchBackend(t *testing.T) {
+	const rel = "../../../app/src/data/alertConfig.ts"
+	raw, err := os.ReadFile(filepath.Join(rel))
+	if err != nil {
+		t.Fatalf("read %s: %v", rel, err)
+	}
+	src := string(raw)
+	start := strings.Index(src, "export const DEFAULT_ALERTS_CONFIG")
+	if start < 0 {
+		t.Fatalf("%s: DEFAULT_ALERTS_CONFIG not found", rel)
+	}
+	block := src[start:]
+	if end := strings.Index(block, "\n}"); end >= 0 {
+		block = block[:end]
+	}
+
+	entries := regexp.MustCompile(`(\w+):\s*'(\w+)'`).FindAllStringSubmatch(block, -1)
+	if len(entries) != len(DefaultConfig()) {
+		t.Fatalf("frontend declares %d categories, backend %d: %q", len(entries), len(DefaultConfig()), block)
+	}
+
+	frontend := make(map[string]string, len(entries))
+	for _, m := range entries {
+		frontend[m[1]] = m[2]
+	}
+
+	for cat, want := range DefaultConfig() {
+		got, ok := frontend[cat]
+		if !ok {
+			t.Errorf("frontend is missing category %q", cat)
+			continue
+		}
+		if got != want {
+			t.Errorf("category %q: frontend default %q, backend default %q", cat, got, want)
+		}
+	}
+}