From e2d865d41b236fe031cb49dea373dc59be2486b5 Mon Sep 17 00:00:00 2001 From: ChuckBuilds Date: Tue, 11 Aug 2026 18:41:36 -0400 Subject: [PATCH] fix(cache): count swept temp files as scanned files_scanned only counted completed .json files, so a sweep that removed orphans reported more deleted than it had looked at -- the summary line renders "/", which came out as "76/1". Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01Udr6MfaFLUPhX5Fgo67Jf5 --- src/cache/disk_cache.py | 4 ++++ test/test_cache_orphan_temp_sweep.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cache/disk_cache.py b/src/cache/disk_cache.py index b67c10b2..03cfb2f1 100644 --- a/src/cache/disk_cache.py +++ b/src/cache/disk_cache.py @@ -423,6 +423,10 @@ class DiskCache: # directory, the oldest six months old. stats['orphan_temp_files_deleted'] = 0 for filename in (f for f in entries if self._is_orphaned_temp(f)): + # Counted as scanned like any other candidate, so files_deleted + # can never exceed files_scanned and the summary line reads + # honestly ("77/8864", not "77/0"). + stats['files_scanned'] += 1 path = os.path.join(self.cache_dir, filename) try: # An in-flight write lives for milliseconds, so anything diff --git a/test/test_cache_orphan_temp_sweep.py b/test/test_cache_orphan_temp_sweep.py index e45e1719..f35579d6 100644 --- a/test/test_cache_orphan_temp_sweep.py +++ b/test/test_cache_orphan_temp_sweep.py @@ -152,6 +152,19 @@ class TestTheSweep: assert stats['orphan_temp_files_deleted'] == 76 assert keep.exists() assert not list(tmp_path.glob('.sched_*')) + # The summary line is "/", so an orphan that is + # deleted but never counted as scanned renders as "76/1". + assert stats['files_scanned'] == 77 + assert stats['files_deleted'] <= stats['files_scanned'] + + def test_deleted_never_exceeds_scanned(self, cache, tmp_path): + p = _write(tmp_path, '.only.json.a1b2c3d4') + _age(p, _ORPHAN_TEMP_MAX_AGE_SECONDS + 60) + + stats = cache.cleanup_expired_files(FakeStrategy(), POLICIES) + + assert stats['files_deleted'] == 1 + assert stats['files_scanned'] == 1 def test_a_missing_file_mid_sweep_is_not_an_error(self, cache, tmp_path): p = _write(tmp_path, '.weather.json.a1b2c3d4')