test: make pack fixture deterministic via git pack-objects

Incremental 'git repack' consolidates small packs on newer git builds
(CI produced 3 packs from 6 commits), making the sprawl fixture count
nondeterministic. pack-objects with an explicit sha per commit creates
exactly one pack each on every git version.
This commit is contained in:
Teknium
2026-08-17 02:43:30 -07:00
parent 25c051d480
commit 31fe024e93

View File

@@ -92,13 +92,21 @@ class TestMaintainPackHealth:
return len(list((repo / ".git" / "objects" / "pack").glob("*.pack")))
def _make_packs(self, repo, n):
"""Create n distinct packs by committing + repacking incrementally."""
"""Create exactly n distinct packs via git pack-objects (deterministic
across git versions — incremental `git repack` consolidates small
packs on newer CI git builds, which made the count nondeterministic)."""
pack_dir = repo / ".git" / "objects" / "pack"
pack_dir.mkdir(parents=True, exist_ok=True)
for i in range(n):
(repo / f"p{i}.txt").write_text(f"{i}\n")
_git(repo, "add", "-A")
_git(repo, "commit", "-qm", f"c{i}")
# `repack` without -a packs only loose objects → one new pack.
_git(repo, "repack", "-q")
sha = _git(repo, "rev-parse", f"HEAD^{{commit}}").stdout.strip()
# One pack per commit object: pipe the sha into pack-objects.
subprocess.run(
["git", "pack-objects", "-q", str(pack_dir / f"tpack{i}")],
input=f"{sha}\n", cwd=str(repo), capture_output=True, text=True, check=True,
)
return self._pack_count(repo)
def test_repacks_at_threshold(self, repo, monkeypatch):