Files
hermes-agent/tests/tools/environments/test_local_path_completion.py
teknium1 43e7e830fd fix(tools): fold ~/.local/bin into the POSIX PATH completion siblings, tests + docs
Slim follow-up to the salvaged #111790: the helper becomes a list-returning
sibling of _managed_runtime_path_entries (same shape, same "only when it
exists" convention) and loses the Windows check the caller already performs.

Why here and not in the Electron remote spawn: propagating the login-shell PATH
that locateHermes discovered into `exec env HERMES_DESKTOP=1 … hermes serve`
would fix only the Desktop SSH surface; the terminal environment's PATH
completion is the seam every thin-PATH launcher (SSH, systemd, launchd, cron)
already goes through, so the class closes once. Windows twin out of scope.

Tests move to the mirror dir tests/tools/environments/ with an absent-dir
control; FAQ documents the terminal PATH composition.

Fixes #111778
2026-09-15 18:49:29 -07:00

42 lines
1.7 KiB
Python

"""Terminal-subshell PATH completion in ``tools/environments/local.py``.
A backend started by a non-interactive SSH session, systemd or a GUI launcher
inherits a PATH without ``~/.local/bin`` (only the login shell adds it), so CLIs
installed there were ``command not found`` from the terminal tool (#111778).
"""
import os
import sys
import pytest
from tools.environments import local as local_mod
from tools.environments.local import _append_missing_sane_path_entries, _make_run_env
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="POSIX PATH completion only")
def test_existing_user_local_bin_appended_after_inherited_entries(monkeypatch, tmp_path):
local_bin = tmp_path / ".local" / "bin"
local_bin.mkdir(parents=True)
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("PATH", "/usr/bin:/bin")
monkeypatch.setattr(local_mod, "_git_bash_bin_dirs", lambda: [])
monkeypatch.setattr(local_mod, "_managed_runtime_path_entries", lambda: [])
monkeypatch.setattr(local_mod, "_resolve_hermes_bin_dir", lambda: None)
entries = _make_run_env({})["PATH"].split(os.pathsep)
assert entries[:2] == ["/usr/bin", "/bin"]
assert entries.count(str(local_bin)) == 1
# Already on PATH: position kept, no duplicate appended.
already = _append_missing_sane_path_entries(f"{local_bin}:/usr/bin").split(":")
assert already[0] == str(local_bin) and already.count(str(local_bin)) == 1
def test_missing_user_local_bin_not_appended(monkeypatch, tmp_path):
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setattr(local_mod, "_managed_runtime_path_entries", lambda: [])
assert ".local" not in _append_missing_sane_path_entries("/usr/bin:/bin")