package backup import ( "testing" "time" ) // R-351 — A FINISHED RESTORE MUST BE VISIBLE TO SOMEONE WHO WAS NOT WATCHING. // // THE MEASURED CASE (demo-hp, 2026-08-21). An off-box reconstitution refused at 16:37:14, the person // reinstalled and ran the local unit restore, and it completed at 16:39:25 — in 8.666s. No screen // ever said so. The banner's JS gated its terminal result on a page-local `sawRunning` flag, so the // result was rendered only for a browser that happened to be open and polling across the transition. // Land on the page a moment later and the banner stayed hidden: "completed" and "never ran" looked // identical. The answer existed only in `docker logs felhom-controller`, which a customer cannot // reach. // // This pins the CONSEQUENCE — the status carries a recency verdict a late arrival can act on — not // the mechanism. Mutating LastRecent to stay false must fail this test. func TestRestoreStatus_LastRecent(t *testing.T) { for _, tc := range []struct { name string finishedAt time.Time wantRecent bool why string }{ { name: "just finished", finishedAt: time.Now().Add(-9 * time.Second), wantRecent: true, why: "the 8.7s OpenGist restore: finished before a poll could see it running", }, { name: "inside the window", finishedAt: time.Now().Add(-RestoreResultWindow + time.Minute), wantRecent: true, why: "still answers \"what just happened\"", }, { name: "outside the window", finishedAt: time.Now().Add(-RestoreResultWindow - time.Minute), wantRecent: false, why: "landing here later must not claim a restore just finished", }, { name: "unstamped result", finishedAt: time.Time{}, wantRecent: false, why: "a zero timestamp is an UNKNOWN and must never be drawn as \"just now\" (presence is not success)", }, } { t.Run(tc.name, func(t *testing.T) { m := &Manager{} m.opLast = &RestoreOpResult{ Op: "restore", Stack: "opengist", OK: true, Message: "Restore completed", FinishedAt: tc.finishedAt, } st := m.RestoreStatus() if st.Last == nil { t.Fatal("fixture: the status must carry the terminal result") } if st.LastRecent != tc.wantRecent { t.Errorf("LastRecent = %v, want %v — %s", st.LastRecent, tc.wantRecent, tc.why) } }) } } // A RUNNING op must not be reported as a recent RESULT — the banner shows one or the other, and // conflating them would put a success message over an operation that is still writing. func TestRestoreStatus_RunningIsNotAResult(t *testing.T) { m := &Manager{} m.BeginRestoreOp("offbox-reconstitute", "opengist") st := m.RestoreStatus() if !st.Running { t.Fatal("fixture: the op must be reported running") } if st.Last != nil { t.Errorf("a fresh op has no terminal result yet, got %+v", st.Last) } if st.LastRecent { t.Error("a running op must never carry a recent-result verdict") } }