refactor(branch): move the held-branch reader to gc_refs and the held-once tests to a unit module
CI / security-codeql (push) Blocked by required conditions
CI / test-unit (push) Blocked by required conditions
CI / test-integration (push) Blocked by required conditions
CI / test-env-virtual (push) Blocked by required conditions
CI / test-env-nix (push) Blocked by required conditions
CI / test-e2e (push) Blocked by required conditions
CI / test-virgin-user (push) Blocked by required conditions
CI / test-virgin-root (push) Blocked by required conditions
CI / lint-shell (push) Blocked by required conditions
CI / lint-python (push) Blocked by required conditions
CI / lint-docker (push) Blocked by required conditions
CI / quality (push) Blocked by required conditions

The quality gate's ratchet flagged PR 13: gc.py and test_branch_cleanup_local.py grew past their already-oversized base length, and _actions gained a seventh parameter. The held-branch reader (_held_branches, _worktree_heads, _git_dirs, _symbolic, _common_dir, HELD_FILES) moves unchanged into gc_refs.py, so gc.py shrinks below its base; scope local is routed in _build, so _actions keeps six parameters; the held-once tests move into tests/unit/pkgmgr/actions/branch/test_gc_held_once.py and test_branch_cleanup_local.py is back to main plus one patch target. Mutating git calls stay on gc._git, so the gc.run spies still see them.

🎯 Fix: 90 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-28 11:52:58 +00:00
1 parent 5e08847286
commit 39843ab627
4 files changed
+320 -185

No files matched your search

+3 -49
View File
@@ -13,7 +13,7 @@ from contextlib import contextmanager, redirect_stderr, redirect_stdout
from types import SimpleNamespace
from unittest.mock import patch
from pkgmgr.actions.branch import gc, gc_forge, tree
from pkgmgr.actions.branch import gc, gc_forge, gc_refs, tree
from pkgmgr.cli.commands.branch import handle_branch, scan_repo_roots
from pkgmgr.cli.parser import create_parser
from pkgmgr.core.credentials.types import NoCredentialsError
@@ -489,52 +489,6 @@ class TestBranchCleanupLocal(unittest.TestCase):
heads["refs/heads/local-done"],
)
def test_plan_reads_the_held_branches_once_per_repository(self) -> None:
self._set_head()
extra = ("more-a", "more-b", "more-c")
for name in extra:
git(self.repo, "branch", name, "done")
with patch.object(gc, "_held_branches", wraps=gc._held_branches) as held:
run = self._cleanup("local", apply=False)
self.assertEqual(held.call_count, 1)
self.assertEqual(
{name for name, i in run.items.items() if i["actions"]},
{"done", "local-done", *extra},
)
def test_branch_held_after_the_plan_is_not_deleted(self) -> None:
self._set_head()
real = gc._rebuild
changes = [
lambda: git(
self.repo, "symbolic-ref", "refs/tags/pin", "refs/heads/local-done"
)
]
def late(repo: gc.Repo, item: gc.Item) -> gc.Item:
if changes:
changes.pop()()
return real(repo, item)
with (
patch.object(gc, "_held_branches", wraps=gc._held_branches) as held,
patch.object(gc, "_rebuild", side_effect=late),
):
run = self._cleanup("local", apply=True)
self.assertEqual(held.call_count, 3)
self.assertEqual(
self._results(run),
{
"done": "done",
"local-done": "skipped: changed since plan "
"(target of symbolic ref refs/tags/pin)",
},
)
self.assertIn("refs/heads/local-done", self._refs(self.repo, "refs/heads"))
def test_delete_never_follows_a_symref_made_after_the_check(self) -> None:
planned = git(self.repo, "rev-parse", "held-done")
@@ -1693,7 +1647,7 @@ class TestBranchCleanupLocal(unittest.TestCase):
def test_failed_head_read_refuses_the_repository(self) -> None:
heads = self._refs(self.repo, "refs/heads")
real = gc._git
real = gc_refs._git
def timed_out(args: list[str], cwd: str) -> str:
if args[1:] == ["symbolic-ref", "--quiet", "HEAD"]:
@@ -1702,7 +1656,7 @@ class TestBranchCleanupLocal(unittest.TestCase):
raise err
return real(args, cwd)
with patch.object(gc, "_git", side_effect=timed_out):
with patch.object(gc_refs, "_git", side_effect=timed_out):
run = self._cleanup("local", apply=True)
self.assertEqual(run.code, 2)