Skip to content

The agent that grows with you

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)

Teknium1bc3af0c05d6
diff --git a/tests/agent/test_empty_tool_name_loop_dampening.py b/tests/agent/test_empty_tool_name_loop_dampening.py
index ab7d16d0c76..7076f75f8d2 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 86827c41cbc..a059383e117 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
[email protected](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_"):