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:
teknium1
2026-03-02 04:34:21 -08:00
parent 56b53bff6e
commit ca5525bcd7
2 changed files with 16 additions and 2 deletions

View File

@@ -14,6 +14,18 @@ if str(PROJECT_ROOT) not in sys.path:
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()
def tmp_dir(tmp_path):
"""Provide a temporary directory that is cleaned up automatically."""

View File

@@ -26,9 +26,11 @@ class TestDebugSessionDisabled:
def test_save_noop(self, tmp_path):
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()
assert list(tmp_path.iterdir()) == []
assert list(log_dir.iterdir()) == []
def test_get_session_info_disabled(self):
ds = DebugSession("test_tool", env_var="FAKE_DEBUG_VAR_XYZ")