Skip to content

The agent that grows with you

test(ci): an import-time class body is not the update running plugin-install code

Teknium0d69d07bb25d
diff --git a/tests/ci/test_update_transitive_routing.py b/tests/ci/test_update_transitive_routing.py
index 4cea2a3bd83..6aeab383604 100644
--- a/tests/ci/test_update_transitive_routing.py
+++ b/tests/ci/test_update_transitive_routing.py
@@ -45,15 +45,21 @@ def test_update_migration_on_a_journey_home_runs_no_plugin_install_code():
ran: set[tuple[str, str]] = set()
def profile(frame, event, _arg):
- if event == "call":
- ran.add((Path(frame.f_code.co_filename).resolve().as_posix(), frame.f_code.co_name))
+ if event != "call" or frame.f_code.co_name == "<module>":
+ return
+ # A class statement or module-level comprehension runs at import, called by its own
+ # file's <module> frame: importing a module is not running its install code.
+ caller = frame.f_back
+ if caller and caller.f_code.co_name == "<module>" and caller.f_code.co_filename == frame.f_code.co_filename:
+ return
+ ran.add((Path(frame.f_code.co_filename).resolve().as_posix(), frame.f_code.co_name))
sys.setprofile(profile)
try:
assert migrate_all_homes() == []
finally:
sys.setprofile(None)
- files = {f for f, name in ran if name != "<module>"}
+ files = {f for f, _name in ran}
assert (_REPO / "hermes_cli/memory_provider_migration.py").resolve().as_posix() in files
hit = [rel for rel in _PLUGIN_INSTALL if (_REPO / rel).resolve().as_posix() in files]
assert hit == [], f"the update runs {hit} on a journey home"