feat(operations): cargo cache force purge ("empty all")

purge_cargo_cache gains force: bool. The default age-based purge only
ever removed entries past the configured retention window, which read
as a lie when a user expected "purge" to clear everything -- force=True
sets the cutoff a day in the future so every existing entry is treated
as expired, backing the web UI's explicit "Empty all" action. A
disabled cache stays untouched either way.
This commit is contained in:
2026-07-24 22:04:31 +02:00
parent 4541dccf9c
commit 2395e3e79f
2 changed files with 52 additions and 3 deletions
+35
View File
@@ -178,6 +178,41 @@ def test_purge_cargo_cache_nothing_to_purge(tmp_path: Path) -> None:
assert fresh.exists()
def test_purge_cargo_cache_force_removes_everything_regardless_of_age(tmp_path: Path) -> None:
root = tmp_path / "cache" / "cargo"
fresh = _seed_entry(root, "new", age_days=0) # brand-new, well within retention
mid = _seed_entry(root, "mid", age_days=1)
config = _make_config(root, retention_days=30) # retention alone would spare both
result = purge_cargo_cache(config, force=True)
assert result.removed_entries == 2
assert not fresh.exists()
assert not mid.exists()
def test_purge_cargo_cache_force_dry_run_counts_all_but_keeps_files(tmp_path: Path) -> None:
root = tmp_path / "cache" / "cargo"
fresh = _seed_entry(root, "new", age_days=0, size=2 * 1024 * 1024)
config = _make_config(root, retention_days=30)
result = purge_cargo_cache(config, force=True, dry_run=True)
assert result == PurgeResult(removed_entries=1, freed_bytes=2 * 1024 * 1024, dry_run=True)
assert fresh.exists(), "force dry_run must not delete anything"
def test_purge_cargo_cache_force_disabled_still_zero(tmp_path: Path) -> None:
root = tmp_path / "cache" / "cargo"
old = _seed_entry(root, "old", age_days=1)
config = _make_config(root, enabled=False, retention_days=30)
result = purge_cargo_cache(config, force=True)
assert result == PurgeResult(removed_entries=0, freed_bytes=0, dry_run=False)
assert old.exists()
def test_purge_cargo_cache_missing_root_is_not_an_error(tmp_path: Path) -> None:
root = tmp_path / "cache" / "cargo"
config = _make_config(root, retention_days=30)