From b197cf409e61087762ea682cf038f391ba14f26f Mon Sep 17 00:00:00 2001 From: Timmy Time Date: Mon, 23 Mar 2026 22:15:37 +0000 Subject: [PATCH] [loop-cycle-3] fix: isolate unit tests from local .env and real Gitea API (#1206) --- tests/unit/test_config.py | 9 ++++++++- tests/unit/test_vassal_agent_health.py | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index c3d73ef..7d93c34 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -18,6 +18,10 @@ def _make_settings(**env_overrides): """Create a fresh Settings instance with isolated env vars.""" from config import Settings + # Prevent Pydantic from reading .env file (local .env pollutes defaults) + _orig_config = Settings.model_config.copy() + Settings.model_config["env_file"] = None + # Strip keys that might bleed in from the test environment clean_env = { k: v @@ -82,7 +86,10 @@ def _make_settings(**env_overrides): } clean_env.update(env_overrides) with patch.dict(os.environ, clean_env, clear=True): - return Settings() + try: + return Settings() + finally: + Settings.model_config.update(_orig_config) # ── normalize_ollama_url ────────────────────────────────────────────────────── diff --git a/tests/unit/test_vassal_agent_health.py b/tests/unit/test_vassal_agent_health.py index 1760708..275078b 100644 --- a/tests/unit/test_vassal_agent_health.py +++ b/tests/unit/test_vassal_agent_health.py @@ -517,8 +517,13 @@ async def test_nudge_stuck_agent_no_token(): """Returns False gracefully when Gitea is not configured.""" from timmy.vassal.agent_health import nudge_stuck_agent - result = await nudge_stuck_agent("claude", 123) - assert result is False + mock_settings = MagicMock() + mock_settings.gitea_enabled = False + mock_settings.gitea_token = "" + + with patch("config.settings", mock_settings): + result = await nudge_stuck_agent("claude", 123) + assert result is False @pytest.mark.asyncio