From 1712a0d79ab52dc63cdb49f1411f7d845e85ef05 Mon Sep 17 00:00:00 2001 From: Tobias Macey Date: Mon, 24 Aug 2026 11:52:14 -0400 Subject: [PATCH] test(witan): stop the merge tests writing to the developer's real state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `witan migrate merge` records a per-pair watermark, and the default path is a real user file beside the token cache. Any test that drives the merge CLI without overriding `WITAN_MERGE_WATERMARKS` therefore writes to the developer's own `~/.config/witan/merge-watermarks.json`. It was doing exactly that. The file had ten entries keyed by `/tmp/pytest-of-*/pytest-NNN/.../personal.omni` from one afternoon's runs, accumulating one per run — each pytest tmp path is unique, so nothing ever replaced anything and the file grew without bound. Nothing in the suite could catch it: every test asserting on watermark contents sets the variable itself and passes, and the leak is a property of the tests that DON'T. It surfaced only because the file was opened by hand before a real merge. Fixed with an autouse fixture next to `no_real_remote`, which exists for the same class of bug. Autouse is the point: opting in is what was already missing. Verified by measurement rather than inspection — snapshot the real file, run the merge tests, compare checksums: 11 pairs / sha 405bb6bf before and after, unchanged. On the unfixed conftest that same run appends an entry. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01BZBrdCenMsbribvmY6zVpe --- mcp/servers/witan/tests/conftest.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mcp/servers/witan/tests/conftest.py b/mcp/servers/witan/tests/conftest.py index ef4d0232..baf26f4c 100644 --- a/mcp/servers/witan/tests/conftest.py +++ b/mcp/servers/witan/tests/conftest.py @@ -94,6 +94,30 @@ def no_real_remote(tmp_path_factory, monkeypatch): monkeypatch.delenv("WITAN_TARGET", raising=False) +@pytest.fixture(autouse=True) +def no_real_merge_watermarks(tmp_path_factory, monkeypatch): + """Keep merge watermarks out of the developer's real ``~/.config/witan``. + + ``witan migrate merge`` records a per-pair watermark, and the default path + is a REAL user file next to the token cache. Any test that drives the merge + CLI without overriding ``WITAN_MERGE_WATERMARKS`` therefore writes to the + developer's own state. + + Not hypothetical, and not caught by the suite: on 2026-08-24 the file had + ten entries keyed by ``/tmp/pytest-of-*/…/personal.omni`` from a single + afternoon's runs — accumulating one per run, since each pytest tmp path is + unique so nothing ever replaced anything. It surfaced only because the file + was opened by hand before a real merge. + + Autouse for the same reason as ``no_real_remote`` above: the leak is a + property of forgetting an override, so the guard has to be the default + rather than something each test opts into. Tests that assert on watermark + contents set the variable themselves, and the later ``setenv`` wins. + """ + marks = tmp_path_factory.mktemp("witan-watermarks") / "merge-watermarks.json" + monkeypatch.setenv("WITAN_MERGE_WATERMARKS", str(marks)) + + @pytest.fixture def tmp_state_dir(tmp_path, monkeypatch): """Redirect the system temp dir, which is where witan parks process state.