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:
@@ -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."""
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user