mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(tests): isolate HERMES_HOME in tests and adjust log directory for debug session
Added a fixture to redirect HERMES_HOME to a temporary directory during tests, preventing writes to the user's home directory. Updated the test for DebugSession to create a dedicated log directory for saving logs, ensuring test isolation and accuracy in assertions.
This commit is contained in:
parent
56b53bff6e
commit
ca5525bcd7
2 changed files with 16 additions and 2 deletions
|
|
@ -14,6 +14,18 @@ if str(PROJECT_ROOT) not in sys.path:
|
||||||
sys.path.insert(0, str(PROJECT_ROOT))
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _isolate_hermes_home(tmp_path, monkeypatch):
|
||||||
|
"""Redirect HERMES_HOME to a temp dir so tests never write to ~/.hermes/."""
|
||||||
|
fake_home = tmp_path / "hermes_test"
|
||||||
|
fake_home.mkdir()
|
||||||
|
(fake_home / "sessions").mkdir()
|
||||||
|
(fake_home / "cron").mkdir()
|
||||||
|
(fake_home / "memories").mkdir()
|
||||||
|
(fake_home / "skills").mkdir()
|
||||||
|
monkeypatch.setenv("HERMES_HOME", str(fake_home))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def tmp_dir(tmp_path):
|
def tmp_dir(tmp_path):
|
||||||
"""Provide a temporary directory that is cleaned up automatically."""
|
"""Provide a temporary directory that is cleaned up automatically."""
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@ class TestDebugSessionDisabled:
|
||||||
|
|
||||||
def test_save_noop(self, tmp_path):
|
def test_save_noop(self, tmp_path):
|
||||||
ds = DebugSession("test_tool", env_var="FAKE_DEBUG_VAR_XYZ")
|
ds = DebugSession("test_tool", env_var="FAKE_DEBUG_VAR_XYZ")
|
||||||
ds.log_dir = tmp_path
|
log_dir = tmp_path / "debug_logs"
|
||||||
|
log_dir.mkdir()
|
||||||
|
ds.log_dir = log_dir
|
||||||
ds.save()
|
ds.save()
|
||||||
assert list(tmp_path.iterdir()) == []
|
assert list(log_dir.iterdir()) == []
|
||||||
|
|
||||||
def test_get_session_info_disabled(self):
|
def test_get_session_info_disabled(self):
|
||||||
ds = DebugSession("test_tool", env_var="FAKE_DEBUG_VAR_XYZ")
|
ds = DebugSession("test_tool", env_var="FAKE_DEBUG_VAR_XYZ")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue