package api
import (
"testing"
)
// divergeRecorder is a MirrorStore that only remembers divergence calls.
type divergeRecorder struct {
memMirrors
calls []string
}
func (r *divergeRecorder) MirrorDiverged(repo, checkin string) error {
r.calls = append(r.calls, repo+"@"+checkin)
return nil
}
// The sync gate calls Deps.MirrorDiverged whenever it admits a push and
// need not ask first: a forge without a mirror store, or a repository
// that is not a tracking mirror, records nothing; a tracking mirror
// records the check-in (5d40f151).
func TestTheGateNeedNotAskBeforeReportingDivergence(t *testing.T) {
Deps{}.MirrorDiverged("native", "aaaa1111")
rec := &divergeRecorder{memMirrors: memMirrors{}}
_ = rec.SetMirror("tracked", "https://upstream.example/t", 3600)
_ = rec.SetMirror("forked", "https://upstream.example/f", 3600)
_ = rec.DetachMirror("forked")
d := Deps{Mirrors: rec}
d.MirrorDiverged("native", "aaaa1111")
d.MirrorDiverged("forked", "bbbb2222")
d.MirrorDiverged("tracked", "cccc3333")
if len(rec.calls) != 1 || rec.calls[0] != "tracked@cccc3333" {
t.Fatalf("FAIL: recorded %v, want only tracked@cccc3333", rec.calls)
}
t.Log("ok: native and detached stores record nothing; the tracking one records the check-in")
}