Auditor recorded output

← All 27 packs

Test-only

mtime bump collides for same-length rewrites, defeating the 'every write' guarantee

buglow tests/conftest.py:8

The finding

The new mtime is computed as the post-write mtime plus len(text)+1. That offset depends only on content length, not on a per-write counter. Linux stamps file mtimes from a coarse clock with roughly 1–4 ms granularity, so two quick rewrites of the same file can get the same base mtime. If both texts have the same length (e.g. 'a: 1' then 'a: 2'), they end up with identical bumped mtimes. An mtime-keyed cache under test then serves stale content. Depending on timing, a test can pass or fail spuriously, which contradicts the fixture's stated purpose.

    1| from __future__ import annotations
    2| 
    3| import os
    4| from pathlib import Path
    5| 
    6| import pytest
    7| 
    8| 
    9| @pytest.fixture
   10| def write_file(tmp_path):
   11|     """Write a file and bump its mtime, so mtime-keyed caches see every write."""
   12| 
   13|     def write(name: str, text: str) -> Path:
   14|         path = tmp_path / name
   15|         path.write_text(text)
   16|         st = path.stat()
   17|         os.utime(path, (st.st_atime, st.st_mtime + len(text) + 1))
   18|         return path
   19| 
   20|     return write

The work pack

Recommendation. Use a strictly increasing per-fixture counter or timestamp. For example, keep last = [0] in the fixture closure, set new = max(st.st_mtime_ns, last[0]) + 1_000_000_000, then call os.utime(path, ns=(st.st_atime_ns, new)) and update last[0] = new. This guarantees each write gets a distinct, later mtime.

Acceptance criteria

  • Address: mtime bump collides for same-length rewrites, defeating the 'every write' guarantee
  • Keep the change scoped to the cited file/symbols unless impact requires otherwise
  • Use a strictly increasing per-fixture counter or timestamp. For example, keep last = [0] in the fixture closure, set new = max(st.st_mtime_ns, last[0]) + 1_000_000_000, then call os.utime(path, ns=(st.st_atime_ns, new)) and update `la
  • Re-check tests/conftest.py after the fix

Status

  1. claimed
  2. resolved

The fix

cac61f0b6c test: write_file gives every write a strictly later mtime.

diff --git a/tests/conftest.py b/tests/conftest.pyindex b63a53c..d1f0669 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -19,13 +19,18 @@ def no_suite_settings(monkeypatch):  @pytest.fixture def write_file(tmp_path):-    """Write a file and bump its mtime, so mtime-keyed caches see every write."""+    """Write a file and bump its mtime, so mtime-keyed caches see every write.++    Each write's mtime is a second past both its own and the previous write's, so two quick rewrites (the+    filesystem clock is coarse) never share one, whatever their contents."""+    last = [0]      def write(name: str, text: str) -> Path:         path = tmp_path / name         path.write_text(text)         st = path.stat()-        os.utime(path, (st.st_atime, st.st_mtime + len(text) + 1))+        last[0] = max(st.st_mtime_ns, last[0]) + 1_000_000_000+        os.utime(path, ns=(st.st_atime_ns, last[0]))         return path      return writediff --git a/tests/test_conftest.py b/tests/test_conftest.pynew file mode 100644index 0000000..32eb5ec--- /dev/null+++ b/tests/test_conftest.py@@ -0,0 +1,22 @@+"""The shared fixtures keep their promises."""++from __future__ import annotations++import os+from pathlib import Path++COARSE_NS = 1_700_000_000 * 1_000_000_000+++def test_write_file_gives_every_rewrite_a_later_mtime(write_file, monkeypatch):+    # A coarse filesystem clock: every write lands on the same mtime, as quick rewrites can on a real one.+    plain = Path.write_text++    def coarse(self, text, *args, **kwargs):+        written = plain(self, text, *args, **kwargs)+        os.utime(self, ns=(COARSE_NS, COARSE_NS))+        return written++    monkeypatch.setattr(Path, "write_text", coarse)+    stamps = [write_file("p.yaml", f"a: {i}").stat().st_mtime_ns for i in range(5)]  # same length every time+    assert all(b > a for a, b in zip(stamps, stamps[1:], strict=False))

How it was judged

Test-only test-only change; the tests ran and passed

Judged 24 Nov 2026, 04:52 UTC against dev at d0c0f66.

The patch only changes tests. They ran and passed, which is all a test-only change can show, so the pack resolved as test_only.