mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-16 19:36:54 +00:00
Post-write .js/.ts lint on the local backend runs PM's node/npx instead of the terminal shell's PATH (user dirs first). pm.activate always puts the store dirs in front, also on drift, activating only packages whose whole chain is installed. tui_gateway puts the store dirs ahead of ~/.local/bin. Bare npx/npm/node/uv/uvx MCP commands resolve to PM's copies; the system fallback tables are gone and an absolute command: stays the user's.
53 lines
2.4 KiB
Python
53 lines
2.4 KiB
Python
"""Regression test for slash_worker PATH construction (#83845).
|
|
|
|
When the gateway is launched by the Desktop/Dashboard app it can inherit a
|
|
minimal PATH (/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin)
|
|
that omits the Hermes venv bin dir and ~/.local/bin. The spawned
|
|
tui_gateway.slash_worker then cannot resolve Hermes-managed CLIs such as
|
|
browser-use/uvx via shutil.which, breaking browser_exec.
|
|
|
|
`tui_gateway.server._prepend_tool_paths` prepends those two directories to
|
|
the worker env PATH while preserving the inherited PATH.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from tui_gateway import server as tui_server
|
|
|
|
class TestPrependToolPaths:
|
|
def test_prepends_managed_venv_and_user_bin(self, monkeypatch, tmp_path):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hh"))
|
|
env = {"PATH": "/usr/bin"}
|
|
result = tui_server._prepend_tool_paths(env)
|
|
|
|
parts = result["PATH"].split(os.pathsep)
|
|
# managed bin first (managed-first policy), then venv bin, then
|
|
# user-local bin, then the original PATH preserved
|
|
assert parts[0] == str(tmp_path / "hh" / "bin")
|
|
assert parts[1] == str(Path(sys.executable).parent)
|
|
assert str(Path.home() / ".local" / "bin") in parts
|
|
assert parts[-1] == "/usr/bin"
|
|
|
|
def test_preserves_existing_path_when_empty(self, monkeypatch, tmp_path):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hh"))
|
|
env = {}
|
|
result = tui_server._prepend_tool_paths(env)
|
|
|
|
parts = result["PATH"].split(os.pathsep)
|
|
assert parts[0] == str(tmp_path / "hh" / "bin")
|
|
assert str(Path(sys.executable).parent) in parts
|
|
assert str(Path.home() / ".local" / "bin") in parts
|
|
|
|
def test_pm_store_dirs_go_ahead_of_user_local_bin(self, monkeypatch, tmp_path):
|
|
"""A user's node/uv in ~/.local/bin must never shadow Hermes's PM toolchain."""
|
|
store_dir = str(tmp_path / "store" / "node" / "bin")
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hh"))
|
|
monkeypatch.setattr("pm.install._store_path_dirs", lambda: [store_dir])
|
|
result = tui_server._prepend_tool_paths({"PATH": os.pathsep.join(["/usr/bin", store_dir])})
|
|
|
|
parts = result["PATH"].split(os.pathsep)
|
|
assert parts[0] == store_dir
|
|
assert parts.count(store_dir) == 1
|
|
assert parts.index(str(Path.home() / ".local" / "bin")) > 0
|