Skip to content

The agent that grows with you

test: home I/O guard lets command lookup resolve PATH entries under the home

Maciej Lisiewski69417052f8af
diff --git a/tests/hermes_cli/test_real_home_tripwire.py b/tests/hermes_cli/test_real_home_tripwire.py
index 0e3454f1a46..24680c199b5 100644
--- a/tests/hermes_cli/test_real_home_tripwire.py
+++ b/tests/hermes_cli/test_real_home_tripwire.py
@@ -186,6 +186,22 @@ def test_relative_path_metadata_exemption_tracks_working_directory(protected_hom
guard.check(target, metadata=True)
+def test_resolving_a_path_entry_under_the_home_is_command_lookup(protected_home, monkeypatch):
+ """Command resolution realpath()s a PATH entry under the home (``~/.hermes/tools/<tool>``)
+ to tell Hermes-managed bin dirs apart; that lstats the entry and each of its ancestors."""
+ from tests.home_io_guard import HomeIOGuard
+
+ entry = protected_home / "tools" / "npm" / "bin"
+ guard = HomeIOGuard(lambda: [protected_home])
+ monkeypatch.setenv("PATH", str(entry))
+ guard.check(entry, metadata=True)
+ guard.check(entry.parent, metadata=True)
+ with pytest.raises(AssertionError, match="REAL hermes home"):
+ guard.check(protected_home / "tools" / "other", metadata=True)
+ with pytest.raises(AssertionError, match="REAL hermes home"):
+ guard.check(entry.parent, metadata=False)
+
+
def test_checkout_inside_a_guarded_root_is_not_hermes_state():
"""The default install checks the repo out INSIDE the home (install.sh:
INSTALL_DIR=$HERMES_HOME/hermes-agent): the checkout, its .venv and test
diff --git a/tests/home_io_guard.py b/tests/home_io_guard.py
index 877d27fd7cb..660939a18b6 100644
--- a/tests/home_io_guard.py
+++ b/tests/home_io_guard.py
@@ -86,13 +86,15 @@ class HomeIOGuard:
# probe) reads no state; only its contents are guarded.
if metadata and absolute in roots:
return
- # ``shutil.which`` stats/accesses ``<PATH entry>/<name>``. A developer shell puts
- # PM's tool store (~/.hermes/tools/...) on PATH; probing an executable there is
- # command lookup, not reading Hermes state. CI has no such entries.
+ # ``shutil.which`` stats/accesses ``<PATH entry>/<name>``, and command resolution
+ # realpath()s the entry itself (is it a Hermes-managed bin dir?), which lstats each of
+ # its ancestors. A developer shell puts PM's tool store (~/.hermes/tools/...) on PATH;
+ # probing there is command lookup, not reading Hermes state. CI has no such entries.
if metadata:
path = os.environ.get("PATH", "")
cwd = os.getcwd() if self._relative_path_entries(path) else None
- if os.path.dirname(absolute) in self._path_entries(path, cwd):
+ entries = self._path_entries(path, cwd)
+ if os.path.dirname(absolute) in entries or any(_contains(absolute, entry) for entry in entries):
return
# The interpreter's own installation (a PM-managed python under ~/.hermes/tools):
# stdlib source reads (linecache, traceback) are not Hermes state either, nor is