package main
import (
"testing"
"time"
"craftdesign.group/quarry/internal/ingest"
)
// A store nobody wrote is current, not behind: the poller skips its
// rounds, so a tick that found it unmoved stands for a success. A store
// whose last round failed keeps its old success, so it still reads
// failing or behind (2026-10-30: every idle store showed behind after a
// restart).
func TestAnUnmovedStoreCountsAsCurrent(t *testing.T) {
round := time.Now().Add(-90 * time.Minute)
tick := time.Now()
if got := withCurrent(ingest.Stats{LastOK: round}, tick.UnixNano()); !got.LastOK.Equal(time.Unix(0, tick.UnixNano())) {
t.Errorf("FAIL: an unmoved store's last success is %v, not the tick", got.LastOK)
}
if got := withCurrent(ingest.Stats{LastOK: round, Failures: 1}, tick.UnixNano()); !got.LastOK.Equal(round) {
t.Errorf("FAIL: a store whose round failed took the tick as a success")
}
if got := withCurrent(ingest.Stats{LastOK: round, Stalled: true}, tick.UnixNano()); !got.LastOK.Equal(round) {
t.Errorf("FAIL: a stalled store took the tick as a success")
}
if got := withCurrent(ingest.Stats{LastOK: round}, 0); !got.LastOK.Equal(round) {
t.Errorf("FAIL: no tick yet, but the last success moved")
}
}