From 9bfede39ba4ff4448092613d69f6be462ebf6acf Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 16 Oct 2026 12:23:37 +0200 Subject: [PATCH] fix: hold the pin while a ref awaits its recale --- scripts/profile_sync.py | 17 ++++++++++++++--- tests/test_profile_sync.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index f706b89b..a8210246 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -2463,11 +2463,23 @@ def pending_recale( revision, whatever the reason it was not rewritten. """ movable = REBASE_STATUSES + (("CHANGED",) if accept_changed else ()) + document = yaml.safe_load(text) if text is not None else None + # A ref the writer regenerates is pending only while the file still + # carries it as written: a bump run without the recale left lrps2's + # SHIFTED refs on the old lines under the new pin. + refs_left = ( + {c.ref for c in collect_citations(document) if c.kind == "ref"} + if document is not None else set() + ) pending = 0 for entry in report.entries or []: if entry.kind == "prose": continue - if _is_rewritable(entry.source_ref) and not entry.name.endswith("]"): + if ( + _is_rewritable(entry.source_ref) + and not entry.name.endswith("]") + and entry.source_ref not in refs_left + ): continue pending += sum( 1 @@ -2476,10 +2488,9 @@ def pending_recale( and part.start is not None and _rendered_part(part) != _original_part(part) ) - if text is None: + if document is None: return pending - document = yaml.safe_load(text) pool: dict[tuple[str, str], int] = {} for citation in collect_citations(document): if citation.kind == "prose": diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index e1f659db..047f3ed9 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -2631,6 +2631,20 @@ class TestBumpCommit(unittest.TestCase): self.assertEqual(profile_sync.pending_recale(report), 0) self.assertTrue(bump_commit(self.path, report)) + def test_a_bump_alone_waits_for_the_recale(self): + """lrps2 at 0 to review with two SHIFTED parts: --bump-commit run + alone wrote the new pin over refs still on the old lines.""" + part = PartResult(RefPart("a.c", 10, 12, "a.c:10-12"), "SHIFTED", None, 30, 32, []) + report = ProfileReport( + name="p", repo="o/n", pin="pin", head="newhead", + entries=[EntryReport("a.bin", "a.c:10-12", "SHIFTED", [part])], + counts={"SHIFTED": 1}, + ) + self.assertFalse(bump_commit(self.path, report)) + self.assertNotIn("newhead", self.path.read_text()) + self.assertEqual(rebase_refs(self.path, report), ["a.c:10-12 -> a.c:30-32"]) + self.assertTrue(bump_commit(self.path, report)) + def test_upstream_pin_moves_with_source_pin(self): """A recale onto upstream HEAD lines must advance upstream_commit too.""" part = PartResult(