fix(issue-45): review round 2 - an unrunnable config check is not a pass, odd pids never close a pane, nan does not drop settings

codex round 2 (PR #48).

- R1: when `herdr config check` could not run (timeout, OSError), the
  merged config was handed to the server as checked. A merge with a schema
  error makes herdr drop the whole file, restore back on - the #45 failure.
  The merged body is no longer used unchecked: _write_checked falls to the
  fixed MINIMAL config with a warning. When the check cannot run on MINIMAL
  either, MINIMAL is still used (with its own warning) rather than no
  config: returning none would leave restore on, and MINIMAL is a fixed
  two-line file the real-herdr test accepts. Unknown non-zero exits stay as
  they were - herdr exits non-zero for harmless warnings (an unknown
  section) that do not drop the file.
- R2: _shell_in_foreground compared shell_pid and the foreground group with
  ==, so 0/0, False/False, ""/"" or -1/-1 closed the pane. Both must now be
  positive ints (bool excluded) before they are compared.
- R3: the re-parse check used ==, and nan != nan, so a valid TOML nan threw
  away every other user setting even on Python 3.11. _same_doc compares
  documents recursively with nan equal to nan.

Tests: R1 (timeout, OSError) and R3 (top-level, array, nested nan) in
test_issue45_herdr_config.py; R2 in the new tests/test_issue45_restore_unit.py
(a herdr stub: zero, false, empty, negative, null, string, true, float;
missing info; a real shell closed; a busy pane kept). On the previous code
12 of them fail. Python 3.11: 67 passed; Python 3.9: 33 passed / 34 skipped
(tomllib-only). Real-herdr restore tests and related files on 3.9: 197
passed / 1 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgu9Fa9iT7TbJUSzdq4Ff
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-10-05 17:50:15 +09:00
1 parent e8d9151226
commit ab93776d6d
4 files changed
+125 -4

No files matched your search

+8 -2
View File
@@ -43,8 +43,14 @@ def _herdr(herdr: str, session: str, *args: str) -> dict:
def _shell_in_foreground(herdr: str, session: str, pane_id: str) -> bool:
info = _herdr(herdr, session, "pane", "process-info", "--pane", pane_id).get("process_info") or {}
shell = info.get("shell_pid")
return shell is not None and info.get("foreground_process_group_id") == shell
shell, fg = info.get("shell_pid"), info.get("foreground_process_group_id")
# Only a real pid proves anything (review R2): None, 0, -1, False, "" or a
# string must leave the pane alone, however they compare.
return _is_pid(shell) and _is_pid(fg) and fg == shell
def _is_pid(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) and v > 0
def close_restored_shells(session_id: str, herdr: str = "herdr",