Files
hermes-agent/tests/hermes_cli/test_sessions_repair_check_only_exit.py
jango 5a2f512390 fix(cli): exit non-zero from sessions repair --check-only on an unhealthy store
`hermes sessions repair --check-only` printed the corruption reason and
exited 0, so scripts and the console wrapper gating on the status read a
broken state.db as healthy. Return 1 from the CLI handler (main.py already
sys.exits a truthy return) and from the console handler, where
`_capture_output` turns the status into a ConsoleCommandError carrying the
printed reason.

Salvaged from PR #103321 (the check-only reporting part only; the probe
rewrite and connection-tracking changes were not taken). Refs #63386.
2026-09-11 06:37:27 -07:00

29 lines
1.0 KiB
Python

"""`hermes sessions repair --check-only` must fail (non-zero) when the store is unhealthy.
Automation gates on the exit status; printing the reason and exiting 0 read as "healthy"
(#63386, PR #103321).
"""
import argparse
from pathlib import Path
import hermes_state
from hermes_cli import sessions_cmd
from hermes_state import SessionDB
def test_check_only_exit_status_tracks_probe_verdict(tmp_path, monkeypatch):
db_path = tmp_path / "state.db"
SessionDB(db_path=db_path).close()
monkeypatch.setattr(hermes_state, "DEFAULT_DB_PATH", db_path)
args = argparse.Namespace(check_only=True, no_backup=False)
assert not sessions_cmd._cmd_repair(args)
# Destroy the schema header so the probe fails on its first statement.
with open(db_path, "r+b") as f:
f.seek(100)
f.write(b"\xff" * (4096 - 100))
for side in ("-wal", "-shm"):
Path(str(db_path) + side).unlink(missing_ok=True)
assert sessions_cmd._cmd_repair(args) == 1
assert db_path.stat().st_size > 0, "check-only must not touch the file"