From b7ed4dca3eeb1cf46dce4db8743a055d9084b76b Mon Sep 17 00:00:00 2001 From: Igor Tarasenko Date: Thu, 7 May 2026 18:35:48 +0200 Subject: [PATCH] fix(bootstrap): clarify shebang fallback precedence + tighten test setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses review feedback on PR #1817: 1. Extend the `_agent_dir_from_hermes_cli` docstring to spell out that the shebang fallback is a last-resort discovery step, not an override. Stale clones in known candidate paths still win — same precedence as today, but now documented so a future maintainer doesn't get the wrong idea. 2. Drop the misleading "install exists but no run_agent.py" comment in `test_returns_none_when_shebang_interpreter_does_not_walk_to_run_agent`. The test exercises a shebang pointing at /usr/bin/python3 whose parents never reach a run_agent.py — it doesn't actually need a fake install dir at all. Renamed for accuracy and removed the unused _make_agent_install call. --- bootstrap.py | 6 ++++++ tests/test_bootstrap_discover_agent.py | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index 71db9640..92d08245 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -102,6 +102,12 @@ def _agent_dir_from_hermes_cli() -> Path | None: `run_agent.py` recovers the install root regardless of where the user chose to clone the agent (e.g. ~/Projects/GitHub/hermes-agent), which the hard-coded candidate list in :func:`discover_agent_dir` cannot. + + Last-resort only: this is invoked after every explicit candidate + (`HERMES_WEBUI_AGENT_DIR`, `$HERMES_HOME/hermes-agent`, etc.) has missed. + A stale clone in a known location still wins over the live `hermes` CLI + — that's intentional, since the candidate list is treated as + authoritative when present, and matches existing behavior. """ hermes_path = shutil.which("hermes") if not hermes_path: diff --git a/tests/test_bootstrap_discover_agent.py b/tests/test_bootstrap_discover_agent.py index 3e60fbe8..e6884a1e 100644 --- a/tests/test_bootstrap_discover_agent.py +++ b/tests/test_bootstrap_discover_agent.py @@ -83,9 +83,8 @@ def test_returns_none_when_hermes_has_no_shebang(monkeypatch, tmp_path): assert bootstrap.discover_agent_dir() is None -def test_returns_none_when_shebang_interpreter_does_not_have_run_agent(monkeypatch, tmp_path): - """Shebang points at /usr/bin/python3 — no install root walks up to run_agent.py.""" - _make_agent_install(tmp_path, with_run_agent=False) # install exists but no run_agent.py +def test_returns_none_when_shebang_interpreter_does_not_walk_to_run_agent(monkeypatch, tmp_path): + """Shebang points at a system Python — no parent of /usr/bin/python3 has run_agent.py.""" hermes = _make_hermes_cli(tmp_path, "/usr/bin/python3") _isolate_discover_agent_dir(monkeypatch, tmp_path, hermes)