gates / gates (push) Successful in 2m20s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
78 lines
3.8 KiB
Go
78 lines
3.8 KiB
Go
package osupdates
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func cleanupReport(detail string) Report {
|
|
r := Report{Layer: LayerKernel, Trigger: "night", Mode: ModeKernelCleanup, Outcome: "cleaned", Healthy: true,
|
|
ReleaseID: "kernel-cleanup", HealthReason: "removed 2 old kernel package(s): …"}
|
|
if detail != "" {
|
|
r.KernelCleanup = json.RawMessage(detail)
|
|
}
|
|
return r
|
|
}
|
|
|
|
// R-1383 (release 3). A clean-up and a kernel step are both kernel-layer reports. Before this the System page showed
|
|
// the NEWEST of the two as „the step”: a clean-up the night after a kernel fell back replaced the amber „fell_back”
|
|
// line with „cleaned”. The stored effect asserted: the step line still reads the step; the clean-up has its own
|
|
// fields with what it removed, kept and gained; the detail survives the hub's re-marshal of the report; and the
|
|
// clean-up changes nothing the kernel lane decides on (it names no kernel).
|
|
// COMPANION RED-PROOFS (observed, audits/night-build-2026-11-14/B/redproof-hub-b3.txt).
|
|
func TestKernelLine_CleanupBesideTheStep(t *testing.T) {
|
|
f := newFix(t)
|
|
f.hostWithPendingKernel(t, "hp")
|
|
f.laneFacts(t, "hp", "c-hp", kOld, "fell_back", kNew)
|
|
f.ingest(t, "hp", kreport("fell_back", "boot", false))
|
|
dueBefore, whyBefore := f.s.KernelDue("hp")
|
|
if l := f.s.KernelLineFor("hp"); l.CleanupOutcome != "" || l.LastOutcome != "fell_back" {
|
|
t.Fatalf("before any clean-up: %+v", l)
|
|
}
|
|
const detail = `{"removed":["proxmox-kernel-7.0.14-20-pve-signed","proxmox-kernel-7.0.2-6-pve-signed"],"kept":["7.0.14-22-pve","7.0.14-26-pve"],"bytes_gained":2147483648,"leftovers":0}`
|
|
f.now = f.now.Add(24 * 60 * 60 * 1e9)
|
|
rep := cleanupReport(detail)
|
|
rep.RunID = "cleanup-1"
|
|
f.ingest(t, "hp", rep)
|
|
|
|
l := f.s.KernelLineFor("hp")
|
|
if l.LastOutcome != "fell_back" || l.LastKernel != kNew {
|
|
t.Fatalf("the clean-up HID the step: the step line reads %q for %q, want fell_back for %s", l.LastOutcome, l.LastKernel, kNew)
|
|
}
|
|
if l.CleanupOutcome != "cleaned" || l.Cleanup == nil || len(l.Cleanup.Removed) != 2 || len(l.Cleanup.Kept) != 2 ||
|
|
l.Cleanup.BytesGained == nil || *l.Cleanup.BytesGained != 2147483648 || l.Cleanup.Removed[0] != "proxmox-kernel-7.0.14-20-pve-signed" {
|
|
t.Fatalf("the clean-up's own fields: outcome %q detail %+v", l.CleanupOutcome, l.Cleanup)
|
|
}
|
|
// the detail is in the STORED report (Ingest re-marshals the struct: a field the struct lacks is lost)
|
|
stored, _ := f.s.Store.LatestOSReport("hp", LayerKernel)
|
|
if stored == nil || stored.Mode != ModeKernelCleanup || !strings.Contains(stored.ReportJSON, `"kernel_cleanup":{"removed":["proxmox-kernel-7.0.14-20-pve-signed"`) {
|
|
t.Fatalf("the stored report lost the detail: %+v", stored)
|
|
}
|
|
// and it is not a step for any kernel: the lane's verdict did not move
|
|
var kr Report
|
|
_ = json.Unmarshal([]byte(stored.ReportJSON), &kr)
|
|
if k := kernelOf(kr); k != "" {
|
|
t.Fatalf("the clean-up report reads as a step for kernel %q", k)
|
|
}
|
|
if due, why := f.s.KernelDue("hp"); due != dueBefore || why != whyBefore {
|
|
t.Fatalf("the clean-up moved the kernel lane: due %q→%q, why %q→%q", dueBefore, due, whyBefore, why)
|
|
}
|
|
// a later step is the step line again, and the clean-up line stays
|
|
f.now = f.now.Add(24 * 60 * 60 * 1e9)
|
|
st := kreport("applied", "boot", true)
|
|
st.RunID = "step-2"
|
|
f.ingest(t, "hp", st)
|
|
if l := f.s.KernelLineFor("hp"); l.LastOutcome != "applied" || l.CleanupOutcome != "cleaned" || l.Cleanup == nil {
|
|
t.Fatalf("after a later step: %+v", l)
|
|
}
|
|
// an agent of release 2a sends no detail: the outcome and the reason text are still shown, the detail is nil
|
|
f2 := newFix(t)
|
|
old := cleanupReport("")
|
|
old.RunID = "cleanup-old"
|
|
f2.ingest(t, "hp", old)
|
|
if l := f2.s.KernelLineFor("hp"); l.CleanupOutcome != "cleaned" || l.Cleanup != nil || !strings.Contains(l.CleanupReason, "removed 2 old kernel") || l.LastOutcome != "" {
|
|
t.Fatalf("a clean-up without detail (agent 0.174.0): %+v", l)
|
|
}
|
|
}
|