diff --git a/tests/plugins/test_disk_cleanup_plugin.py b/tests/plugins/test_disk_cleanup_plugin.py index 38fffd5fbf9..52afddc9c46 100644 --- a/tests/plugins/test_disk_cleanup_plugin.py +++ b/tests/plugins/test_disk_cleanup_plugin.py @@ -352,13 +352,24 @@ class TestTrackForgetQuick: for d in ("logs", "memories", "sessions", "cron", "cache"): assert (_isolate_env / d).exists(), f"{d}/ should be preserved" - def test_quick_does_not_descend_into_protected_top_level_dirs(self, _isolate_env): + def test_quick_does_not_descend_into_protected_top_level_dirs( + self, _isolate_env, monkeypatch + ): dg = _load_lib() protected_empty = ( _isolate_env / "hermes-agent" / "node_modules" / "pkg" / "empty" ) protected_empty.mkdir(parents=True) + original_iterdir = Path.iterdir + + def guarded_iterdir(path): + if path == _isolate_env / "hermes-agent": + raise AssertionError("quick() descended into protected hermes-agent/") + return original_iterdir(path) + + monkeypatch.setattr(Path, "iterdir", guarded_iterdir) + dg.quick() assert protected_empty.exists()