From 2a13e3ee116d6c80e333b89eb6a7add9ab647917 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 03:53:12 +0200 Subject: [PATCH] fix: recount commits touching a path once stale The commit list behind the triage drift score was cached for good, so pushes upstream never moved a profile up the triage. It now expires like the other moving answers. --- scripts/upstream.py | 4 +++- tests/test_upstream.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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):