refactor(cli): extract git worktree machinery into hermes_cli/worktree_ops.py (cli re-exports)

This commit is contained in:
Teknium
2026-09-02 18:44:44 -07:00
parent 849cec20e2
commit 8c9c7a041a
5 changed files with 1093 additions and 1026 deletions
+35 -1020
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -1086,9 +1086,10 @@ class TestMergeVerdictCache:
def test_cache_is_bounded(self, monkeypatch, tmp_path):
"""The cache file must not grow without limit across sessions."""
import cli
from hermes_cli import worktree_ops
path = tmp_path / "verdicts.json"
monkeypatch.setattr(cli, "_worktree_merge_cache_path", lambda: path)
monkeypatch.setattr(cli, "_WORKTREE_MERGE_CACHE_MAX", 10)
monkeypatch.setattr(worktree_ops, "_worktree_merge_cache_path", lambda: path)
monkeypatch.setattr(worktree_ops, "_WORKTREE_MERGE_CACHE_MAX", 10)
cli._save_worktree_merge_cache({f"sha{i}..sha{i}:20": True for i in range(50)})
assert len(cli._load_worktree_merge_cache()) == 10
+4 -2
View File
@@ -111,6 +111,7 @@ class TestMaintainPackHealth:
def test_repacks_at_threshold(self, repo, monkeypatch):
import cli
from hermes_cli import worktree_ops
made = self._make_packs(repo, 6)
# Behavior contract, not a snapshot: different git builds consolidate
@@ -119,7 +120,7 @@ class TestMaintainPackHealth:
# strictly more packs than the threshold we set — so the maintenance
# pass has something real to consolidate.
threshold = 2
monkeypatch.setattr(cli, "_PACK_SPRAWL_THRESHOLD", threshold)
monkeypatch.setattr(worktree_ops, "_PACK_SPRAWL_THRESHOLD", threshold)
assert made > threshold, f"fixture failed to produce sprawl (made={made})"
cli._maintain_pack_health(str(repo))
@@ -130,9 +131,10 @@ class TestMaintainPackHealth:
def test_noop_below_threshold(self, repo, monkeypatch):
import cli
from hermes_cli import worktree_ops
made = self._make_packs(repo, 2)
monkeypatch.setattr(cli, "_PACK_SPRAWL_THRESHOLD", 50)
monkeypatch.setattr(worktree_ops, "_PACK_SPRAWL_THRESHOLD", 50)
cli._maintain_pack_health(str(repo))
+2 -2
View File
@@ -782,13 +782,13 @@ class TestWorktreeSymlinkFallback:
def test_source_has_symlink_fallback(self):
root = Path(__file__).resolve().parents[2]
source = (root / "cli.py").read_text(encoding="utf-8")
source = (root / "hermes_cli" / "worktree_ops.py").read_text(encoding="utf-8")
# Look for the try/except that handles OSError around os.symlink
# with a shutil.copytree fallback.
assert "os.symlink(str(src_resolved), str(dst))" in source
assert "except (OSError, NotImplementedError)" in source
assert "shutil.copytree" in source
assert 'sys.platform == "win32"' in source
assert 'sys.platform != "win32"' in source
# ---------------------------------------------------------------------------