From 0111a9ffc87462753f9435a233fab554ee7a751c Mon Sep 17 00:00:00 2001 From: istos Date: Thu, 30 Jul 2026 07:36:51 +0200 Subject: [PATCH] PR #7 review: count 'ahead' against HEAD, not local main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ticker note says the branch point is N ahead of this checkout, but the count compared origin/main to the local main branch — misleading whenever the board runs from another branch or detached HEAD. HEAD is the fallback base, so HEAD..origin/main is exactly what launching from it would have missed. Co-Authored-By: Claude Fable 5 --- manager/core/agents.py | 5 ++++- tests/test_fresh_branch_point.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/manager/core/agents.py b/manager/core/agents.py index fc55bd8..f09658e 100644 --- a/manager/core/agents.py +++ b/manager/core/agents.py @@ -168,7 +168,10 @@ def _fresh_branch_point() -> tuple[str | None, str | None]: if fetched.returncode != 0 or \ _git("rev-parse", "--verify", "--quiet", "origin/main").returncode != 0: return None, "fetch of origin/main failed; branched from local HEAD" - ahead = _git("rev-list", "--count", "main..origin/main").stdout.strip() + # Counted against HEAD, not main: HEAD is the fallback base, so this is + # exactly what launching would have missed — accurate even when the + # board checkout sits on another branch. + ahead = _git("rev-list", "--count", "HEAD..origin/main").stdout.strip() if ahead.isdigit() and int(ahead) > 0: return "origin/main", (f"branched from origin/main, " f"{ahead} ahead of this checkout") diff --git a/tests/test_fresh_branch_point.py b/tests/test_fresh_branch_point.py index 2ba3282..7c5269c 100644 --- a/tests/test_fresh_branch_point.py +++ b/tests/test_fresh_branch_point.py @@ -98,6 +98,15 @@ class FreshBranchPoint(unittest.TestCase): capture_output=True) self.assertNotEqual(upstream_cfg.returncode, 0) + def test_ahead_count_is_relative_to_the_checkout_not_local_main(self): + # The checkout already holds origin/main's tip on another branch; + # only local main is behind. Nothing was missed, so no narration — + # counting main..origin/main would have claimed "1 ahead" here. + _commit(self.upstream, "landed elsewhere") + _git(self.local, "fetch", "-q", "origin") + _git(self.local, "checkout", "-q", "-b", "other", "origin/main") + self.assertEqual(agents._fresh_branch_point(), ("origin/main", None)) + def test_origin_in_sync_is_used_without_narration(self): self.assertEqual(agents._fresh_branch_point(), ("origin/main", None))