fix(test): isolate settings.runs_dir in conftest to stop ambient prod-log pollution (ORCH-100)
test_queue.py::TestRetry::test_finalize_job_requeue_then_fail failed in the self-hosting environment because launcher._finalize_job classifies a non-zero exit by reading the tail of <settings.runs_dir>/<run_id>.log. settings.runs_dir defaults to the live prod dir /app/data/runs, which on the host holds REAL accumulated agent logs; a real 2.log containing "429" flips the expected 'permanent' classification to 'transient', requeueing the job instead of marking it 'failed'. This is ambient prod pollution, not a code fault. Add an autouse _isolate_runs_dir fixture (mirroring _no_telegram / _disable_merge_verify) that redirects settings.runs_dir to a per-test tmp dir so _run_log_path() resolves to a non-existent file and classify_log_file() returns the documented 'permanent' default. Full suite: 1617 passed. src/** untouched. Refs: ORCH-100 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -77,6 +77,34 @@ def _reset_webhook_secrets(monkeypatch):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _isolate_runs_dir(monkeypatch, tmp_path):
|
||||
"""ORCH-100: point settings.runs_dir at a per-test tmp dir in ALL tests.
|
||||
|
||||
Background: ``launcher._run_log_path(run_id)`` resolves to
|
||||
``<settings.runs_dir>/<run_id>.log`` and, on a non-zero exit,
|
||||
``_finalize_job`` classifies the failure by reading the *tail of that log*
|
||||
(transient 429/overload/timeout -> backoff-requeue; permanent -> attempts
|
||||
requeue then 'failed'). settings.runs_dir defaults to the live prod dir
|
||||
``/app/data/runs``, which on the self-hosting host holds REAL accumulated
|
||||
agent logs (1.log, 2.log, ...). Tests that exercise the finalize path with a
|
||||
small literal run_id (e.g. test_finalize_job_requeue_then_fail uses run_id=1/2)
|
||||
therefore read whatever a real prod run happened to log — and a real 2.log that
|
||||
contains "429" silently flips an expected 'permanent' classification to
|
||||
'transient', requeueing instead of failing. That is ambient prod pollution, not
|
||||
a code fault.
|
||||
|
||||
Redirecting runs_dir to an empty tmp dir makes _run_log_path() resolve to a
|
||||
non-existent file -> classify_log_file() returns the documented 'permanent'
|
||||
default, restoring deterministic, environment-independent behaviour for the
|
||||
whole suite. settings is a process-wide singleton shared by launcher
|
||||
(``launcher.settings is config.settings``), so patching the source covers it.
|
||||
"""
|
||||
from src import config as _cfg
|
||||
monkeypatch.setattr(_cfg.settings, "runs_dir", str(tmp_path), raising=False)
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _disable_merge_verify(monkeypatch):
|
||||
"""ORCH-071: disable the merge-verify under-gate by default in ALL tests.
|
||||
|
||||
Reference in New Issue
Block a user