simplify(compat): hermes_cli small facades — drop 7 re-exports/aliases (+relay_runtime alias module), repoint 12 callers/tests

This commit is contained in:
Teknium
2026-09-03 13:05:57 -07:00
parent b39948106a
commit eeb7671e69
46 changed files with 171 additions and 231 deletions
+1 -9
View File
@@ -74,14 +74,6 @@ class TestSubprocessCompatDelegation:
assert shell_hooks.kill_process_tree is _subprocess_compat.kill_process_tree
def test_backcompat_alias_preserved(self):
from hermes_cli import _subprocess_compat
assert (
_subprocess_compat._kill_git_process_tree
is _subprocess_compat.kill_process_tree
)
# ---------------------------------------------------------------------------
# (2) tools.browser_tool._kill_process_tree
@@ -108,7 +100,7 @@ class TestBrowserToolDelegation:
monkeypatch.setattr(deadline_mod, "kill_process_tree", _boom)
legacy_calls = []
monkeypatch.setattr(
browser_tool, "_legacy_kill_process_tree", lambda proc: legacy_calls.append(proc)
"tools.browser_tool_lifecycle._legacy_kill_process_tree", lambda proc: legacy_calls.append(proc)
)
proc = _FakeProc(pid=4444)
browser_tool._kill_process_tree(proc) # must not raise
+7 -7
View File
@@ -24,7 +24,7 @@ def cli_obj(_isolate):
"display": {"tool_progress": "new"},
"terminal": {},
}), patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
from cli import HermesCLI
obj = HermesCLI.__new__(HermesCLI)
obj.model = "test-model"
@@ -50,7 +50,7 @@ class TestLowContextWarning:
"""Warning shown when context is below Hermes' minimum."""
cli_obj.agent.context_compressor.context_length = 32768
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
@@ -64,7 +64,7 @@ class TestLowContextWarning:
"""Warning shown for 2048 tokens (common LM Studio default)."""
cli_obj.agent.context_compressor.context_length = 2048
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
@@ -75,7 +75,7 @@ class TestLowContextWarning:
"""No warning at exactly Hermes' minimum context length."""
cli_obj.agent.context_compressor.context_length = MINIMUM_CONTEXT_LENGTH
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
@@ -86,7 +86,7 @@ class TestLowContextWarning:
"""No warning above Hermes' minimum context length."""
cli_obj.agent.context_compressor.context_length = MINIMUM_CONTEXT_LENGTH + 1
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
@@ -98,7 +98,7 @@ class TestLowContextWarning:
cli_obj.agent.context_compressor.context_length = 4096
cli_obj.base_url = "http://localhost:11434/v1"
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
@@ -112,7 +112,7 @@ class TestLowContextWarning:
cli_obj.agent.context_compressor.context_length = 4096
cli_obj.base_url = "http://localhost:8080/v1"
with patch("cli.get_tool_definitions", return_value=[]), \
patch("cli.build_welcome_banner"):
patch("hermes_cli.banner.build_welcome_banner"):
cli_obj.show_banner()
calls = [str(c) for c in cli_obj.console.print.call_args_list]
+1 -1
View File
@@ -140,7 +140,7 @@ def test_show_banner_does_not_print_skills():
cli_obj.preloaded_skills = ["hermes-agent-dev", "github-auth"]
cli_obj.console = MagicMock()
with patch("cli.build_welcome_banner") as mock_banner, patch(
with patch("hermes_cli.banner.build_welcome_banner") as mock_banner, patch(
"shutil.get_terminal_size", return_value=os.terminal_size((120, 40))
):
cli_obj.show_banner()
+1 -1
View File
@@ -249,7 +249,7 @@ def test_runtime_resolution_failure_is_not_sticky(monkeypatch):
monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", _runtime_resolve)
monkeypatch.setattr("hermes_cli.runtime_provider.format_runtime_provider_error", lambda exc: str(exc))
monkeypatch.setattr(cli, "AIAgent", _DummyAgent)
monkeypatch.setattr("run_agent.AIAgent", _DummyAgent)
shell = cli.HermesCLI(model="gpt-5", compact=True, max_turns=1)
+2 -2
View File
@@ -78,7 +78,7 @@ def test_show_session_status_prints_gateway_style_summary():
"started_at": 1775791440,
}
with patch("cli.display_hermes_home", return_value="~/.hermes"):
with patch("hermes_constants.display_hermes_home", return_value="~/.hermes"):
cli_obj._show_session_status()
printed = "\n".join(str(call.args[0]) for call in cli_obj.console.print.call_args_list)
@@ -107,7 +107,7 @@ def test_show_session_status_includes_reasoning_approvals_context():
"context_tokens": 50000, "context_length": 200000, "context_percent": 25,
}
with patch("cli.display_hermes_home", return_value="~/.hermes"), \
with patch("hermes_constants.display_hermes_home", return_value="~/.hermes"), \
patch("tools.approval._get_approval_mode", return_value="manual"), \
patch("tools.approval.is_approval_bypass_active_for_session", return_value=False):
cli_obj._show_session_status()
@@ -5,7 +5,12 @@ leak into the input buffer after terminal resize storms or multiplexer
tab switches — see issue #14692.
"""
from cli import _strip_leaked_terminal_responses
from cli import _strip_leaked_terminal_responses_with_meta
def _strip_leaked_terminal_responses(text: str) -> str:
cleaned, _ = _strip_leaked_terminal_responses_with_meta(text)
return cleaned
class TestStripLeakedTerminalResponses:
+25 -21
View File
@@ -8,6 +8,8 @@ import os
import shutil
import subprocess
import pytest
from hermes_cli import worktree_ops
from pathlib import Path
@@ -845,7 +847,7 @@ class TestWorktreeLockReaping:
import cli
wt = self._mk(cli, git_repo, "hermes-dead", pid=999999)
# sanity: this is the accumulation bug — remove --force alone can't do it
assert cli._worktree_lock_is_live(str(git_repo), str(wt)) == "dead"
assert worktree_ops._worktree_lock_is_live(str(git_repo), str(wt)) == "dead"
cli._prune_stale_worktrees(str(git_repo))
assert not wt.exists(), "dead-locked clean worktree should be unlocked + reaped"
@@ -899,19 +901,19 @@ class TestWorktreeLockPredicate:
["git", "worktree", "add", str(p), "-b", "hermes/hermes-x", "HEAD"],
cwd=git_repo, capture_output=True,
)
assert cli._worktree_lock_is_live(str(git_repo), str(p)) is None
assert worktree_ops._worktree_lock_is_live(str(git_repo), str(p)) is None
def test_foreign_lock_reason_returns_dead(self, git_repo):
import cli
p = self._mk_locked(git_repo, "hermes-foreign", "some other tool")
assert cli._worktree_lock_is_live(str(git_repo), str(p)) == "dead"
assert worktree_ops._worktree_lock_is_live(str(git_repo), str(p)) == "dead"
def test_bad_repo_root_fails_safe_to_live(self, tmp_path):
import cli
# Not a git repo -> git query fails -> must report "live" (never delete)
assert cli._worktree_lock_is_live(str(tmp_path), str(tmp_path / "x")) == "live"
assert worktree_ops._worktree_lock_is_live(str(tmp_path), str(tmp_path / "x")) == "live"
class TestWidenedPruner:
@@ -1021,7 +1023,7 @@ class TestWidenedPruner:
["git", "worktree", "add", str(p), "-b", "wt/noremote", "HEAD"],
cwd=repo, capture_output=True,
)
assert cli._worktree_commits_all_merged_upstream(str(p)) is False
assert worktree_ops._worktree_commits_all_merged_upstream(str(p)) is False
# -- preserved-work warning ----------------------------------------------
@@ -1050,10 +1052,10 @@ class TestMergeVerdictCache:
wt, sha = self._mk(git_repo, "hermes-cachehit", commit=True)
self._merge_upstream(git_repo, sha)
uncached = cli._worktree_commits_all_merged_upstream(str(wt))
uncached = worktree_ops._worktree_commits_all_merged_upstream(str(wt))
cache = {}
cold = cli._worktree_commits_all_merged_upstream(str(wt), cache=cache)
warm = cli._worktree_commits_all_merged_upstream(str(wt), cache=cache)
cold = worktree_ops._worktree_commits_all_merged_upstream(str(wt), cache=cache)
warm = worktree_ops._worktree_commits_all_merged_upstream(str(wt), cache=cache)
assert cache, "verdict should have been memoized"
assert uncached is cold is warm is True
@@ -1070,7 +1072,7 @@ class TestMergeVerdictCache:
self._merge_upstream(git_repo, sha)
cache = {}
assert cli._worktree_commits_all_merged_upstream(str(wt), cache=cache) is True
assert worktree_ops._worktree_commits_all_merged_upstream(str(wt), cache=cache) is True
key_after_merge = set(cache)
# New local-only work lands in the worktree.
@@ -1078,7 +1080,7 @@ class TestMergeVerdictCache:
subprocess.run(["git", "add", "more.txt"], cwd=wt, capture_output=True)
subprocess.run(["git", "commit", "-m", "new work"], cwd=wt, capture_output=True)
assert cli._worktree_commits_all_merged_upstream(str(wt), cache=cache) is False
assert worktree_ops._worktree_commits_all_merged_upstream(str(wt), cache=cache) is False
assert set(cache) != key_after_merge, "moved HEAD must produce a new key"
@@ -1091,8 +1093,8 @@ class TestMergeVerdictCache:
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
worktree_ops._save_worktree_merge_cache({f"sha{i}..sha{i}:20": True for i in range(50)})
assert len(worktree_ops._load_worktree_merge_cache()) == 10
class TestPruneParallelEquivalence:
@@ -1151,7 +1153,7 @@ class TestPruneParallelEquivalence:
# Phase B — an independent board (distinct branch names so creation
# can't collide with phase A's leftover refs) run through a real pool.
try:
cli._worktree_merge_cache_path().unlink()
worktree_ops._worktree_merge_cache_path().unlink()
except Exception:
pass
board2 = self._board(git_repo, tag="b")
@@ -1177,7 +1179,9 @@ class TestPruneParallelEquivalence:
def __init__(self, *a, **kw):
raise RuntimeError("cannot start thread")
monkeypatch.setattr(cli.concurrent.futures, "ThreadPoolExecutor", _Boom)
import concurrent.futures
monkeypatch.setattr(concurrent.futures, "ThreadPoolExecutor", _Boom)
monkeypatch.setattr(cli.os, "cpu_count", lambda: 8)
cli._prune_stale_worktrees(str(git_repo))
@@ -1289,7 +1293,7 @@ class TestShallowCloneDeepening:
_, clone, wt = self._stuck_worktree(tmp_path)
assert cli._worktree_has_unpushed_commits(str(wt))
assert cli._deepen_shallow_repo(str(clone)) is True
assert worktree_ops._deepen_shallow_repo(str(clone)) is True
assert not cli._repo_is_shallow(str(clone))
assert not cli._worktree_has_unpushed_commits(str(wt)), (
"after deepening, the worktree's HEAD is an ancestor of "
@@ -1317,7 +1321,7 @@ class TestShallowCloneDeepening:
["git", "remote", "set-url", "origin", f"file://{tmp_path}/gone"],
clone,
)
assert cli._deepen_shallow_repo(str(clone), timeout=30) is False
assert worktree_ops._deepen_shallow_repo(str(clone), timeout=30) is False
cli._prune_stale_worktrees(str(clone))
assert wt.exists(), (
"offline deepen failure must fall back to preserving the tree"
@@ -1325,7 +1329,7 @@ class TestShallowCloneDeepening:
def test_deepen_noop_on_full_clone(self, git_repo):
import cli
assert cli._deepen_shallow_repo(str(git_repo)) is True
assert worktree_ops._deepen_shallow_repo(str(git_repo)) is True
def test_real_unpushed_work_survives_deepening(self, tmp_path):
"""Deepening must not turn genuinely unpushed commits reapable."""
@@ -1384,7 +1388,7 @@ class TestPrMergedEscapeHatch:
def test_merged_pr_tree_is_reaped(self, git_repo, tmp_path, monkeypatch):
import cli
wt = self._mk_diverged(git_repo, "hermes-rebase-merged")
assert cli._worktree_commits_all_merged_upstream(str(wt)) is False, (
assert worktree_ops._worktree_commits_all_merged_upstream(str(wt)) is False, (
"precondition: cherry must NOT consider this merged — the PR "
"check is the only thing that can reap it"
)
@@ -1426,19 +1430,19 @@ class TestPrMergedEscapeHatch:
wt = self._mk_diverged(git_repo, "hermes-memo")
self._stub_gh(tmp_path, monkeypatch)
cache: dict = {}
assert cli._worktree_branch_pr_merged(str(wt), cache=cache) is True
assert worktree_ops._worktree_branch_pr_merged(str(wt), cache=cache) is True
keys = [k for k in cache if k.startswith("pr-merged:")]
assert len(keys) == 1 and cache[keys[0]] is True
# Break gh: a cached True verdict must not re-consult it.
self._stub_gh(tmp_path, monkeypatch, stdout="", exit_code=1)
assert cli._worktree_branch_pr_merged(str(wt), cache=cache) is True
assert worktree_ops._worktree_branch_pr_merged(str(wt), cache=cache) is True
def test_negative_verdict_not_cached(self, git_repo, tmp_path, monkeypatch):
import cli
wt = self._mk_diverged(git_repo, "hermes-nocache-neg")
self._stub_gh(tmp_path, monkeypatch, stdout="[]")
cache: dict = {}
assert cli._worktree_branch_pr_merged(str(wt), cache=cache) is False
assert worktree_ops._worktree_branch_pr_merged(str(wt), cache=cache) is False
assert not [k for k in cache if k.startswith("pr-merged:")], (
"False must not be memoized — the PR can merge later with the "
"same (branch, head) key"
+12 -10
View File
@@ -15,6 +15,8 @@ import time
import pytest
from hermes_cli import worktree_ops
def _run(args, cwd):
return subprocess.run(
@@ -93,7 +95,7 @@ class TestFetchRemoteBranchHeads:
import cli
repo = repo_with_bare_origin
_mk_worktree(repo, "hermes-a", "hermes/hermes-a", push=True)
heads = cli._fetch_remote_branch_heads(str(repo))
heads = worktree_ops._fetch_remote_branch_heads(str(repo))
assert heads is not None
assert "main" in heads
assert "hermes/hermes-a" in heads
@@ -104,7 +106,7 @@ class TestFetchRemoteBranchHeads:
repo.mkdir()
_run(["git", "init"], repo)
_run(["git", "remote", "add", "origin", str(tmp_path / "missing.git")], repo)
assert cli._fetch_remote_branch_heads(str(repo)) is None
assert worktree_ops._fetch_remote_branch_heads(str(repo)) is None
class TestBranchPushedExact:
@@ -112,8 +114,8 @@ class TestBranchPushedExact:
import cli
repo = repo_with_bare_origin
wt = _mk_worktree(repo, "hermes-x", "hermes/hermes-x", push=True)
heads = cli._fetch_remote_branch_heads(str(repo))
assert cli._worktree_branch_pushed_exact(str(wt), heads) is True
heads = worktree_ops._fetch_remote_branch_heads(str(repo))
assert worktree_ops._worktree_branch_pushed_exact(str(wt), heads) is True
def test_local_ahead_of_push_false(self, repo_with_bare_origin):
import cli
@@ -122,22 +124,22 @@ class TestBranchPushedExact:
repo, "hermes-y", "hermes/hermes-y",
push=True, extra_commit_after_push=True,
)
heads = cli._fetch_remote_branch_heads(str(repo))
assert cli._worktree_branch_pushed_exact(str(wt), heads) is False
heads = worktree_ops._fetch_remote_branch_heads(str(repo))
assert worktree_ops._worktree_branch_pushed_exact(str(wt), heads) is False
def test_never_pushed_false(self, repo_with_bare_origin):
import cli
repo = repo_with_bare_origin
wt = _mk_worktree(repo, "hermes-z", "hermes/hermes-z", push=False)
heads = cli._fetch_remote_branch_heads(str(repo))
assert cli._worktree_branch_pushed_exact(str(wt), heads) is False
heads = worktree_ops._fetch_remote_branch_heads(str(repo))
assert worktree_ops._worktree_branch_pushed_exact(str(wt), heads) is False
def test_none_heads_false(self, repo_with_bare_origin):
import cli
repo = repo_with_bare_origin
wt = _mk_worktree(repo, "hermes-n", "hermes/hermes-n", push=True)
assert cli._worktree_branch_pushed_exact(str(wt), None) is False
assert cli._worktree_branch_pushed_exact(str(wt), {}) is False
assert worktree_ops._worktree_branch_pushed_exact(str(wt), None) is False
assert worktree_ops._worktree_branch_pushed_exact(str(wt), {}) is False
class TestStartupPrunerPushedTier:
+3 -3
View File
@@ -53,7 +53,7 @@ class TestCleanupFailedWorktreeAdd:
return wt
def test_sweeps_dir_admin_entry_and_branch(self, repo):
from cli import _cleanup_failed_worktree_add
from hermes_cli.worktree_ops import _cleanup_failed_worktree_add
wt = self._simulate_timed_out_add(repo)
admin = repo / ".git" / "worktrees" / "hermes-dead00"
@@ -68,7 +68,7 @@ class TestCleanupFailedWorktreeAdd:
def test_retry_succeeds_after_cleanup(self, repo):
"""The whole point: the same worktree name is creatable again."""
from cli import _cleanup_failed_worktree_add
from hermes_cli.worktree_ops import _cleanup_failed_worktree_add
wt = self._simulate_timed_out_add(repo)
_cleanup_failed_worktree_add(str(repo), wt, "hermes/hermes-dead00")
@@ -80,7 +80,7 @@ class TestCleanupFailedWorktreeAdd:
def test_noop_when_nothing_exists(self, repo):
"""Fail-soft on an error path where git never created anything."""
from cli import _cleanup_failed_worktree_add
from hermes_cli.worktree_ops import _cleanup_failed_worktree_add
_cleanup_failed_worktree_add(
str(repo), repo / ".worktrees" / "never-existed", "hermes/never-existed"
+9 -7
View File
@@ -4,7 +4,7 @@ A worktree created off the standalone clone's local ``HEAD`` roots the new
branch on a stale base when that clone lags the remote. ``_resolve_worktree_base``
fetches and branches from the remote tip instead so the worktree starts current.
These tests exercise the REAL ``cli._resolve_worktree_base`` /
These tests exercise the REAL ``worktree_ops._resolve_worktree_base`` /
``cli._setup_worktree`` against a real local "remote" repo (so ``git fetch``
works offline in the hermetic sandbox), proving the worktree includes commits
that exist on the remote but not on the stale local HEAD.
@@ -17,6 +17,8 @@ from pathlib import Path
import pytest
from hermes_cli import worktree_ops
import cli
@@ -76,7 +78,7 @@ def remote_and_clone(tmp_path):
class TestResolveWorktreeBase:
def test_resolves_to_fetched_upstream(self, remote_and_clone):
clone, remote_head, stale_local_head = remote_and_clone
base_ref, label = cli._resolve_worktree_base(str(clone))
base_ref, label = worktree_ops._resolve_worktree_base(str(clone))
# Should resolve to the upstream tracking ref and have fetched it.
assert base_ref == "origin/main"
assert "fetched" in label
@@ -92,7 +94,7 @@ class TestResolveWorktreeBase:
_run(["git", "config", "user.email", "t@t.com"], repo)
_run(["git", "config", "user.name", "T"], repo)
_commit(repo, "README.md", "only commit")
base_ref, label = cli._resolve_worktree_base(str(repo))
base_ref, label = worktree_ops._resolve_worktree_base(str(repo))
assert base_ref == "HEAD"
assert "HEAD" in label
@@ -119,7 +121,7 @@ class TestResolveWorktreeBaseStartupCost:
return real_run(args, **kw)
monkeypatch.setattr(subprocess, "run", spy)
base_ref, label = cli._resolve_worktree_base(str(clone))
base_ref, label = worktree_ops._resolve_worktree_base(str(clone))
assert base_ref == "origin/main"
assert "fetched" in label and "ago" in label
assert calls == [], "fresh FETCH_HEAD must skip the network fetch"
@@ -134,7 +136,7 @@ class TestResolveWorktreeBaseStartupCost:
fetch_head = Path(clone) / ".git" / "FETCH_HEAD"
old = time.time() - 3600
os.utime(fetch_head, (old, old))
base_ref, label = cli._resolve_worktree_base(str(clone))
base_ref, label = worktree_ops._resolve_worktree_base(str(clone))
assert base_ref == "origin/main"
assert label == "origin/main (fetched)"
@@ -154,7 +156,7 @@ class TestResolveWorktreeBaseStartupCost:
monkeypatch.setattr(subprocess, "run", stall_fetches)
start = time.monotonic()
base_ref, label = cli._resolve_worktree_base(str(clone))
base_ref, label = worktree_ops._resolve_worktree_base(str(clone))
elapsed = time.monotonic() - start
# Cached tracking ref, single fetch attempt, no step-2 cascade.
assert base_ref == "origin/main"
@@ -185,7 +187,7 @@ class TestResolveWorktreeBaseStartupCost:
_run(
["git", "config", "branch.main.merge", "refs/heads/main"], repo
)
base_ref, label = cli._resolve_worktree_base(str(repo))
base_ref, label = worktree_ops._resolve_worktree_base(str(repo))
assert base_ref == "HEAD"
assert "HEAD" in label
+3 -3
View File
@@ -632,16 +632,16 @@ class TestRoundTrip:
class TestFormatSize:
def test_bytes(self):
from hermes_cli.backup import _format_size
from hermes_cli.sizefmt import format_bytes as _format_size
assert _format_size(512) == "512 B"
def test_kilobytes(self):
from hermes_cli.backup import _format_size
from hermes_cli.sizefmt import format_bytes as _format_size
assert "KB" in _format_size(2048)
def test_terabytes(self):
from hermes_cli.backup import _format_size
from hermes_cli.sizefmt import format_bytes as _format_size
assert "TB" in _format_size(2 * 1024 ** 4)
@@ -12,10 +12,8 @@ from argparse import Namespace
import pytest
from hermes_cli.cron import (
_contains_gateway_lifecycle_command,
cron_command,
)
from cron.lifecycle_guard import contains_gateway_lifecycle_command as _contains_gateway_lifecycle_command
from hermes_cli.cron import cron_command
# ---------------------------------------------------------------------------
+5 -5
View File
@@ -3,7 +3,7 @@
Timing out a git probe must not leave helper descendants (credential helpers,
``git-remote-https``, hook children) running after the probe returns. The
probe spawns the child in its own process group (``process_group=0``) and
``_kill_git_process_tree`` signals the whole group with ``os.killpg`` — but
``kill_process_tree`` signals the whole group with ``os.killpg`` — but
only when the child actually leads its own group, so a shared-group spawn can
never take down unrelated processes.
@@ -20,7 +20,7 @@ import time
import pytest
from hermes_cli import _subprocess_compat
from hermes_cli._subprocess_compat import _kill_git_process_tree, bounded_git_probe
from hermes_cli._subprocess_compat import bounded_git_probe, kill_process_tree
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="POSIX process-group semantics"
@@ -94,7 +94,7 @@ def test_posix_spawn_uses_own_process_group(tmp_path):
def test_group_kill_skipped_when_child_shares_our_group():
"""_kill_git_process_tree must never killpg a group the child doesn't lead.
"""kill_process_tree must never killpg a group the child doesn't lead.
Spawn WITHOUT process_group=0 (child inherits OUR group): the ownership
check (pgid == pid) must skip the group signal, or the test process itself
@@ -107,7 +107,7 @@ def test_group_kill_skipped_when_child_shares_our_group():
stdin=subprocess.DEVNULL,
)
assert os.getpgid(proc.pid) == os.getpgid(0) # shared group precondition
_kill_git_process_tree(proc)
kill_process_tree(proc)
proc.wait(timeout=5)
# We are alive to make this assertion — killpg on our own group would have
# taken the test runner down. The direct child is still killed.
@@ -132,4 +132,4 @@ def test_kill_helper_swallow_all_failures():
def kill(self):
raise OSError("already reaped")
_kill_git_process_tree(_Dead()) # must not raise
kill_process_tree(_Dead()) # must not raise
@@ -144,7 +144,9 @@ def test_tree_dirtied_between_check_and_removal_preserved(
(wt / "late-wip.txt").write_text("dirtied after the check\n", encoding="utf-8")
# Pre-check lies (as if the file appeared just after it ran) — real git
# must still refuse the removal.
monkeypatch.setattr(cli, "_worktree_is_dirty", lambda _p: False)
from hermes_cli import worktree_ops
monkeypatch.setattr(worktree_ops, "_worktree_is_dirty", lambda _p: False)
kb._cleanup_worktree_workspace("t_gggg7777", str(wt))
assert wt.is_dir()
assert (wt / "late-wip.txt").exists()
+3 -2
View File
@@ -1,3 +1,4 @@
import importlib.metadata
import argparse
import json
from types import SimpleNamespace
@@ -75,7 +76,7 @@ def test_discover_all_plugins_includes_entrypoint_plugins(monkeypatch, tmp_path)
lambda: bundled_dir,
)
monkeypatch.setattr(
plugins_cmd.importlib.metadata,
importlib.metadata,
"entry_points",
lambda: [entry_point],
)
@@ -117,7 +118,7 @@ def test_declared_capabilities_for_entrypoint_uses_distribution_metadata(
"hermes_cli.plugins.get_bundled_plugins_dir", lambda: bundled_dir
)
monkeypatch.setattr(
plugins_cmd.importlib.metadata,
importlib.metadata,
"entry_points",
lambda: [plugin_ep, capability_ep],
)
@@ -15,7 +15,8 @@ from typing import Any
import pytest
from hermes_cli import lifecycle, plugins
from hermes_cli.observability import relay_runtime, relay_shared_metrics
from agent import relay_runtime
from hermes_cli.observability import relay_shared_metrics
from hermes_cli.plugins import PluginManager
+2 -2
View File
@@ -284,7 +284,7 @@ class TestPreToolCallBlocking:
monkeypatch.setattr("hermes_cli.plugins.invoke_hook", fake_invoke_hook)
monkeypatch.setattr("model_tools.registry.dispatch",
lambda *a, **kw: (_ for _ in ()).throw(AssertionError("should not run")))
monkeypatch.setattr("tools.file_tools.notify_other_tool_call",
monkeypatch.setattr("tools.file_tools_read_tracking.notify_other_tool_call",
lambda task_id: notifications.append(task_id))
result = json.loads(handle_function_call("web_search", {"q": "test"}, task_id="t1"))
@@ -327,7 +327,7 @@ class TestPreToolCallBlocking:
return json.dumps({"ok": True})
monkeypatch.setattr(
"hermes_cli.observability.relay_runtime.apply_tool_request_intercepts",
"agent.relay_runtime.apply_tool_request_intercepts",
rewrite,
)
monkeypatch.setattr("hermes_cli.plugins.invoke_hook", fake_invoke_hook)
+6 -6
View File
@@ -20726,7 +20726,7 @@ def test_fallback_session_info_reports_session_cwd_not_launch_dir(monkeypatch):
wrong project for any session resumed without a built agent (#71254).
"""
monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "bb/feature")
monkeypatch.setattr(server.git_probe, "branch", lambda cwd: "bb/feature")
monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
@@ -20743,7 +20743,7 @@ def test_fallback_session_info_always_emits_branch(monkeypatch):
after switching into a non-git session.
"""
monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "")
monkeypatch.setattr(server.git_probe, "branch", lambda cwd: "")
monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
@@ -22238,13 +22238,13 @@ def test_workspace_move_rehomes_running_session(monkeypatch, tmp_path):
monkeypatch.setattr(server, "_profile_db", _fake_db)
monkeypatch.setattr(
server,
"_git_branch_for_cwd",
server.git_probe,
"branch",
lambda cwd: "main",
)
monkeypatch.setattr(
server,
"_git_common_repo_root_for_cwd",
server.git_probe,
"common_repo_root",
lambda cwd: str(new_cwd),
)
+1 -1
View File
@@ -749,7 +749,7 @@ class TestGitBashPathNormalization:
def test_posix_noop(self):
"""Must NOT mutate paths on Linux/macOS."""
from cli import _normalize_git_bash_path
from hermes_cli.worktree_ops import _normalize_git_bash_path
if sys.platform != "win32":
assert _normalize_git_bash_path("/home/teknium/foo") == "/home/teknium/foo"
assert _normalize_git_bash_path("/c/Users/foo") == "/c/Users/foo"
+2 -2
View File
@@ -370,7 +370,7 @@ class TestDelegationCleanup:
reset_hermes_home_override,
set_hermes_home_override,
)
from hermes_cli.observability import relay_runtime
from agent import relay_runtime
from tools.delegate_tool import _run_single_child
parent = MagicMock()
@@ -415,7 +415,7 @@ class TestDelegationCleanup:
def test_active_child_turn_owns_relay_scope_cleanup(self, monkeypatch):
from unittest.mock import MagicMock
from hermes_cli.observability import relay_runtime
from agent import relay_runtime
from tools.delegate_tool import _run_single_child
parent = MagicMock()
+1 -1
View File
@@ -999,7 +999,7 @@ def test_session_resume_active_turn_payload_matches_desktop_fixture(server, monk
"session_key": fixture["session_key"],
}
monkeypatch.setattr(server, "_get_db", lambda: _DB())
monkeypatch.setattr(server, "_session_info", lambda _agent: fixture["info"])
monkeypatch.setattr(server, "_session_info", lambda _agent, _session=None: fixture["info"])
# JSON round-trip the real RPC envelope: the desktop fixture must stay
# faithful to what the gateway actually serializes, not a copied shape.
@@ -32,11 +32,11 @@ def test_cwd_claim_precedes_probe_and_generation_reaches_publish(monkeypatch):
monkeypatch.setattr(server, "_get_db", lambda: DB())
monkeypatch.setattr(server.threading, "Thread", _ImmediateThread)
monkeypatch.setattr(
server,
"_git_branch_for_cwd",
server.git_probe,
"branch",
lambda cwd: events.append(("probe", cwd)) or "feature",
)
monkeypatch.setattr(server, "_git_common_repo_root_for_cwd", lambda _cwd: "/repo")
monkeypatch.setattr(server.git_probe, "common_repo_root", lambda _cwd: "/repo")
generation = server._persist_session_cwd_and_schedule_git_meta(
{"session_key": "session"}, "/repo/worktree"
@@ -61,7 +61,7 @@ def test_missing_db_claim_never_starts_git_probe(monkeypatch):
probed = []
monkeypatch.setattr(server, "_get_db", lambda: None)
monkeypatch.setattr(
server, "_git_branch_for_cwd", lambda cwd: probed.append(cwd)
server.git_probe, "branch", lambda cwd: probed.append(cwd)
)
generation = server._persist_session_cwd_and_schedule_git_meta(