Skip to content

The agent that grows with you

fix(doctor): return failure for unresolved findings

funky-xamarine1790567395d
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py
index 81a64f76ea1..107b563b63a 100644
--- a/hermes_cli/doctor.py
+++ b/hermes_cli/doctor.py
@@ -185,6 +185,7 @@ def run_doctor(args):
from hermes_cli.doctor_live import maybe_run_live_checks
maybe_run_live_checks(args, total.manual_issues)
_print_summary(should_fix, total)
+ return int(bool(total.issues or total.manual_issues))
# ---- BEGIN PLUGIN-COMPAT (revert-scheduled; see COMPAT_MANIFEST.md) ----
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 5d8ffdca864..fe96b0348be 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -1910,7 +1910,7 @@ cmd_webhook = _forward_command("cmd_webhook", "hermes_cli.webhook", "webhook_com
cmd_kanban = _forward_command("cmd_kanban", "hermes_cli.kanban", "kanban_command", forward_return=True, doc='Multi-profile collaboration board.')
cmd_project = _forward_command("cmd_project", "hermes_cli.projects_cmd", "projects_command", forward_return=True, doc='Manage projects (named, multi-folder workspaces).')
cmd_hooks = _forward_command("cmd_hooks", "hermes_cli.hooks", "hooks_command", doc='Shell-hook inspection and management.')
-cmd_doctor = _forward_command("cmd_doctor", "hermes_cli.doctor", "run_doctor", doc='Check configuration and dependencies.')
+cmd_doctor = _forward_command("cmd_doctor", "hermes_cli.doctor", "run_doctor", forward_return=True, doc='Check configuration and dependencies.')
cmd_dump = _forward_command("cmd_dump", "hermes_cli.dump", "run_dump", doc='Dump setup summary for support/debugging.')
cmd_debug = _forward_command("cmd_debug", "hermes_cli.debug", "run_debug", doc='Debug tools (share report, etc.).')
cmd_skin = _forward_command("cmd_skin", "hermes_cli.skin_cmd", "skin_command", doc='Skin management (list / use / set).')
diff --git a/tests/hermes_cli/test_doctor_exit_status.py b/tests/hermes_cli/test_doctor_exit_status.py
new file mode 100644
index 00000000000..d083ac1be7c
--- /dev/null
+++ b/tests/hermes_cli/test_doctor_exit_status.py
@@ -0,0 +1,89 @@
+"""Doctor's exit status must agree with its unresolved findings."""
+from types import SimpleNamespace
+
+import pytest
+
+
[email protected]("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
+
+
+def test_doctor_preserves_check_exception(monkeypatch):
+ import hermes_cli.doctor as doctor
+ from hermes_cli.main import cmd_doctor
+
+ def broken(_fix):
+ raise RuntimeError("check failed")
+
+ monkeypatch.setattr(doctor, "DOCTOR_CHECKS", ((None, broken),))
+ with pytest.raises(RuntimeError, match="check failed"):
+ cmd_doctor(SimpleNamespace(fix=False, ack=None, live=False))
+
+
+def test_doctor_ack_keeps_success_fast_path(monkeypatch):
+ import hermes_cli.doctor as doctor
+ from hermes_cli.main import cmd_doctor
+
+ acknowledged = []
+ monkeypatch.setattr(doctor, "_ack_advisory", acknowledged.append)
+ assert cmd_doctor(SimpleNamespace(ack="example")) is None
+ assert acknowledged == ["example"]
+
+
+def test_live_findings_affect_exit_status(monkeypatch):
+ import hermes_cli.doctor as doctor
+ import hermes_cli.doctor_live as live
+ from hermes_cli.main import cmd_doctor
+
+ def probe(args, issues):
+ assert args.live is True
+ issues.append("live route unavailable")
+
+ monkeypatch.setattr(doctor, "DOCTOR_CHECKS", ())
+ monkeypatch.setattr(live, "maybe_run_live_checks", probe)
+ assert cmd_doctor(SimpleNamespace(fix=False, ack=None, live=True)) == 1
+
+
[email protected]("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