package oltp
import (
"testing"
"time"
)
// A push admitted onto a tracking store means it holds check-ins the
// upstream lacks. The time of the last admitted round is kept, a hash
// when the gate had one, and detaching — the fork made official —
// clears both (5d40f151).
func TestAMirrorCountsCheckinsItsUpstreamLacks(t *testing.T) {
d := openTest(t)
if err := d.SetMirror("w", "https://example.invalid/w", time.Hour); err != nil {
t.Fatal(err)
}
at := time.Date(2026, 9, 23, 3, 0, 0, 0, time.UTC)
for i, h := range []string{"aaaa1111", "", ""} {
if err := d.MirrorDiverged("w", h, at.Add(time.Duration(i)*time.Minute)); err != nil {
t.Fatal(err)
}
}
m, ok, err := d.MirrorFor("w")
if err != nil || !ok {
t.Fatalf("MirrorFor: %v %v", ok, err)
}
if m.DivergedAt != "2026-09-23T03:02:00Z" || m.DivergedLast != "aaaa1111" {
t.Fatalf("FAIL: divergedAt=%q last=%q, want the third round's time and the one hash given", m.DivergedAt, m.DivergedLast)
}
if err := d.DetachMirror("w"); err != nil {
t.Fatal(err)
}
m, _, _ = d.MirrorFor("w")
if m.DivergedAt != "" || m.DivergedLast != "" {
t.Fatalf("FAIL: detach kept divergedAt=%q last=%q", m.DivergedAt, m.DivergedLast)
}
t.Log("ok: the last round's time kept, a hash kept when given and not blanked by rounds without one, detach clears")
}