From 1bc3af0c05d6473e87b9c6977dc99a99efb3f47f Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 3 Sep 2026 16:11:41 -0700 Subject: [PATCH] fix(compat-fallout): sys.modules-wiping agent tests restore the original module objects afterwards (their wipe of hermes_*/tools.* detached sibling files' monkeypatches now that facades no longer re-import the defining modules) --- tests/agent/test_empty_tool_name_loop_dampening.py | 6 ++++++ tests/agent/test_verification_stop_caching.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/agent/test_empty_tool_name_loop_dampening.py b/tests/agent/test_empty_tool_name_loop_dampening.py index ab7d16d0c7..7076f75f8d 100644 --- a/tests/agent/test_empty_tool_name_loop_dampening.py +++ b/tests/agent/test_empty_tool_name_loop_dampening.py @@ -136,6 +136,7 @@ def agent_env(): # Import fresh so the patched conversation_loop is exercised even when the # module was imported earlier in the same worker. + saved_modules = dict(sys.modules) # restored in finally — see below for mod in list(sys.modules): if mod == "run_agent" or mod.startswith("agent.") or mod.startswith("tools.") or mod.startswith("hermes_"): del sys.modules[mod] @@ -155,6 +156,11 @@ def agent_env(): finally: srv.shutdown() shutil.rmtree(test_home, ignore_errors=True) + # Put the original module objects back: sibling test files hold module-level + # references into hermes_cli.*/tools.* and their monkeypatches would otherwise + # land on modules the app no longer imports. + sys.modules.clear() + sys.modules.update(saved_modules) if prev_home is None: os.environ.pop("HERMES_HOME", None) else: diff --git a/tests/agent/test_verification_stop_caching.py b/tests/agent/test_verification_stop_caching.py index 86827c41cb..a059383e11 100644 --- a/tests/agent/test_verification_stop_caching.py +++ b/tests/agent/test_verification_stop_caching.py @@ -19,6 +19,18 @@ from unittest.mock import MagicMock import pytest +@pytest.fixture(autouse=True) +def _restore_sys_modules(): + """``_fresh_run_agent`` wipes the agent stack out of ``sys.modules``. Put the original + module objects back afterwards: sibling test files hold module-level references into + ``hermes_cli.*`` / ``tools.*`` and their monkeypatches would otherwise land on modules + the app no longer imports.""" + saved = dict(sys.modules) + yield + sys.modules.clear() + sys.modules.update(saved) + + def _fresh_run_agent(hermes_home): for mod in list(sys.modules): if mod == "run_agent" or mod.startswith("agent.") or mod.startswith("tools.") or mod.startswith("hermes_"):