mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Cross-file leaks made tests/tui_gateway + tests/test_tui_gateway_server.py fail when run in one process (issue #57068): - conftest: _hermetic_environment now re-pins hermes_state.DEFAULT_DB_PATH to the fake home so no test ever touches the developer's real state.db - conftest: new autouse _reset_tui_gateway_server_state snapshots/restores _methods, cfg cache, db handle and _real_stdout, and tears down leftover sessions via the production _close_session_by_id(..., end_reason= "test_cleanup") boundary - per-file fixtures scope patch.dict(sys.modules) to the import only - drop reload()-based teardowns that duplicated atexit hooks Conflict resolution vs main: kept main's mod._live_transports.clear() in the test_protocol.py server fixture alongside the snapshot/restore logic. Combined run now 792 passed / 0 failed. Salvaged from PR #57066 by @lEWFkRAD. Fixes #57068.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""Regression tests for the conftest live-system guard's argv handling.
|
|
|
|
The guard must treat only argv[0] of a list/tuple command as the executable
|
|
(arguments are data: a file named ``skill`` is not the ``skill`` binary),
|
|
while still scanning every token of wrapper invocations like ``bash -c``.
|
|
All blocked-case commands use patterns that match no real process, so a
|
|
guard regression cannot kill anything.
|
|
"""
|
|
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
|
|
def test_argv_arguments_are_not_treated_as_executables(tmp_path):
|
|
"""A file argument whose basename is a killer name must not trip the
|
|
guard (the path contains "hermes" via the pytest tmp root)."""
|
|
target = tmp_path / "skill"
|
|
target.write_text("just a filename\n")
|
|
result = subprocess.run(["cat", str(target)], capture_output=True, text=True)
|
|
assert result.returncode == 0
|
|
assert "just a filename" in result.stdout
|
|
|
|
|
|
def test_direct_killer_argv_is_still_blocked():
|
|
with pytest.raises(RuntimeError, match="live-system guard"):
|
|
subprocess.run(["pkill", "-f", "hermes-guard-regression-nomatch"])
|
|
|
|
|
|
def test_wrapped_killer_command_is_still_blocked():
|
|
"""argv[0]-only scanning must not exempt commands hidden behind a
|
|
shell wrapper."""
|
|
with pytest.raises(RuntimeError, match="live-system guard"):
|
|
subprocess.run(["bash", "-c", "pkill -f hermes-guard-regression-nomatch"])
|
|
|
|
|
|
def test_env_wrapped_killer_command_is_still_blocked():
|
|
with pytest.raises(RuntimeError, match="live-system guard"):
|
|
subprocess.run(["env", "GUARD_TEST=1", "pkill", "-f", "hermes-guard-regression-nomatch"])
|