diff --git a/scripts/upstream.py b/scripts/upstream.py index 2a27fce6..efcbfdff 100644 --- a/scripts/upstream.py +++ b/scripts/upstream.py @@ -773,7 +773,9 @@ def commits_touching( f"{repo.api_base}/repos/{repo.slug}/commits" f"?path={quoted}&since={stamp}&limit=100" ) - payload = _api(url, cache_dir, offline) + # The list grows with every push touching the path: cached for good, the + # triage drift score stayed at whatever the first run counted. + payload = _api(url, cache_dir, offline, MOVING_TTL) if not isinstance(payload, list): return 0 return sum( diff --git a/tests/test_upstream.py b/tests/test_upstream.py index 2eded270..fa08749d 100644 --- a/tests/test_upstream.py +++ b/tests/test_upstream.py @@ -648,6 +648,30 @@ class TestCompare(unittest.TestCase): upstream.commits_touching(self.repo, "a.c", "tip", self.dir, head="tip"), 0 ) + def test_commits_touching_is_recounted_once_stale(self): + """The list grows with every push: cached for good, the triage drift + score stayed at what the first run counted.""" + import os as _os + + served = { + "commits/base": {"commit": {"committer": {"date": "2026-01-01T00:00:00Z"}}}, + } + listing = [{"sha": "1"}] + + def answer(url): + for key, value in served.items(): + if url.endswith(key): + return value + return list(listing) + + upstream._http_json = answer + self.assertEqual(upstream.commits_touching(self.repo, "a.c", "base", self.dir), 1) + for cached in (Path(self.dir) / "_api").glob("*.json"): + stale = _os.path.getmtime(cached) - upstream.MOVING_TTL - 1 + _os.utime(cached, (stale, stale)) + listing.extend([{"sha": "2"}, {"sha": "3"}]) + self.assertEqual(upstream.commits_touching(self.repo, "a.c", "base", self.dir), 3) + class TestGitlabTree(unittest.TestCase): def setUp(self):