Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep dashboard equivalence on canonical active alerts

pulse-triage[bot]4b849cff8315
diff --git a/internal/websocket/connected_equivalence_test.go b/internal/websocket/connected_equivalence_test.go
index 0c40475e81..d5847e9605 100644
--- a/internal/websocket/connected_equivalence_test.go
+++ b/internal/websocket/connected_equivalence_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"reflect"
+ "slices"
"testing"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
@@ -19,7 +20,7 @@ func TestDashboardDispatchLifecycleEquivalence(t *testing.T) {
state.PolicyCatalog = map[string]json.RawMessage{"policy": json.RawMessage(`{"write":false}`)}
state.AISafeSummaryCatalog = map[string]string{"summary": "initial"}
state.ConnectedInfrastructure = []models.ConnectedInfrastructureItemFrontend{{ID: "infra", LastSeen: 1, Status: "online"}}
- state.ActiveAlerts = []models.Alert{{ID: "alert", Level: "warning", Message: "initial"}}
+ state.ActiveAlerts = []models.Alert{{ID: "alert", ResourceID: state.Resources[0].ID, Level: "warning", Message: "initial"}}
getter := func(string) interface{} { return state }
hub := NewHub(getter)
clients := []*Client{{orgID: "own", send: make(chan []byte, 1)}, {orgID: "own", send: make(chan []byte, 1)}, {orgID: "other", send: make(chan []byte, 1)}}
@@ -35,7 +36,7 @@ func TestDashboardDispatchLifecycleEquivalence(t *testing.T) {
hub.clientsByTenant[client.orgID][client] = true
}
otherBaseline := clients[2].stateSnapshot
- for phase := 0; phase < 8; phase++ {
+ for phase := 0; phase < 11; phase++ {
t.Run(fmt.Sprint(phase), func(t *testing.T) {
before := clients[0].stateSnapshot
switch phase {
@@ -51,8 +52,8 @@ func TestDashboardDispatchLifecycleEquivalence(t *testing.T) {
state.Resources[0].PlatformData = json.RawMessage(`{"counter":18446744073709551615,"inventory":["c"]}`)
case 2:
state.Resources[0].Health = json.RawMessage(`{"status":"unhealthy","age":70}`)
- state.Resources[0].Alerts = []models.ResourceAlertFrontend{{ID: "live", Level: "critical"}}
state.ActiveAlerts[0].Level = "critical"
+ state.ActiveAlerts = append(state.ActiveAlerts, models.Alert{ID: "live", ResourceID: state.Resources[0].ID, Level: "critical"})
case 3:
state.Resources[0].Labels = map[string]string{"team": "changed"}
state.Resources[0].Tags = []string{"new"}
@@ -72,10 +73,15 @@ func TestDashboardDispatchLifecycleEquivalence(t *testing.T) {
state.ActiveAlerts = nil
case 6:
state.Resources[0].Health = nil
- state.Resources[0].Alerts = nil
state.Resources[0].PlatformData = nil
state.ConnectionHealth = nil
- case 7: // unchanged evidence must not manufacture a heartbeat
+ case 7: // Alert-only changes must reach both connected clients.
+ state.ActiveAlerts = []models.Alert{{ID: "recurrence", ResourceID: state.Resources[0].ID, Level: "warning", Value: 85}}
+ case 8:
+ state.ActiveAlerts[0].Level, state.ActiveAlerts[0].Value = "critical", 97
+ case 9:
+ state.ActiveAlerts = nil
+ case 10: // unchanged evidence must not manufacture a heartbeat
}
current, err := buildGenericClientStateSnapshot(state)
if err != nil {
@@ -85,6 +91,42 @@ func TestDashboardDispatchLifecycleEquivalence(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ // Pin the alert oracle independently of reference/wire equality:
+ // both encoders dropping alerts must not make this fixture pass.
+ if phase == 2 || phase == 5 || phase >= 7 && phase <= 9 {
+ payload, ok := want[activeAlertsDeltaField].(resourceDeltaPayload)
+ if !ok {
+ t.Fatalf("phase %d lost the active-alert delta: %#v", phase, want)
+ }
+ switch phase {
+ case 2:
+ if len(payload.Upserts) != 2 || len(payload.Removed) != 0 {
+ t.Fatalf("alert update/insertion delta = %#v", payload)
+ }
+ case 5:
+ if len(payload.Upserts) != 0 || len(payload.Removed) != 2 || !slices.Contains(payload.Removed, "alert") || !slices.Contains(payload.Removed, "live") {
+ t.Fatalf("alert removal delta = %#v", payload)
+ }
+ case 7, 8:
+ if len(payload.Upserts) != 1 || len(payload.Removed) != 0 {
+ t.Fatalf("alert-only upsert delta = %#v", payload)
+ }
+ var patch models.Alert
+ if err := json.Unmarshal(payload.Upserts[0], &patch); err != nil {
+ t.Fatal(err)
+ }
+ if patch.ID != "recurrence" || patch.Level != state.ActiveAlerts[0].Level || patch.Value != state.ActiveAlerts[0].Value || phase == 7 && patch.ResourceID != state.Resources[0].ID {
+ t.Fatalf("alert-only patch lost occurrence, target or changed values: %s", payload.Upserts[0])
+ }
+ case 9:
+ if len(payload.Upserts) != 0 || !reflect.DeepEqual(payload.Removed, []string{"recurrence"}) {
+ t.Fatalf("alert-only removal delta = %#v", payload)
+ }
+ }
+ if phase >= 7 && len(want) != 1 {
+ t.Fatalf("alert-only change altered another state field: %#v", want)
+ }
+ }
encoded, err := json.Marshal(Message{Type: "rawData", Data: want})
if err != nil {
t.Fatal(err)