Files
hermes-agent/tests/hermes_cli/test_doctor_exit_status.py
teknium1 661d73f06b test+docs: trim doctor exit-status tests to two invariants; document the exit code
Keep the in-process return-code matrix (issues / manual / --fix full and
partial repair) and the real-process exit-status check; drop the exception
passthrough, --ack and --live cases, which pin behaviour this change does not
touch. Document 0/1 exit status under `hermes doctor` in the CLI reference.
2026-09-21 01:57:05 -07:00

54 lines
1.9 KiB
Python

"""Regression for #117276: ``hermes doctor``'s exit status must agree with its unresolved findings."""
from types import SimpleNamespace
import pytest
@pytest.mark.parametrize("issues,manual,fixed,fix,expected", [
(["needs repair"], [], 0, False, 1),
([], ["manual repair"], 0, False, 1),
([], [], 0, False, 0),
([], [], 1, True, 0),
([], ["remaining repair"], 1, True, 1),
])
def test_doctor_command_reports_remaining_findings(monkeypatch, capsys, issues, manual, fixed, fix, expected):
import hermes_cli.doctor as doctor
from hermes_cli.main import cmd_doctor
from hermes_cli.doctor_report import Finding
def check(should_fix):
assert should_fix is fix
return Finding(issues=issues, manual_issues=manual, fixed=fixed)
monkeypatch.setattr(doctor, "DOCTOR_CHECKS", ((None, check),))
result = cmd_doctor(SimpleNamespace(fix=fix, ack=None, live=False))
output = capsys.readouterr().out
assert result == expected
for issue in issues + manual:
assert issue in output
@pytest.mark.parametrize("unresolved", [False, True])
def test_doctor_cli_process_status_matches_summary(unresolved):
import subprocess
import sys
from pathlib import Path
program = f"""
import sys
import hermes_cli.doctor as doctor
from hermes_cli.doctor_report import Finding
from hermes_cli.main import main
issues = ['fixture unresolved problem'] if {unresolved!r} else []
doctor.DOCTOR_CHECKS = ((None, lambda fix: Finding(issues=issues)),)
sys.argv = ['hermes', 'doctor']
main()
"""
result = subprocess.run(
[sys.executable, "-c", program],
cwd=Path(__file__).resolve().parents[2],
capture_output=True, text=True, encoding="utf-8", timeout=30,
)
assert result.returncode == int(unresolved), result.stdout + result.stderr
assert ("fixture unresolved problem" if unresolved else "All checks passed") in result.stdout