From c0cc8c40c44c16705dc4d2bbc615daa5a6a00d3c Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 15 Jul 2026 15:48:12 -0700 Subject: [PATCH] fix(tests): isolate 4th polluter victim caught in live -n auto run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tests/test_teaching_queue.py::test_read_only_invariant hardcoded `project_root / "engine_state"` (the real shared dir) in its read-only- invariant snapshot, instead of reading `engine_state._DEFAULT_DIR` (the root-conftest autouse fixture's per-test isolated dir). Same bug pattern as test_workbench_replay.py::test_replay_leaves_no_trace, and this one was caught red-handed: a full `-n auto` fast-lane run failed with "Directory .../engine_state was mutated!" and passed cleanly in serial isolation, the exact order-dependent-flake signature this wave hunts. The other three snapshotted dirs (teaching/proposals, packs, contemplation/runs) have no equivalent per-test isolation idiom in the repo yet and are left as-is — this test's own hitl-queue commands don't write to them, so they were not implicated in the observed failure. --- tests/test_teaching_queue.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_teaching_queue.py b/tests/test_teaching_queue.py index acb34315..41a0bcea 100644 --- a/tests/test_teaching_queue.py +++ b/tests/test_teaching_queue.py @@ -9,6 +9,7 @@ from unittest.mock import patch import pytest +import engine_state from core.cli import main from teaching.discovery import DiscoveryCandidate, EvidencePointer from teaching.proposals import ProposalLog, ReplayEvidence, build_proposal @@ -515,11 +516,21 @@ def snapshot_dir(directory: Path) -> dict[Path, bytes]: def test_read_only_invariant(): + """Directories the hitl-queue commands must not mutate. + + ``engine_state`` is read via ``engine_state._DEFAULT_DIR`` (not a + hardcoded ``project_root / "engine_state"``) because the root-conftest + ``_isolate_engine_state_default`` autouse fixture repoints it at a + per-test tmp dir; a hardcoded real path would instead snapshot the + shared repo dir and false-fail under ``-n auto`` whenever an unrelated + concurrent worker wrote to it (observed: AssertionError on this exact + directory under a full `-n auto` fast-lane run). + """ project_root = Path(__file__).resolve().parent.parent dirs = [ project_root / "teaching" / "proposals", project_root / "packs", - project_root / "engine_state", + Path(engine_state._DEFAULT_DIR), project_root / "contemplation" / "runs", ]