From 804691501f24739d5d86bd91149f20315538fa36 Mon Sep 17 00:00:00 2001 From: Victor <124416658+victorv2i@users.noreply.github.com> Date: Thu, 18 Jun 2026 14:54:15 -0400 Subject: [PATCH] test: stop test_skill_index_prompt_injection leaking a stub prefs_routes (#4387) _patch_prefs installs a fake routes.prefs_routes with a bare sys.modules[...] = assignment that is never undone. The stub is an empty ModuleType without _save_for_user, so a later test whose code path runs `from routes.prefs_routes import _save_for_user` (e.g. test_backup_import_skills) fails with ImportError under an unfavorable test order. Install the stub with monkeypatch.setitem instead (the helper already takes monkeypatch and uses it for DATA_DIR) so it is reverted at teardown. Repro: pytest tests/test_skill_index_prompt_injection.py tests/test_backup_import_skills.py (1 failed before, 5 passed after). --- tests/test_skill_index_prompt_injection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_skill_index_prompt_injection.py b/tests/test_skill_index_prompt_injection.py index 865e727bb..710a00032 100644 --- a/tests/test_skill_index_prompt_injection.py +++ b/tests/test_skill_index_prompt_injection.py @@ -105,7 +105,7 @@ def _patch_prefs(monkeypatch, data_dir): "skills_enabled": True, "auto_approve_skills": True, } - sys.modules["routes.prefs_routes"] = fake_prefs + monkeypatch.setitem(sys.modules, "routes.prefs_routes", fake_prefs) # Bust the base-prompt cache so our test re-reads the skill index. from src import agent_loop