import os
import subprocess
import sys
from pathlib import Path

REPO = Path(__file__).resolve().parents[2]


def test_audit_script_exits_zero_on_stub():
    result = subprocess.run(
        [
            sys.executable,
            "recoil/pipeline/tools/audit_dispatch.py",
            "--project", "tartarus",
            "--episode", "ep_001",
            "--fixture-plan", "recoil/pipeline/tools/audit_fixtures/audit_plan.json",
        ],
        cwd=REPO,
        env={"PYTHONPATH": str(REPO), **os.environ},
        capture_output=True,
        text=True,
    )
    assert result.returncode == 0, f"stderr={result.stderr}\nstdout={result.stdout}"
    assert "PASS" in result.stdout
