test(herdr): add regression tests for pane misattribution and idle-pane reuse
- Add test_r2 and test_r3 for bare-kind fallback restriction and R-1 exact-match enforcement - Add test_h24 and test_h25 for idle-pane reuse and env_flags preservation
This commit is contained in:
@@ -622,3 +622,75 @@ echo "RC=$rc|PID=$pid"
|
||||
assert "RC=1|PID=" in res.stdout, f"Expected fail-closed RC=1 and empty PID: {res.stdout}"
|
||||
|
||||
|
||||
def test_r2_resolve_pane_id_does_not_misattribute_unrelated_same_kind_pane():
|
||||
"""BUG-1: a single unrelated same-kind pane must not be silently returned
|
||||
as the target — the generic agent_kind fallback only applies when the
|
||||
caller searched by the bare kind itself, not when a specific session
|
||||
name's own pane is missing but another agy/claude/... pane exists."""
|
||||
helper = _lib_helper_src()
|
||||
script = helper + """
|
||||
# Ambient HERDR_WORKSPACE_ID (this session itself runs inside a herdr pane)
|
||||
# must not leak into the test — it would scope-filter the mock pane list
|
||||
# and mask the fallback logic under test.
|
||||
unset HERDR_WORKSPACE_ID 2>/dev/null || true
|
||||
|
||||
# Mock real herdr pane list returning exactly ONE unrelated agy pane —
|
||||
# this is the exact single-match scenario the old code misattributed.
|
||||
_real_herdr() {
|
||||
cat << 'EOF'
|
||||
{"result": {"panes": [
|
||||
{"pane_id": "w1:p1", "label": "orchestrator-agy", "agent": "agy"}
|
||||
]}}
|
||||
EOF
|
||||
}
|
||||
|
||||
# creator-agy-01's own pane is gone (it died); yaml still lists it as agy-kind.
|
||||
mkdir -p .mam
|
||||
cat << 'EOF' > .mam/agent-sessions.yaml
|
||||
herdr_sessions:
|
||||
- name: creator-agy-01
|
||||
pane:
|
||||
cmd: agy
|
||||
EOF
|
||||
|
||||
rc=0
|
||||
pid=$(_resolve_herdr_pane_id "creator-agy-01") || rc=$?
|
||||
echo "RC=$rc|PID=$pid"
|
||||
"""
|
||||
res = _run_lib_helpers(script)
|
||||
assert res.returncode == 0, res.stderr + res.stdout
|
||||
assert "RC=1|PID=" in res.stdout, (
|
||||
f"Expected fail-closed RC=1 (must NOT misattribute the unrelated "
|
||||
f"orchestrator-agy pane as creator-agy-01): {res.stdout}"
|
||||
)
|
||||
|
||||
|
||||
def test_r3_resolve_pane_id_bare_kind_multiple_panes_fails_closed():
|
||||
"""Finding B: a bare-kind search (e.g. target='agy') when multiple panes
|
||||
of that agent kind exist must fail-closed (RC=1), not match the first
|
||||
pane via an un-guarded exact match loop."""
|
||||
helper = _lib_helper_src()
|
||||
script = helper + """
|
||||
unset HERDR_WORKSPACE_ID 2>/dev/null || true
|
||||
|
||||
_real_herdr() {
|
||||
cat << 'EOF'
|
||||
{"result": {"panes": [
|
||||
{"pane_id": "w1:p1", "label": "orchestrator-agy", "agent": "agy"},
|
||||
{"pane_id": "w1:p2", "label": "creator-agy-01", "agent": "agy"}
|
||||
]}}
|
||||
EOF
|
||||
}
|
||||
|
||||
rc=0
|
||||
pid=$(_resolve_herdr_pane_id "agy") || rc=$?
|
||||
echo "RC=$rc|PID=$pid"
|
||||
"""
|
||||
res = _run_lib_helpers(script)
|
||||
assert res.returncode == 0, res.stderr + res.stdout
|
||||
assert "RC=1|PID=" in res.stdout, (
|
||||
f"Expected fail-closed RC=1 for ambiguous multiple same-kind panes on bare-kind target: {res.stdout}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user