fix: P1 — MessageType.BUTTON_CLICK → COMMAND (Move-Request Confirm crash)

Root cause: adapter.py referenced MessageType.BUTTON_CLICK which does
not exist in Hermes-Core (only TEXT, COMMAND, PHOTO, etc.). The heuristic
at line 1502 matched MOVE_REQ:room_id::✅Ja text payloads as button
responses, triggering the crash path in _dispatch_agent.

Changes:
1. Heuristic fix: exclude MOVE_REQ: prefix from button detection (line 1502)
2. MessageType.BUTTON_CLICK → MessageType.COMMAND in both dispatch sites
3. DRY refactor: extracted _message_type_for() helper method
4. Updated fallback exception handlers and log messages (BUTTON_CLICK → COMMAND)
5. Regression test: test_p1_button_click_fix.py (6 tests)

Verification:
- python3 -c "from gateway.platforms.base import MessageType; assert hasattr(MessageType,COMMAND)" → OK
- pytest test_v8_3_2.py -k confirm_move → PASSED
- grep BUTTON_CLICK plugin/adapter.py → 1 (docstring only)
- pytest plugin/ -k dispatch → 5 passed
- Full suite: 984 passed, 2 skipped, 0 failures
This commit is contained in:
Bernd (Hermes)
2026-07-19 21:00:31 +02:00
parent 4604f2e123
commit 439cca48be
2 changed files with 131 additions and 11 deletions
@@ -0,0 +1,106 @@
"""
P1 Regression: MessageType.BUTTON_CLICK → COMMAND (Move-Request Confirm crash).
Root cause: adapter.py uses MessageType.BUTTON_CLICK which does not exist
in Hermes-Core's MessageType enum. The heuristic at line 1502 matches
MOVE_REQ:room_id::✅Ja text payloads as button responses, triggering
the crash path in _dispatch_agent.
Tests:
1. RED: adapter.py still references BUTTON_CLICK (will fail until fixed)
2. RED: MOVE_REQ text matches button heuristic (will fail until fixed)
3. GREEN: MessageType.COMMAND exists as replacement
4. GREEN: After fix, normal button text still matches
5. GREEN: After fix, CLARIFY still excluded
"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
class TestP1ButtonClickFix(unittest.TestCase):
"""P1: MessageType.BUTTON_CLICK existiert nicht → COMMAND verwenden."""
# ── RED tests (fail now, pass after fix) ──────────────────────────
def test_adapter_has_no_button_click_references(self):
"""RED: adapter.py darf KEINE BUTTON_CLICK-Referenzen enthalten
(ausser im Docstring der Hilfsfunktion)."""
adapter_path = Path(__file__).resolve().parents[3] / "plugin" / "adapter.py"
content = adapter_path.read_text()
# Count BUTTON_CLICK occurrences (should be <= 1 after fix:
# only the docstring in _message_type_for is acceptable)
count = content.count("BUTTON_CLICK")
self.assertLessEqual(count, 1,
f"adapter.py has {count} BUTTON_CLICK references — "
f"max 1 allowed (docstring only)")
def test_move_req_not_matched_by_button_heuristic(self):
"""RED: MOVE_REQ:room_id::✅Ja darf NICHT als Button-Response matchen."""
text = "MOVE_REQ:abc123::✅Ja"
# Simulate the FIXED heuristic from adapter.py line 1502
has_double_colon = "::" in text
not_clarify = (not text.startswith("CLARIFY:")
and not text.startswith("ARCHIVAR_CLARIFY:"))
not_move_req = not text.startswith("MOVE_REQ:")
prefix_non_empty = text.split("::", 1)[0].strip() != ""
# Fixed heuristic: MOVE_REQ: prefix excluded
is_match = (has_double_colon and not_clarify
and not_move_req and prefix_non_empty)
self.assertFalse(is_match,
"MOVE_REQ: text should NOT match button heuristic")
# ── GREEN tests (pass now, must still pass after fix) ─────────────
def test_message_type_has_command(self):
"""MessageType.COMMAND exists (replacement for BUTTON_CLICK)."""
from gateway.platforms.base import MessageType
self.assertTrue(hasattr(MessageType, "COMMAND"))
self.assertEqual(MessageType.COMMAND.value, "command")
def test_message_type_no_button_click(self):
"""MessageType.BUTTON_CLICK does NOT exist in Hermes-Core."""
from gateway.platforms.base import MessageType
self.assertFalse(hasattr(MessageType, "BUTTON_CLICK"))
def test_normal_button_text_still_matches_after_fix(self):
"""Nach Fix: 'bypass_001::Ja' matched weiterhin als Button-Response."""
text = "bypass_001::Ja"
has_double_colon = "::" in text
not_clarify = (not text.startswith("CLARIFY:")
and not text.startswith("ARCHIVAR_CLARIFY:"))
not_move_req = not text.startswith("MOVE_REQ:")
prefix_non_empty = text.split("::", 1)[0].strip() != ""
is_match = (has_double_colon and not_clarify
and not_move_req and prefix_non_empty)
self.assertTrue(is_match,
"Normal button text 'bypass_001::Ja' must still match")
def test_clarify_text_still_excluded_after_fix(self):
"""Nach Fix: CLARIFY: text weiterhin ausgeschlossen."""
text = "CLARIFY:some_id::answer"
has_double_colon = "::" in text
not_clarify = (not text.startswith("CLARIFY:")
and not text.startswith("ARCHIVAR_CLARIFY:"))
not_move_req = not text.startswith("MOVE_REQ:")
is_match = has_double_colon and not_clarify and not_move_req
self.assertFalse(is_match,
"CLARIFY: text must NOT match button heuristic")
if __name__ == "__main__":
unittest.main()