package web import ( "testing" "time" "gitea.dooplex.hu/admin/felhom-hub/internal/sysfacts" ) // R-840: the "Root files" cell — amber behind, red from the alarm's wait, amber on drift, unknown never coloured as a fact. func TestBundleCell(t *testing.T) { now := time.Date(2026, 10, 4, 20, 0, 0, 0, time.UTC) sys := func(rep string) sysfacts.System { return sysfacts.Parse(rep) } cur := sys(`{"system":{"config_bundle":{"version":"0.143.0","bundle_sha256":"new"}}}`) old := sys(`{"system":{"config_bundle":{"version":"none"}}}`) drift := sys(`{"system":{"config_bundle":{"version":"0.143.0","bundle_sha256":"new"},"facts":{"host":{"config_bundle":{"version":"0.143.0","drift":["/usr/local/sbin/felhom-pbs-apply"]}}}}}`) if c := bundleCell(cur, "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Class != "" || c.Text != "0.143.0" { t.Fatalf("current: %+v", c) } if c := bundleCell(old, "0.143.0", "new", false, now.Add(-time.Hour), 7*24*time.Hour, now); c.Class != "warn" || c.Text != "none" { t.Fatalf("behind 1 h: %+v", c) } if c := bundleCell(old, "0.143.0", "new", false, now.Add(-8*24*time.Hour), 7*24*time.Hour, now); c.Class != "bad" { t.Fatalf("behind 8 days: %+v", c) } if c := bundleCell(drift, "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Class != "warn" || c.Title == "" { t.Fatalf("drift: %+v", c) } if c := bundleCell(sys(`{}`), "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Text != "unknown" { t.Fatalf("no stanza: %+v", c) } } // R-1392 (`09` §3 decision 304): the same files under an older label are not "behind" — no colour, also after the // alarm's wait; a bundle whose files differ stays amber; drift is still amber. func TestBundleCell_R1392(t *testing.T) { now := time.Date(2026, 11, 14, 10, 0, 0, 0, time.UTC) box := sysfacts.Parse(`{"system":{"config_bundle":{"version":"0.172.1","bundle_sha256":"old"}}}`) if c := bundleCell(box, "0.173.0", "new", true, now.Add(-8*24*time.Hour), 7*24*time.Hour, now); c.Class != "" || c.Text != "0.172.1" || c.Title == "" { t.Fatalf("same files, new label: %+v", c) } if c := bundleCell(box, "0.173.0", "new", false, now.Add(-time.Hour), 7*24*time.Hour, now); c.Class != "warn" { t.Fatalf("different files: %+v", c) } drift := sysfacts.Parse(`{"system":{"config_bundle":{"version":"0.172.1","bundle_sha256":"old"},"facts":{"host":{"config_bundle":{"version":"0.172.1","drift":["/etc/sudoers.d/felhom-agent"]}}}}}`) if c := bundleCell(drift, "0.173.0", "new", true, time.Time{}, 7*24*time.Hour, now); c.Class != "warn" { t.Fatalf("drift under the same files: %+v", c) } }