From 9731339bbb57478833a97f79a6757a9d5abf81b5 Mon Sep 17 00:00:00 2001 From: Anatolii Date: Sat, 11 Jul 2026 19:30:30 +0400 Subject: [PATCH] fix(tests): pin test_runtime WAL to tmp_path to avoid cross-Python flake The test_runtime fixture in test_protect_branches.py built a real NullRunRuntime(api_key, _test_mode=True) without going through the mock_api conftest. The runtime's Transport.start() calls _replay_from_wal() which reads /tmp/nullrun.wal (the default NULLRUN_WAL_PATH fallback). If a previous test run in a different Python version (3.10 or 3.12) had persisted a non-empty WAL, the 3.11 worker would replay those events to a real HTTP endpoint, get HTTP 401, and the fixture would fail at setup with NullRunAuthError: nullrun.breaker.exceptions.NullRunAuthError: Invalid API key This bit CI on 2026-07-11 (run 29156199607): tests 3.10 + 3.12 passed, test 3.11 failed with that error in the fixture setup of test_enforce_sensitive_tool_dict_with_fallback_fail_open. The 3.10/3.12 runs cleared the global /tmp/nullrun.wal by reading it first, so 3.11 picked up the next writer. Order- dependent; flaky on the matrix. Pin NULLRUN_WAL_PATH to a tmp_path-scoped file so each test session reads its own fresh empty WAL. Resolves the flake without touching SDK source (no production code change). Verified locally: - pytest tests/test_protect_branches.py -> 43/43 pass - with pre-seeded stale /tmp/nullrun.wal, the previously failing test now passes. No public API change. No SDK_MIN_VERSION bump. Backends on 1.0.0 keep working unchanged. Recommended: 0.13.6 (no version bump needed for a test-only fix). --- tests/test_protect_branches.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_protect_branches.py b/tests/test_protect_branches.py index cd528cd..9723222 100644 --- a/tests/test_protect_branches.py +++ b/tests/test_protect_branches.py @@ -35,11 +35,20 @@ @pytest.fixture -def test_runtime(monkeypatch): +def test_runtime(monkeypatch, tmp_path): """Provide a runtime in test mode so get_runtime returns without authenticating against a real server. + + Replays any WAL left over from previous test runs in a + tmp_path-scoped WAL file so the constructor's + ``_replay_from_wal`` never reads ``~/.nullrun/sdk.wal`` and + flushes real on-disk events to a live API. This avoids the + cross-Python-version flake seen on CI in 2026-07-11 where + 3.11 picked up a stale WAL from a 3.10/3.12 worker that + finished without explicitly clearing it. """ monkeypatch.setenv("NULLRUN_API_KEY", "test-key-12345678") + monkeypatch.setenv("NULLRUN_WAL_PATH", str(tmp_path / "sdk.wal")) NullRunRuntime.reset_instance() rt = NullRunRuntime(api_key="test-key-12345678", _test_mode=True) rt.organization_id = "org-1"