feat(F557): Emoji-Number Fallback fuer nicht-interactive Clients @implements: [F-557]

- button_builder.py: _is_numeric_choice() Helper (Inverse der Emoji-Nummer-Generierung)
  erkennt "1", Emoji-Keycap "1", "1.", "1)", "1 rueber", "Option 1" -> 1-basierter Index;
  "0"/"11"/"99" + Multi-Wahl ("1 und 2") -> None
- adapter.py: is_pending_clarify_answer + Plain-Digit-Clarify-Block + Move-Request-Intercept
  von isdigit()/expliziten Listen auf _is_numeric_choice() umgestellt
- Fallback IMMER aktiv (keine Client-Type-Detection, Rainer 2.4)
- test_f557_numeric_choice.py: 29 Tests (Rainer 4: 5 Test-Pflichten + Edge-Case-Matrix)
- KEINE Core-Aenderungen (nur Plugin-Layer)
This commit is contained in:
Bernd (Hermes)
2026-09-26 21:05:22 +02:00
parent d5f6ca66c4
commit 5f376d2588
4 changed files with 229 additions and 18 deletions
@@ -0,0 +1,103 @@
"""
F-557: Emoji-Number Fallback — _is_numeric_choice Helper (Rainer §4).
Deckt die 5 Test-Pflichten aus der Architektur ab:
1. "1" → Wahl 1 (Regression — Plain-Digit, war schon funktional)
2. "1️⃣" → Wahl 1 (L1-Fix — Emoji-Variante war nicht erkannt)
3. "1 rüber" / "Option 1" / "1." → Wahl 1 (L2-Fix — loose Match)
4. "5" / "0" → None (Bounds-Check)
5. "1 und 2" → None (Multi-Wahl nicht erlaubt)
Zusätzlich die parametrisierte Edge-Case-Matrix aus Rainer §4 Test 1.
"""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
from archivar.button_builder import _is_numeric_choice
@pytest.mark.parametrize(
"text,expected",
[
# Plain-Digit (Regression)
("1", 1),
("9", 9),
("10", 10),
# Emoji-Nummern (L1)
("1️⃣", 1),
("🔟", 10),
# Mit Punkt (L2)
("1.", 1),
("9.", 9),
# Whitespace-tolerant
(" 1 ", 1),
("\t2\n", 2),
# Mit Text (L2)
("1 rüber", 1),
("Option 1", 1),
("1)", 1),
("1.)", 1),
# Invalid
("", None),
("abc", None),
("0", None),
# Out of EMOJI_NUMBERS cap (Bounds-Check, Test 4)
("11", None),
("99", None),
("123", None),
# Multi-Wahl (nicht erlaubt, Test 5)
("1 und 2", None),
("1, 2", None),
("1 oder 2", None),
("2 und 3", None),
# None-Eingabe
(None, None),
],
)
def test_is_numeric_choice(text, expected):
assert _is_numeric_choice(text) == expected
def test_plain_digit_regression():
"""Test 1: '1' → Wahl 1 (bereits funktional, Regression-Test)."""
assert _is_numeric_choice("1") == 1
def test_emoji_digit_l1_fix():
"""Test 2: '1️⃣' → Wahl 1 (L1-Fix — Emoji-Variante)."""
assert _is_numeric_choice("1️⃣") == 1
def test_loose_variants_l2_fix():
"""Test 3: '1 rüber' / 'Option 1' / '1.' → Wahl 1 (L2-Fix)."""
assert _is_numeric_choice("1 rüber") == 1
assert _is_numeric_choice("Option 1") == 1
assert _is_numeric_choice("1.") == 1
def test_bounds_check_out_of_range():
"""Test 4: '0' / '11' / '99' → None (Bounds-Check).
Der Helper deckt 1..10 ab (EMOJI_NUMBERS-Cap). Der 4-Bound ist eine
Call-Site-Angelegenheit (Move-Request: 1<=num<=4; Clarify:
idx < len(choices)). '0' ist nicht 1-basiert → None.
"""
assert _is_numeric_choice("0") is None
assert _is_numeric_choice("11") is None
assert _is_numeric_choice("99") is None
def test_multi_choice_not_allowed():
"""Test 5: '1 und 2' → None (Multi-Wahl nicht erlaubt)."""
assert _is_numeric_choice("1 und 2") is None
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-v"]))