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:
1 parent
e8d9151226
commit
ab93776d6d
4 files changed
+125
-4
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""Issue #45 (B), review round 2 R2: resume closes a restored pane only when
|
||||
herdr's answer proves the shell is in the foreground. Odd pid values - missing,
|
||||
null, 0, negative, bool, string - must leave the pane alone. herdr is a stub
|
||||
here; the real-server behaviour is tests/test_issue45_restore.py."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / ".agents" / "skills"))
|
||||
from lib_py import herdr_restore as hr # noqa: E402
|
||||
|
||||
SID = "probe-id"
|
||||
|
||||
|
||||
def _stub(monkeypatch, process_info):
|
||||
calls = []
|
||||
|
||||
def fake(herdr, session, *args):
|
||||
calls.append(args)
|
||||
if args[:2] == ("pane", "list"):
|
||||
return {"panes": [{"pane_id": "probe-pane", "agent": None, "agent_session": {"value": SID}}]}
|
||||
if args[:2] == ("pane", "process-info"):
|
||||
return {"process_info": process_info}
|
||||
return {}
|
||||
monkeypatch.setattr(hr, "_herdr", fake)
|
||||
return calls
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shell,fg", [(0, 0), (False, False), ("", ""), (-1, -1), (None, None),
|
||||
("123", "123"), (True, True), (1.0, 1.0)],
|
||||
ids=["zero", "false", "empty", "negative", "null", "string", "true", "float"])
|
||||
def test_an_odd_pid_answer_leaves_the_pane_alone(monkeypatch, shell, fg):
|
||||
calls = _stub(monkeypatch, {"shell_pid": shell, "foreground_process_group_id": fg})
|
||||
assert hr.close_restored_shells(SID, session="m45-review-probe") == []
|
||||
assert ("pane", "close", "probe-pane") not in calls
|
||||
|
||||
|
||||
def test_a_missing_process_info_leaves_the_pane_alone(monkeypatch):
|
||||
calls = _stub(monkeypatch, {})
|
||||
assert hr.close_restored_shells(SID, session="m45-review-probe") == []
|
||||
assert ("pane", "close", "probe-pane") not in calls
|
||||
|
||||
|
||||
def test_a_real_shell_in_the_foreground_is_closed(monkeypatch):
|
||||
calls = _stub(monkeypatch, {"shell_pid": 4242, "foreground_process_group_id": 4242})
|
||||
assert hr.close_restored_shells(SID, session="m45-review-probe") == ["probe-pane"]
|
||||
assert ("pane", "close", "probe-pane") in calls
|
||||
|
||||
|
||||
def test_a_busy_pane_is_left_alone(monkeypatch):
|
||||
calls = _stub(monkeypatch, {"shell_pid": 4242, "foreground_process_group_id": 4300})
|
||||
assert hr.close_restored_shells(SID, session="m45-review-probe") == []
|
||||
assert ("pane", "close", "probe-pane") not in calls
|
||||
Reference in new issue
Block a user