package main
import (
"path/filepath"
"testing"
"time"
"craftdesign.group/quarry/internal/index"
)
// A store whose tip archive was refused for its size is not built again
// for a week, whatever its tip does; after that it is tried once more.
func TestAnOversizeTreeWaitsAWeek(t *testing.T) {
ix, err := index.Open(filepath.Join(t.TempDir(), "index.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { ix.Close() })
now := time.Date(2026, 10, 24, 14, 0, 0, 0, time.UTC)
if treeRefusedRecently(ix, now) {
t.Fatal("FAIL: a store never refused is held back")
}
if err := ix.TreeRefused("tip-a", 768<<20, now.Add(-time.Hour)); err != nil {
t.Fatal(err)
}
if !treeRefusedRecently(ix, now) {
t.Error("FAIL: an hour after a refusal the indexer would build it again")
}
if treeRefusedRecently(ix, now.Add(7*24*time.Hour)) {
t.Error("FAIL: a week after a refusal the indexer still holds back")
}
}