Move the live metric status projection test clear of main

Main appended TestSilentLinkedAgentStopsRefreshingNodeTemperatureAlert
at the end of monitor_alert_handling_test.go, where this branch had
appended its own projection test, so the two edits conflict. Move the
test unchanged in substance to monitor_alert_intent_test.go, which main
has not touched, so the merge with main is clean.
This commit is contained in:
rcourtman
2026-10-06 18:03:55 +01:00
parent 49caa6bbf4
commit 3ca8b9647a
2 changed files with 44 additions and 36 deletions
@@ -1466,39 +1466,3 @@ func TestMonitorDelayedPartialResolutionKeepsDestinationRecovery(t *testing.T) {
t.Fatal("unannounced destination received a recovery")
}
}
func TestSyncAlertsToStateCarriesLiveMetricStatusOfHeldAlert(t *testing.T) {
m := &Monitor{
state: models.NewState(),
alertManager: alerts.NewManagerWithDataDir(t.TempDir()),
}
defer m.alertManager.Stop()
cfg := m.alertManager.GetConfig()
cfg.TimeThresholds = map[string]int{"node": 0}
cfg.NodeDefaults.Temperature = &alerts.HysteresisThreshold{Trigger: 80, Clear: 75}
m.alertManager.UpdateConfig(cfg)
node := models.Node{
ID: "homelab-minipc", Name: "minipc", Instance: "homelab", Status: "online",
Temperature: &models.Temperature{Available: true, CPUPackage: 85},
}
m.alertManager.CheckNode(node)
node.Temperature = &models.Temperature{Available: true, CPUPackage: 78}
m.alertManager.CheckNode(node)
m.syncAlertsToState()
var held *models.Alert
for i, alert := range m.state.GetSnapshot().ActiveAlerts {
if alert.Type == "temperature" {
held = &m.state.GetSnapshot().ActiveAlerts[i]
}
}
require.NotNil(t, held, "expected the temperature alert to stay open at 78°C")
require.Equal(t, 85.0, held.Value, "the legacy value keeps the last breach")
require.NotNil(t, held.MetricStatus, "websocket state must carry the live reading")
require.Equal(t, models.MetricAlertPhaseLatched, held.MetricStatus.Phase)
require.Equal(t, 78.0, held.MetricStatus.Value)
require.Equal(t, 75.0, held.MetricStatus.Recovery)
}
@@ -258,3 +258,47 @@ func TestResolveBackupIntentContextAcceptsSynthesizedJobGuestTask(t *testing.T)
t.Fatalf("guest whose job section already finished should not carry intent: %+v", got)
}
}
func TestSyncAlertsToStateCarriesLiveMetricStatusOfHeldAlert(t *testing.T) {
m := &Monitor{
state: models.NewState(),
alertManager: alerts.NewManagerWithDataDir(t.TempDir()),
}
defer m.alertManager.Stop()
cfg := m.alertManager.GetConfig()
cfg.TimeThresholds = map[string]int{"node": 0}
cfg.NodeDefaults.Temperature = &alerts.HysteresisThreshold{Trigger: 80, Clear: 75}
m.alertManager.UpdateConfig(cfg)
node := models.Node{
ID: "homelab-minipc", Name: "minipc", Instance: "homelab", Status: "online",
Temperature: &models.Temperature{Available: true, CPUPackage: 85},
}
m.alertManager.CheckNode(node)
node.Temperature = &models.Temperature{Available: true, CPUPackage: 78}
m.alertManager.CheckNode(node)
m.syncAlertsToState()
var held *models.Alert
snapshot := m.state.GetSnapshot()
for i := range snapshot.ActiveAlerts {
if snapshot.ActiveAlerts[i].Type == "temperature" {
held = &snapshot.ActiveAlerts[i]
}
}
if held == nil {
t.Fatal("expected the temperature alert to stay open at 78°C")
}
if held.Value != 85 {
t.Fatalf("legacy value = %v, want the last breach 85", held.Value)
}
status := held.MetricStatus
if status == nil {
t.Fatal("websocket state must carry the live reading")
}
if status.Phase != models.MetricAlertPhaseLatched || status.Value != 78 || status.Recovery != 75 {
t.Fatalf("live status = %+v, want latched at 78 clearing at 75", status)
}
}