hub (unreleased): the System page shows the kernel clean-up and the security-profile refresh; a clean-up no longer hides a kernel step (R-1383)
gates / gates (push) Successful in 2m20s
gates / gates (push) Successful in 2m20s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
e5c643d73d
commit
68292e40f6
14 files changed
+452
-13
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/osupdates"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/sysfacts"
|
||||
)
|
||||
|
||||
// R-1383 (release 3): the two new cells of the System page, from what a box really sends.
|
||||
// COMPANION RED-PROOFS (observed, audits/night-build-2026-11-14/B/redproof-hub-b3.txt).
|
||||
func TestSystemCells_KernelCleanupAndSecurityProfiles(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 6, 0, 0, 0, time.UTC)
|
||||
gained := int64(6442450944)
|
||||
// --- the clean-up ---
|
||||
if c := cleanupCell(osupdates.KernelLine{}, now); c.Text != "—" || c.Class != "" {
|
||||
t.Errorf("no clean-up reported: %+v (a box with nothing to remove reports none — not a fault)", c)
|
||||
}
|
||||
kl := osupdates.KernelLine{CleanupOutcome: "cleaned", CleanupAt: now.Add(-3 * time.Hour), CleanupReason: "removed 6 …",
|
||||
Cleanup: &osupdates.CleanupDetail{Removed: []string{"proxmox-kernel-7.0.2-6-pve-signed", "b", "c", "d", "e", "f"},
|
||||
Kept: []string{"7.0.14-26-pve", "7.0.14-28-pve"}, BytesGained: &gained}}
|
||||
c := cleanupCell(kl, now)
|
||||
for _, want := range []string{"removed 6, kept 2", "6.0 GiB gained", "3"} {
|
||||
if !strings.Contains(c.Text, want) {
|
||||
t.Errorf("clean-up cell %q lacks %q", c.Text, want)
|
||||
}
|
||||
}
|
||||
if c.Class != "" || !strings.Contains(c.Title, "proxmox-kernel-7.0.2-6-pve-signed") || !strings.Contains(c.Title, "kept: 7.0.14-26-pve, 7.0.14-28-pve") {
|
||||
t.Errorf("clean-up cell = %+v, want no colour and the names in the title", c)
|
||||
}
|
||||
kl.Cleanup.Leftovers = 2
|
||||
if c := cleanupCell(kl, now); c.Class != "warn" || !strings.Contains(c.Text, "2 left-over path(s)") {
|
||||
t.Errorf("left-over paths must be amber and named: %+v", c)
|
||||
}
|
||||
kl.Cleanup = nil // an agent of release 2a
|
||||
if c := cleanupCell(kl, now); !strings.HasPrefix(c.Text, "cleaned ") || c.Title != "removed 6 …" {
|
||||
t.Errorf("a clean-up without detail: %+v", c)
|
||||
}
|
||||
for _, bad := range []string{"refused", "failed"} {
|
||||
if c := cleanupCell(osupdates.KernelLine{CleanupOutcome: bad, CleanupAt: now.Add(-time.Hour), CleanupReason: "K4: the phase is judging"}, now); c.Class != "warn" || !strings.HasPrefix(c.Text, bad) || c.Title != "K4: the phase is judging" {
|
||||
t.Errorf("%s clean-up: %+v, want amber with the reason", bad, c)
|
||||
}
|
||||
}
|
||||
// --- the security profiles: parsed from a host report, as the page gets it ---
|
||||
if c := profileCell(sysfacts.Parse(`{"host_id":"x"}`), now); c.Text != "—" || c.Class != "" {
|
||||
t.Errorf("no stanza: %+v", c)
|
||||
}
|
||||
f := sysfacts.Parse(`{"profile_refresh":{"kernel":"7.0.14-28-pve","at":"2026-11-14T11:30:11Z","rewritten":2,"restarted":["chrony.service"],"last_ask":"refreshed","last_ask_at":"2026-11-14T11:30:11Z"}}`)
|
||||
c = profileCell(f, now)
|
||||
for _, want := range []string{"7.0.14-28-pve", "2 rewritten", "restarted chrony.service"} {
|
||||
if !strings.Contains(c.Text, want) {
|
||||
t.Errorf("profile cell %q lacks %q", c.Text, want)
|
||||
}
|
||||
}
|
||||
if c.Class != "" {
|
||||
t.Errorf("a good refresh must have no colour: %+v", c)
|
||||
}
|
||||
for _, ask := range []string{"failed", "no_answer"} {
|
||||
f = sysfacts.Parse(`{"profile_refresh":{"kernel":"7.0.14-28-pve","at":"2026-11-14T11:30:11Z","rewritten":2,"last_ask":"` + ask + `","last_ask_at":"2026-11-15T05:00:00Z"}}`)
|
||||
if c := profileCell(f, now); c.Class != "warn" || !strings.Contains(c.Text, "last ask "+strings.ToUpper(ask)) || !strings.Contains(c.Text, "2 rewritten") {
|
||||
t.Errorf("last ask %s: %+v, want amber, the failed ask AND the older record", ask, c)
|
||||
}
|
||||
}
|
||||
f = sysfacts.Parse(`{"profile_refresh":{"last_ask":"refused","last_ask_at":"2026-11-15T05:00:00Z"}}`)
|
||||
if c := profileCell(f, now); c.Class != "" || c.Text != "no refresh yet" || !strings.Contains(c.Title, "older root wrapper") {
|
||||
t.Errorf("a refused ask (an older wrapper) is not a fault: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
// Both cells are on the rendered page, under their names, and a failed ask reaches „Needs attention”.
|
||||
func TestSystemPage_ShowsCleanupAndProfiles(t *testing.T) {
|
||||
in := fixtureInput(true)
|
||||
gained := int64(1073741824)
|
||||
in.KernelLines = map[string]osupdates.KernelLine{"demo-hp-d4e5f6": {CleanupOutcome: "cleaned", CleanupAt: in.Now.Add(-2 * time.Hour),
|
||||
Cleanup: &osupdates.CleanupDetail{Removed: []string{"proxmox-kernel-7.0.14-20-pve-signed"}, Kept: []string{"7.0.14-23-pve"}, BytesGained: &gained}}}
|
||||
f := in.Facts["demo-hp-d4e5f6"]
|
||||
f.ProfileRefresh = &sysfacts.ProfileRefresh{Kernel: "7.0.14-23-pve", At: in.Now.Add(-5 * time.Hour).UTC().Format(time.RFC3339), Rewritten: 1,
|
||||
Restarted: []string{"chrony.service"}, LastAsk: "failed", LastAskAt: in.Now.Add(-time.Hour).UTC().Format(time.RFC3339)}
|
||||
in.Facts["demo-hp-d4e5f6"] = f
|
||||
page := renderSystem(t, in)
|
||||
for _, want := range []string{">Kernel clean-up</dt>", ">Security profiles</dt>", "removed 1, kept 1", "1.0 GiB gained",
|
||||
"restarted chrony.service", "last ask FAILED"} {
|
||||
if !strings.Contains(page, want) {
|
||||
t.Errorf("the System page lacks %q", want)
|
||||
}
|
||||
}
|
||||
if att := sysSection(page, "attention"); !strings.Contains(att, "security profiles") {
|
||||
t.Errorf("a failed ask of the profile refresh is not under „Needs attention”")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user