diff --git a/tests/cache/test_cache_correctness.py b/tests/cache/test_cache_correctness.py index 94f2c7109..01b161d3e 100644 --- a/tests/cache/test_cache_correctness.py +++ b/tests/cache/test_cache_correctness.py @@ -1939,11 +1939,19 @@ def close(self) -> None: assert monitor.closed is True +@pytest.mark.parametrize("retry_capture", [False, True], ids=["initial-capture", "retried-capture"]) def test_identity_capture_closes_darwin_monitor_on_retained_keyboard_interrupt( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, + retry_capture: bool, ) -> None: created_monitors: list[Any] = [] + stat_comparisons = 0 + + def stat_matches(_left: os.stat_result, _right: os.stat_result) -> bool: + nonlocal stat_comparisons + stat_comparisons += 1 + return not retry_capture or stat_comparisons > 1 class StubDarwinPathMonitor: def __init__(self, _file_path: str, _ancestor_identity: tuple[Any, ...]) -> None: @@ -1961,16 +1969,25 @@ def interrupt_hash(_path: str, _file_stat: os.stat_result) -> str: file_path = _make_cacheable_file(tmp_path) cache = ScanResultsCache(str(tmp_path / "cache")) + ancestor_identity = cache._capture_ancestor_identity(str(file_path)) + barrier_token = max(1, *(entry[-1] for entry in ancestor_identity)) + 1 + monkeypatch.setattr(cache, "_get_file_change_token", lambda _path, _stat: 1) + monkeypatch.setattr(cache, "_capture_ancestor_identity", lambda _path: ancestor_identity) + monkeypatch.setattr(cache, "_advance_change_clock", lambda *_args: barrier_token) + monkeypatch.setattr(cache, "_stat_matches", stat_matches) monkeypatch.setattr(scan_results_cache_module.sys, "platform", "darwin") monkeypatch.setattr(scan_results_cache_module, "_DarwinPathMonitor", StubDarwinPathMonitor) monkeypatch.setattr(cache.hasher, "hash_file_with_stat", interrupt_hash) - with pytest.raises(KeyboardInterrupt, match="identity hashing interrupted") as interruption: - cache.capture_file_identity(str(file_path)) + with tempfile.TemporaryFile(mode="w+b", dir=tmp_path) as probe: + monkeypatch.setattr(cache, "_get_change_clock_probe", lambda _path, _device: probe) + with pytest.raises(KeyboardInterrupt, match="identity hashing interrupted") as interruption: + cache.capture_file_identity(str(file_path)) assert interruption.traceback is not None - assert len(created_monitors) == 1 - assert created_monitors[0].closed is True + assert stat_comparisons == (2 if retry_capture else 1) + assert len(created_monitors) == stat_comparisons + assert all(monitor.closed for monitor in created_monitors) @pytest.mark.parametrize("retry_capture", [False, True], ids=["initial-capture", "retried-capture"]) diff --git a/tests/test_dependency_lock.py b/tests/test_dependency_lock.py index 9866da2e4..00d19ddfb 100644 --- a/tests/test_dependency_lock.py +++ b/tests/test_dependency_lock.py @@ -19,6 +19,7 @@ RENOVATE_CONFIG = ROOT_DIR / "renovate.json" PICKLESCAN_PYPROJECT = ROOT_DIR / "packages" / "modelaudit-picklescan" / "pyproject.toml" PATCHED_GITPYTHON_FLOOR = (3, 1, 60) +PATCHED_ANYIO_FLOOR = (4, 14, 2) PINNED_MATURIN_BACKEND = "maturin===1.13.3" PATCHED_PY7ZR_REQUIREMENT = "py7zr>=1.1.3" PY7ZR_EXTRAS = ("sevenzip", "all-ci", "all") @@ -82,6 +83,7 @@ def test_gitpython_lock_stays_on_patched_release_floor() -> None: ("package_name", "patched_floor"), [ ("aiohttp", (3, 14, 3)), + ("anyio", PATCHED_ANYIO_FLOOR), ("cryptography", (50, 0, 0)), ("keras", (3, 15, 0)), ("sqlparse", (0, 6, 0)),