hub v0.160.0: a live re-enroll mails the operator (R-1156); further refused backups counted, alarm once a day (R-1157); the reinstall's off-site re-issue says what it still does (R-1158)
This commit is contained in:
1 parent
d5e3c8b0d9
commit
503c93fada
10 files changed
+251
-28
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
_ "modernc.org/sqlite"
|
||||
@@ -298,3 +299,76 @@ func TestR1150_BornRefusedAlertsOnce(t *testing.T) {
|
||||
t.Fatalf("born-refused → want exactly [whole_guest_backup_refused], got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func capCadenceRefusedAt(at string) string {
|
||||
return `[{"name":"guest-init-pid","feature":"drive-gate","critical":true,"status":"ok"},` +
|
||||
`{"name":"localapi:backup-cadence-cap","feature":"whole-guest restore points","critical":true,"status":"degraded",` +
|
||||
`"reason":"refused a whole-guest backup of guest 9202 on target \"local\" at ` + at + ` — more than the schedule allows"}]`
|
||||
}
|
||||
|
||||
// R-1157: a guest refused again and again inside one degraded stretch. Each FURTHER refusal (the agent's reason names
|
||||
// a new time) adds to the count; the alarm repeats with the count at most once a day; a steady report (same reason)
|
||||
// adds nothing; the cleared record carries the episode's total.
|
||||
//
|
||||
// COMPANION RED-PROOF (observed 2026-10-19): with the further-refusal branch removed from Check this fails with
|
||||
//
|
||||
// host_capability_test.go: a refusal a day later → want a second whole_guest_backup_refused, got [whole_guest_backup_refused]
|
||||
//
|
||||
// Restored.
|
||||
func TestR1157_FurtherRefusalsAreCountedAndRepeatDaily(t *testing.T) {
|
||||
st := newCapStore(t)
|
||||
st.SaveHostReport("h1", "c1", reportWith(capCadenceOK), store.HostReportDenorm{})
|
||||
var evs []capEvent
|
||||
cc := NewHostCapabilityChecker(st, recordCapEvents(&evs), log.New(io.Discard, "", 0))
|
||||
now := time.Date(2026, 10, 19, 8, 0, 0, 0, time.UTC)
|
||||
cc.now = func() time.Time { return now }
|
||||
report := func(caps string) {
|
||||
st.SaveHostReport("h1", "c1", reportWith(caps), store.HostReportDenorm{})
|
||||
cc.Check()
|
||||
}
|
||||
|
||||
report(capCadenceRefusedAt("2026-10-19T08:00:00Z"))
|
||||
if got := capTypes(evs); len(got) != 1 || got[0] != "whole_guest_backup_refused" {
|
||||
t.Fatalf("first refusal → want [whole_guest_backup_refused], got %v", got)
|
||||
}
|
||||
if !strings.Contains(evs[0].details, `"refusals_in_episode":1`) {
|
||||
t.Errorf("first alarm details lack the count 1: %s", evs[0].details)
|
||||
}
|
||||
|
||||
now = now.Add(2 * time.Hour)
|
||||
report(capCadenceRefusedAt("2026-10-19T08:00:00Z")) // the same refusal reported again
|
||||
now = now.Add(time.Hour)
|
||||
report(capCadenceRefusedAt("2026-10-19T11:00:00Z")) // a second refusal, 3 h after the alarm
|
||||
if len(evs) != 1 {
|
||||
t.Fatalf("a second refusal within the day must be counted, not alarmed: got %v", capTypes(evs))
|
||||
}
|
||||
|
||||
now = now.Add(22 * time.Hour)
|
||||
report(capCadenceRefusedAt("2026-10-20T09:00:00Z")) // a third refusal, a day after the first alarm
|
||||
if got := capTypes(evs); len(got) != 2 || got[1] != "whole_guest_backup_refused" {
|
||||
t.Fatalf("a refusal a day later → want a second whole_guest_backup_refused, got %v", got)
|
||||
}
|
||||
e := evs[1]
|
||||
if e.severity != "warning" || !strings.Contains(e.message, "still being refused — 3 refusals") {
|
||||
t.Errorf("the repeat must say the count in plain words: %s %q", e.severity, e.message)
|
||||
}
|
||||
if !strings.Contains(e.details, `"refusals_in_episode":3`) || !strings.Contains(e.details, "2026-10-19T08:00:00Z") || !strings.Contains(e.details, "2026-10-20T09:00:00Z") {
|
||||
t.Errorf("the repeat's details must carry the count, the first and the newest refusal: %s", e.details)
|
||||
}
|
||||
|
||||
now = now.Add(time.Hour)
|
||||
report(capCadenceRefusedAt("2026-10-20T10:00:00Z"))
|
||||
report(capCadenceOK)
|
||||
if got := capTypes(evs); len(got) != 3 || got[2] != "whole_guest_backup_refusal_cleared" {
|
||||
t.Fatalf("window ended → want [.. whole_guest_backup_refusal_cleared], got %v", got)
|
||||
}
|
||||
if !strings.Contains(evs[2].details, `"refusals_in_episode":4`) {
|
||||
t.Errorf("the cleared record must carry the episode's total 4: %s", evs[2].details)
|
||||
}
|
||||
|
||||
// A new episode starts at 1 again.
|
||||
report(capCadenceRefusedAt("2026-10-21T08:00:00Z"))
|
||||
if len(evs) != 4 || !strings.Contains(evs[3].details, `"refusals_in_episode":1`) {
|
||||
t.Fatalf("a new episode must start at 1: %v %s", capTypes(evs), evs[len(evs)-1].details)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user