From 651cabf412cf7cd53e76fe27f2d32c1ed0b7556c Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:27:36 +0100 Subject: [PATCH] fix: rank orphaned and moved pins first in triage drift_score ignored orphaned pins and moved repositories although triage_state says they are fixed before any ref is read: pcem ranked last at 0 with an upstream_commit on no branch. Each now weighs more than a GONE ref. --- scripts/profile_sync.py | 5 +++++ tests/test_profile_sync.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 1d2b81f38..e46a0e44b 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -2627,6 +2627,7 @@ def tree_diff(result: CompareResult, ref_dirs: set[str]) -> list[str]: DRIFT_WEIGHTS = {"GONE": 40, "CHANGED": 30, "AMBIGUOUS": 15, "SHIFTED": 1} +PIN_WEIGHT = 50 def drift_score( @@ -2644,6 +2645,10 @@ def drift_score( if version is not None and not version.tag_matches_declared: if version.latest_release and version.latest_release != version.declared: score += 10 + # A pin off its branch or a repository answering under another name is + # set again before any ref can be read, so each outranks a GONE ref: + # pcem ranked last at 0 with an orphaned upstream_commit. + score += PIN_WEIGHT * (len(report.orphaned) + len(report.moved_repos)) score += min(commits, 20) // 4 return score diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index a9d71c062..147670577 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -3812,6 +3812,18 @@ class TestDriftScore(unittest.TestCase): report = ProfileReport(name="a", entries=[], counts={"ANCHORED": 5}) self.assertEqual(drift_score(report, None, 0), 0) + def test_a_pin_to_set_again_outranks_a_gone_ref(self): + """pcem ranked last at 0 with "1 to review, 1 orphaned pin": its + upstream_commit had left every branch of a force-pushed repository.""" + gone = ProfileReport(name="a", entries=[], counts={"GONE": 1}) + orphaned = ProfileReport(name="pcem", entries=[], counts={}, + orphaned=["upstream_commit 25b54e3f"]) + moved = ProfileReport(name="m", entries=[], counts={}, + moved_repos=["a/b answers as c/b"]) + for report in (orphaned, moved): + with self.subTest(name=report.name): + self.assertGreater(drift_score(report, None, 0), drift_score(gone, None, 0)) + class TestCollectCitations(unittest.TestCase): def test_files_refs_in_document_order(self):