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))