From 2a680996752c68fadb2c55ab857b902ca7694a1f Mon Sep 17 00:00:00 2001 From: teknium1 Date: Fri, 6 Mar 2026 17:10:35 -0800 Subject: [PATCH] fix(tests): isolate tests from user ~/.hermes/ config and SOUL.md _make_cli() now patches CLI_CONFIG with clean defaults so test_cli_init tests don't depend on the developer's local config.yaml. test_empty_dir_returns_empty now mocks Path.home() so it doesn't pick up a global SOUL.md. Credit to teyrebaz33 for identifying and fixing these in PR #557. Fixes #555. --- tests/agent/test_prompt_builder.py | 6 +++++- tests/test_cli_init.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py index 6971dc9f2..80309722b 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -172,7 +172,11 @@ class TestBuildSkillsSystemPrompt: class TestBuildContextFilesPrompt: def test_empty_dir_returns_empty(self, tmp_path): - result = build_context_files_prompt(cwd=str(tmp_path)) + from unittest.mock import patch + fake_home = tmp_path / "fake_home" + fake_home.mkdir() + with patch("pathlib.Path.home", return_value=fake_home): + result = build_context_files_prompt(cwd=str(tmp_path)) assert result == "" def test_loads_agents_md(self, tmp_path): diff --git a/tests/test_cli_init.py b/tests/test_cli_init.py index 5fe7d477f..b26a3ff4a 100644 --- a/tests/test_cli_init.py +++ b/tests/test_cli_init.py @@ -12,8 +12,21 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) def _make_cli(**kwargs): """Create a HermesCLI instance with minimal mocking.""" + import cli as _cli_mod from cli import HermesCLI - with patch("cli.get_tool_definitions", return_value=[]): + _clean_config = { + "model": { + "default": "anthropic/claude-opus-4.6", + "base_url": "https://openrouter.ai/api/v1", + "provider": "auto", + }, + "display": {"compact": False, "tool_progress": "all"}, + "agent": {}, + "terminal": {"env_type": "local"}, + } + with patch("cli.get_tool_definitions", return_value=[]), \ + patch.dict("os.environ", {"LLM_MODEL": ""}, clear=False), \ + patch.dict(_cli_mod.__dict__, {"CLI_CONFIG": _clean_config}): return HermesCLI(**kwargs)