Artifact 54f6667bb0a4deaa9525aad7d6b3535e5103ae35a2c89ca603c2f193f5ec8e06:
- File
internal/web/opshealth_test.go
— part of check-in
[e2b74749b4]
at
2026-08-25 22:19:15
on branch fleet-census
— Analytics: say whether history is being kept, and stop keeping it for ever
The live panels read in-memory rings, so a forge whose store failed to open looked exactly like a healthy one. Sink.Err() existed and nothing asked it. The page now distinguishes three states: off, broken, and recording to a named path.
Retention was 'append for ever', which is a default nobody was asked about. --analytics-keep sets the window, 14d by default, 0 keeps everything. Pruned at startup and daily. (user: dmestas, size: 2551) [annotate] [blame] [check-ins using]
package web import ( "bytes" "strings" "testing" ) // renderOps executes the operations page far enough to read the prose // about the durable store. The panels themselves are fed by rings and // render the same whatever the store is doing — which is the whole // reason this line has to exist. func renderOps(t *testing.T, v opsView) string { t.Helper() var buf bytes.Buffer if err := opsPage.ExecuteTemplate(&buf, "ops-body", pageData{Title: "operations", Ops: v}); err != nil { t.Fatal(err) } return buf.String() } // Off is a choice; broken is a fault. A panel that renders identically // for both teaches an operator to trust a forge that is recording // nothing — which is how the reserved-word schema failure would have // reached production instead of a test run. func TestOpsPageSaysWhenHistoryIsOff(t *testing.T) { var v opsView v.BudgetMs = 500 body := renderOps(t, v) if !strings.Contains(body, "History is off") { t.Errorf("an unconfigured store renders no notice:\n%s", body) } if strings.Contains(body, "NOT being recorded") { t.Error("switched off is reported as a failure") } } func TestOpsPageSaysWhenHistoryIsBroken(t *testing.T) { var v opsView v.BudgetMs = 500 v.Store.Configured = true v.Store.Path = "/data/ops.duckdb" v.Store.Err = "schema: at is reserved" body := renderOps(t, v) if !strings.Contains(body, "NOT being recorded") { t.Errorf("a broken store renders no warning:\n%s", body) } if !strings.Contains(body, "schema: at is reserved") { t.Error("the warning does not say what went wrong") } if !strings.Contains(body, "ci-fail-text") { t.Error("the warning is not marked as a failure") } if strings.Contains(body, "History is off") { t.Error("a broken store is reported as switched off") } } func TestOpsPageNamesTheStoreAndItsWindow(t *testing.T) { var v opsView v.BudgetMs = 500 v.Store.Configured = true v.Store.Path = "/data/ops.duckdb" v.Store.Kept = "14d" body := renderOps(t, v) if !strings.Contains(body, "/data/ops.duckdb") { t.Errorf("a healthy store is not named:\n%s", body) } if !strings.Contains(body, "kept for 14d") { t.Error("the retention window is not stated, so nobody was asked about it") } if strings.Contains(body, "NOT being recorded") || strings.Contains(body, "History is off") { t.Error("a healthy store renders a fault") } // Retention off must not render a dangling "kept for". v.Store.Kept = "" if body := renderOps(t, v); strings.Contains(body, "kept for") { t.Error("retention off still renders a window") } }