From 8f6f56f481cecf95ed771df729b7cba9e2929f34 Mon Sep 17 00:00:00 2001 From: anti Date: Sun, 10 May 2026 07:18:50 -0400 Subject: [PATCH] fix(test): restore decnet.cli in sys.modules via monkeypatch to prevent agent-mode app stripping from leaking into subsequent tests --- tests/cli/test_mode_gating.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cli/test_mode_gating.py b/tests/cli/test_mode_gating.py index 1b18b8a5..5800cb51 100644 --- a/tests/cli/test_mode_gating.py +++ b/tests/cli/test_mode_gating.py @@ -79,10 +79,10 @@ def test_defence_in_depth_direct_call_fails_in_agent_mode(monkeypatch): monkeypatch.setenv("DECNET_MODE", "agent") monkeypatch.setenv("DECNET_DISALLOW_MASTER", "true") # Re-import cli so the module-level gate re-runs (harmless here; - # we're exercising the in-function guard). - for mod in list(sys.modules): - if mod == "decnet.cli": - sys.modules.pop(mod) + # we're exercising the in-function guard). Use monkeypatch.delitem so + # the original cached module is restored after the test and subsequent + # tests don't see the agent-mode-stripped app singleton. + monkeypatch.delitem(sys.modules, "decnet.cli", raising=False) from decnet.cli import _require_master_mode import typer with pytest.raises(typer.Exit):