diff --git a/plugin/adapter.py b/plugin/adapter.py index 24c524a..cb24e17 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -4638,16 +4638,29 @@ class RocketChatAdapter(BasePlatformAdapter): f"Möchtest du den Butler-Mode ändern oder beibehalten?\n\n" f"👉 Klicke auf einen Button:" ) - butler_buttons = _build( - ["✏️ Ändern", "⏭️ Skip"], + # Reihe 1: Ändern-Button + butler_buttons_row1 = _build( + ["✏️ Ändern"], prefix="REVIEW_BUTLER", style="primary", ) - butler_attachments = [{ - "color": "#1d74f5", - "title": "Butler-Mode Review", - "actions": butler_buttons, - }] + # Reihe 2: Beibehalten (Sonderschaltfläche) + butler_buttons_row2 = _build( + ["⏭️ Beibehalten"], + prefix="REVIEW_BUTLER", + style="default", + ) + butler_attachments = [ + { + "color": "#1d74f5", + "title": "Butler-Mode Review", + "actions": butler_buttons_row1, + }, + { + "color": "#1d74f5", + "actions": butler_buttons_row2, + }, + ] await self._post_message_with_retry( operator_room_id, butler_text, attachments=butler_attachments ) @@ -4695,16 +4708,29 @@ class RocketChatAdapter(BasePlatformAdapter): f"Möchtest du den FAKT-Speicherort ändern oder beibehalten?\n\n" f"👉 Klicke auf einen Button:" ) - fakt_buttons = _build( - ["✏️ Ändern", "⏭️ Skip"], + # Reihe 1: Ändern-Button + fakt_buttons_row1 = _build( + ["✏️ Ändern"], prefix="REVIEW_FAKT", style="primary", ) - fakt_attachments = [{ - "color": "#1d74f5", - "title": "FAKT-Speicherort Review", - "actions": fakt_buttons, - }] + # Reihe 2: Beibehalten (Sonderschaltfläche) + fakt_buttons_row2 = _build( + ["⏭️ Beibehalten"], + prefix="REVIEW_FAKT", + style="default", + ) + fakt_attachments = [ + { + "color": "#1d74f5", + "title": "FAKT-Speicherort Review", + "actions": fakt_buttons_row1, + }, + { + "color": "#1d74f5", + "actions": fakt_buttons_row2, + }, + ] await self._post_message_with_retry( operator_room_id, fakt_text, attachments=fakt_attachments ) @@ -4729,11 +4755,22 @@ class RocketChatAdapter(BasePlatformAdapter): prefix="BUTLER", style="primary", ) - butler_attachments = [{ - "color": "#1d74f5", - "title": "Butler-Modus wählen", - "actions": butler_buttons, - }] + butler_back = _build( + ["↩️ Zurück"], + prefix="REVIEW_BUTLER", + style="default", + ) + butler_attachments = [ + { + "color": "#1d74f5", + "title": "Butler-Modus wählen", + "actions": butler_buttons, + }, + { + "color": "#1d74f5", + "actions": butler_back, + }, + ] # Wechsle in butler_mode Phase (existierende Logik) self._onboarding_state = { "phase": "butler_mode", @@ -4783,16 +4820,27 @@ class RocketChatAdapter(BasePlatformAdapter): "4️⃣ **Keine Sammlung** — FAKT-Nachrichten werden nicht persistiert\n\n" "👉 Klicke auf einen Button oder antworte mit 1–4:" ) - fakt_buttons = _build( - ["1️⃣ Standard", "2️⃣ Neu", "3️⃣ Vorhanden", "4️⃣ Keine"], + fakt_buttons_row1 = _build( + ["1️⃣ Standard", "2️⃣ Neu", "3️⃣ Vorhanden"], prefix="FAKT", style="primary", ) - fakt_attachments = [{ - "color": "#1d74f5", - "title": "FAKT-Speicherort wählen", - "actions": fakt_buttons, - }] + fakt_buttons_row2 = _build( + ["4️⃣ Keine", "⏭️ Skip"], + prefix="FAKT", + style="primary", + ) + fakt_attachments = [ + { + "color": "#1d74f5", + "title": "FAKT-Speicherort wählen", + "actions": fakt_buttons_row1, + }, + { + "color": "#1d74f5", + "actions": fakt_buttons_row2, + }, + ] # Wechsle in fakt_store Phase (existierende Logik) self._onboarding_state = { "phase": "fakt_store", diff --git a/plugin/archivar/onboarding_review.py b/plugin/archivar/onboarding_review.py index 43c8c36..4c3f97d 100644 --- a/plugin/archivar/onboarding_review.py +++ b/plugin/archivar/onboarding_review.py @@ -153,6 +153,81 @@ def _persist_room_map_changes( logger.warning("FAISS-Rebuild fehlgeschlagen: %s", e) +# ── UX REFACTOR: build_button_attachments() Helper ────────────────────────── + +# Emoji-Nummern für bis zu 10 Buttons +_EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] + +# Sonderschaltflächen-Erkennung (diese bekommen KEINE Nummer) +_SPECIAL_BUTTON_PATTERNS = ["↩️", "⏭️", "➕"] + + +def build_button_attachments( + num_buttons: List[Tuple[str, str]], + special_buttons: List[Tuple[str, str, str]], + color: str = "#1d74f5", + title: str = "", +) -> List[dict]: + """Baut Attachments nach Andreas' 2-Reihen-Button-Pattern. + + Regeln: + - Nummerierte Buttons: max 3 pro Attachment, mit 1️⃣ 2️⃣ 3️⃣... + - Sonderschaltflächen (↩️ Zurück, ⏭️ Skip, ➕ Neu): KEINE Nummer, + IMMER in separatem (letztem) Attachment + - Jedes Attachment hat max 3 actions + + Args: + num_buttons: Liste von (label, prefix) Tuples für nummerierte Buttons + special_buttons: Liste von (label, prefix, style) Tuples für Sonderschaltflächen + color: Attachment-Farbe + title: Attachment-Titel (nur für erstes Attachment) + + Returns: + Liste von Attachment-Dicts (jedes mit max 3 actions) + """ + attachments: List[dict] = [] + + # Nummerierte Buttons in 3er-Blöcke aufteilen + for i in range(0, len(num_buttons), 3): + chunk = num_buttons[i:i + 3] + actions = [] + for j, (label, prefix) in enumerate(chunk): + num_idx = i + j + emoji = _EMOJI_NUMBERS[num_idx] if num_idx < len(_EMOJI_NUMBERS) else str(num_idx + 1) + actions.append({ + "type": "button", + "text": f"{emoji} {label}", + "msg": prefix, + "msg_in_chat_window": True, + "style": "primary", + }) + att = { + "color": color, + "actions": actions, + } + if i == 0 and title: + att["title"] = title + attachments.append(att) + + # Sonderschaltflächen in separatem Attachment + if special_buttons: + special_actions = [] + for label, prefix, style in special_buttons: + special_actions.append({ + "type": "button", + "text": label, + "msg": prefix, + "msg_in_chat_window": True, + "style": style, + }) + attachments.append({ + "color": color, + "actions": special_actions, + }) + + return attachments + + # ── Schritt 1: review_room Top-Level Renderer ───────────────────────────── @@ -182,7 +257,7 @@ def render_review_room_step( "", ] - buttons: List[dict] = [] + num_buttons: List[Tuple[str, str]] = [] room_count = 0 for rid, entry in room_map.rooms.items(): @@ -203,39 +278,34 @@ def render_review_room_step( lines.append(f" KwKontext: {kwctx_str or '—'}") lines.append("") - # Pro Raum ein 'Anpassen'-Button (kurzer Name, max 9 Zeichen) + # Pro Raum ein nummerierter Button prefix = f"{REVIEW_ROOM_EDIT}::{rid}::edit" short_name = entry.name[:9] if len(entry.name) > 9 else entry.name - buttons.extend(_build_custom_buttons( - [f"{room_count}️⃣ {short_name}"], - prefix=prefix, - style="primary", - )) + num_buttons.append((short_name, prefix)) if room_count == 0: lines.append("_(keine Räume eingerichtet)_") lines.append("") + # Nummerierte Optionen im Text lines.append("👉 Klicke auf einen Raum zum Anpassen:") + for i, (label, _) in enumerate(num_buttons): + emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1) + lines.append(f" {emoji} {label}") - # Globale Buttons - buttons.extend(_build_custom_buttons( - ["➕ Neuer"], - prefix=REVIEW_ROOM_ADD_NEW, - style="default", - )) - buttons.extend(_build_custom_buttons( - ["⏭️ Skip"], - prefix=REVIEW_ROOM_SKIP, - style="default", - )) + # Sonderschaltflächen + special_buttons: List[Tuple[str, str, str]] = [ + ("➕ Neuer", REVIEW_ROOM_ADD_NEW, "default"), + ("⏭️ Skip", REVIEW_ROOM_SKIP, "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#1d74f5", - "title": "Raum-Map Review — Raum auswählen", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#1d74f5", + title="Raum-Map Review — Raum auswählen", + ) return text, attachments @@ -276,46 +346,31 @@ def render_review_room_edit( f"KwKontext ({len(entry.keywords_context)}): {', '.join(entry.keywords_context) or '—'}", "", "👉 Was möchtest du bearbeiten?", + " 1️⃣ Kw100", + " 2️⃣ KwKtx", + " 3️⃣ Theme", + " 4️⃣ Catch-All", + " 5️⃣ Lösch", ] - buttons: List[dict] = [] - buttons.extend(_build_custom_buttons( - ["1️⃣ Kw100"], - prefix=f"{REVIEW_ROOM_KW_ADD}::{target_room_id}", - style="primary", - )) - buttons.extend(_build_custom_buttons( - ["2️⃣ KwKtx"], - prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::keywords_context", - style="primary", - )) - buttons.extend(_build_custom_buttons( - ["3️⃣ Theme"], - prefix=f"{REVIEW_ROOM_THEME_SAVE}::{target_room_id}", - style="primary", - )) - buttons.extend(_build_custom_buttons( - ["4️⃣ Catch-All"], - prefix=f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}", - style="primary", - )) - buttons.extend(_build_custom_buttons( - ["5️⃣ Lösch"], - prefix=f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}", - style="danger", - )) - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=REVIEW_ROOM_BACK, - style="default", - )) + num_buttons: List[Tuple[str, str]] = [ + ("Kw100", f"{REVIEW_ROOM_KW_ADD}::{target_room_id}"), + ("KwKtx", f"{REVIEW_ROOM_EDIT}::{target_room_id}::keywords_context"), + ("Theme", f"{REVIEW_ROOM_THEME_SAVE}::{target_room_id}"), + ("Catch", f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}"), + ("Lösch", f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}"), + ] + special_buttons: List[Tuple[str, str, str]] = [ + ("↩️ Zurück", REVIEW_ROOM_BACK, "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#1d74f5", - "title": f"Raum bearbeiten: {entry.name}", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#1d74f5", + title=f"Raum bearbeiten: {entry.name}", + ) return text, attachments @@ -362,18 +417,17 @@ def render_review_room_keywords_edit( f"Aktuelle Keywords ({len(keywords)}):", ] - buttons: List[dict] = [] + # X-Buttons als num_buttons (ohne Nummerierung — build_button_attachments + # nummeriert nur wenn wir es explizit wollen; für X-Buttons nutzen wir + # einen separaten Mechanismus) + x_buttons: List[Tuple[str, str]] = [] if keywords: for kw in keywords: lines.append(f" • `{kw}`") # Pro Keyword ein X-Button zum Entfernen (gekürzt auf 8 Zeichen) short_kw = kw[:8] if len(kw) > 8 else kw - buttons.extend(_build_custom_buttons( - [f"❌ {short_kw}"], - prefix=f"{remove_prefix}{kw}", - style="danger", - )) + x_buttons.append((f"❌ {short_kw}", f"{remove_prefix}{kw}")) else: lines.append(" _(keine)_") @@ -386,18 +440,38 @@ def render_review_room_keywords_edit( lines.append("💬 Antworte mit einem neuen Keyword (2-30 Zeichen) " "oder klicke Zurück.") - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=back_prefix, - style="default", - )) + # X-Buttons in 3er-Blöcke aufteilen (manuell, ohne build_button_attachments + # da diese KEINE Nummern bekommen sollen) + attachments: List[dict] = [] + for i in range(0, len(x_buttons), 3): + chunk = x_buttons[i:i + 3] + actions = [] + for label, prefix in chunk: + actions.append({ + "type": "button", + "text": label, + "msg": prefix, + "msg_in_chat_window": True, + "style": "danger", + }) + attachments.append({ + "color": "#1d74f5", + "actions": actions, + }) + + # Zurück-Button in separatem Attachment + attachments.append({ + "color": "#1d74f5", + "actions": [{ + "type": "button", + "text": "↩️ Zurück", + "msg": back_prefix, + "msg_in_chat_window": True, + "style": "default", + }], + }) text = "\n".join(lines) - attachments = [{ - "color": "#1d74f5", - "title": f"{kind_label} bearbeiten: {entry.name}", - "actions": buttons, - }] return text, attachments @@ -443,19 +517,19 @@ def render_review_room_theme_edit( lines.append("") lines.append("⚠️ Das aktuelle Theme ist sehr lang (>500 Zeichen).") - buttons: List[dict] = [] - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", - style="default", - )) + # Nur Sonderschaltfläche (keine nummerierten Buttons) + num_buttons: List[Tuple[str, str]] = [] + special_buttons: List[Tuple[str, str, str]] = [ + ("↩️ Zurück", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#1d74f5", - "title": f"Theme bearbeiten: {entry.name}", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#1d74f5", + title=f"Theme bearbeiten: {entry.name}", + ) return text, attachments @@ -510,24 +584,20 @@ def render_review_room_catch_all_toggle( lines.append("") lines.append("👉 Bestätigen?") - buttons: List[dict] = [] - buttons.extend(_build_custom_buttons( - ["✅ Setzen"], - prefix=f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}::confirm", - style="primary", - )) - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", - style="default", - )) + num_buttons: List[Tuple[str, str]] = [ + ("✅ Setzen", f"{REVIEW_ROOM_CATCHALL_SET}::{target_room_id}::confirm"), + ] + special_buttons: List[Tuple[str, str, str]] = [ + ("↩️ Zurück", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#f5a623", - "title": f"Catch-All ändern: {entry.name}", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#f5a623", + title=f"Catch-All ändern: {entry.name}", + ) return text, attachments @@ -574,24 +644,20 @@ def render_review_room_remove( "👉 Bestätigen?", ] - buttons: List[dict] = [] - buttons.extend(_build_custom_buttons( - ["✅ Löschen"], - prefix=f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}::confirm", - style="danger", - )) - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", - style="default", - )) + num_buttons: List[Tuple[str, str]] = [ + ("🗑️ Ja", f"{REVIEW_ROOM_REMOVE_CONFIRM}::{target_room_id}::confirm"), + ] + special_buttons: List[Tuple[str, str, str]] = [ + ("↩️ Abbrechen", f"{REVIEW_ROOM_EDIT}::{target_room_id}::edit", "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#f5455c", - "title": f"Raum entfernen: {entry.name}", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#f5455c", + title=f"Raum entfernen: {entry.name}", + ) return text, attachments @@ -629,36 +695,32 @@ def render_review_room_add_new( "", ] - buttons: List[dict] = [] + num_buttons: List[Tuple[str, str]] = [] for i, room in enumerate(available_rooms): rid = room["id"] name = room.get("name", rid) rtype = room.get("type", "c") type_label = "💬" if rtype == "d" else "#" - lines.append(f" {type_label} {name}") + emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1) + lines.append(f" {emoji} {type_label} {name}") # Kurzer Button-Name (max 9 Zeichen) short_name = name[:9] if len(name) > 9 else name - buttons.extend(_build_custom_buttons( - [f"{i+1}️⃣ {short_name}"], - prefix=f"{REVIEW_ROOM_ADD_NEW}::{rid}", - style="primary", - )) + num_buttons.append((short_name, f"{REVIEW_ROOM_ADD_NEW}::{rid}")) lines.append("") lines.append("👉 Klicke auf einen Raum zum Hinzufügen:") - buttons.extend(_build_custom_buttons( - ["↩️ Zurück"], - prefix=REVIEW_ROOM_BACK, - style="default", - )) + special_buttons: List[Tuple[str, str, str]] = [ + ("↩️ Zurück", REVIEW_ROOM_BACK, "default"), + ] text = "\n".join(lines) - attachments = [{ - "color": "#1d74f5", - "title": "Neuen Raum hinzufügen", - "actions": buttons, - }] + attachments = build_button_attachments( + num_buttons, + special_buttons, + color="#1d74f5", + title="Neuen Raum hinzufügen", + ) return text, attachments diff --git a/plugin/archivar/tests/test_review_room_subphases.py b/plugin/archivar/tests/test_review_room_subphases.py index 87ab618..6e63905 100644 --- a/plugin/archivar/tests/test_review_room_subphases.py +++ b/plugin/archivar/tests/test_review_room_subphases.py @@ -154,8 +154,8 @@ class TestRenderReviewRoomStep: assert "Catch-All" in text assert "code" in text assert "bug" in text - assert len(attachments) == 1 - assert len(attachments[0]["actions"]) >= 4 # 2 rooms + Neuer Raum + Überspringen + assert len(attachments) == 2 # 1 nummeriert + 1 special (Neuer/Skip) + assert len(attachments[0]["actions"]) >= 2 # 2 rooms in erster Reihe def test_renders_empty_room_list(self): rm = _load_room_map([ @@ -191,7 +191,7 @@ class TestRenderReviewRoomEdit: assert "code" in text assert "1️⃣ Kw100" in str(attachments) assert "3️⃣ Theme" in str(attachments) - assert "4️⃣ Catch-All" in str(attachments) + assert "4️⃣ Catch" in str(attachments) assert "5️⃣ Lösch" in str(attachments) assert "Zurück" in str(attachments) @@ -295,8 +295,8 @@ class TestRenderReviewRoomRemove: ]) text, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons) assert "wirklich entfernen" in text - assert "✅ Löschen" in str(attachments) - assert "Zurück" in str(attachments) + assert "🗑️ Ja" in str(attachments) + assert "Abbrechen" in str(attachments) def test_rejects_catch_all_removal(self): rm = _load_room_map([ @@ -731,10 +731,11 @@ class TestAllSubphasesHaveBack: """UX-7: Alle Sub-Phasen haben Zurück-Button.""" def _has_back_button(self, attachments): - """Prüft ob Attachments einen '↩️ Zurück' Button enthalten.""" + """Prüft ob Attachments einen '↩️ Zurück' oder '↩️ Abbrechen' Button enthalten.""" for att in attachments: for action in att.get("actions", []): - if "Zurück" in action.get("text", ""): + text = action.get("text", "") + if "Zurück" in text or "Abbrechen" in text: return True return False @@ -782,14 +783,14 @@ class TestAllSubphasesHaveBack: assert self._has_back_button(attachments), "catch_all_toggle sub-phase fehlt Zurück-Button" def test_remove_subphase_has_back(self): - """review_room_remove hat Zurück-Button.""" + """review_room_remove hat Abbrechen-Button.""" rm = _load_room_map([ {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]}, {"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True}, ]) _, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons) - assert self._has_back_button(attachments), "remove sub-phase fehlt Zurück-Button" + assert self._has_back_button(attachments), "remove sub-phase fehlt Abbrechen-Button" def test_add_new_subphase_has_back(self): """review_room_add_new hat Zurück-Button.""" @@ -1082,3 +1083,375 @@ class TestKeywordsContextDispatch: assert result is True assert "neues-kw" in rm.get_room_by_id("r1").keywords_100 assert "neues-kw" not in rm.get_room_by_id("r1").keywords_context + + +# ═══════════════════════════════════════════════════════════════════════════════ +# UX REFACTOR: 2-Reihen-Button-Pattern Tests (Andreas' Spezifikation) +# ═══════════════════════════════════════════════════════════════════════════════ + +# Import build_button_attachments — wird erst nach Implementierung existieren +try: + from plugin.archivar.onboarding_review import build_button_attachments + _HAS_BUILD_BUTTON_ATTACHMENTS = True +except ImportError: + _HAS_BUILD_BUTTON_ATTACHMENTS = False + + +class TestBuildButtonAttachments: + """build_button_attachments() — zentrale Helper-Funktion.""" + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_splits_into_rows_of_max_3(self): + """5 nummerierte Buttons → 2 Attachments (3 + 2).""" + num_buttons = [ + ("Kw100", "REVIEW_ROOM_KW_ADD::r1"), + ("KwKtx", "REVIEW_ROOM_EDIT::r1::keywords_context"), + ("Theme", "REVIEW_ROOM_THEME_SAVE::r1"), + ("Catch", "REVIEW_ROOM_CATCHALL_SET::r1"), + ("Lösch", "REVIEW_ROOM_REMOVE_CONFIRM::r1"), + ] + special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")] + attachments = build_button_attachments(num_buttons, special_buttons) + assert len(attachments) == 3 # 3+2 nummeriert + 1 special + assert len(attachments[0]["actions"]) == 3 + assert len(attachments[1]["actions"]) == 2 + assert len(attachments[2]["actions"]) == 1 # Zurück + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_no_attachment_exceeds_3_actions(self): + """Kein Attachment hat >3 actions.""" + num_buttons = [ + (f"Btn{i}", f"PREFIX::btn{i}") for i in range(1, 8) + ] + special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")] + attachments = build_button_attachments(num_buttons, special_buttons) + for att in attachments: + assert len(att["actions"]) <= 3, \ + f"Attachment hat {len(att['actions'])} actions (>3)" + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_numbers_sequential(self): + """Nummerierte Buttons haben fortlaufende Nummern 1️⃣ 2️⃣ 3️⃣...""" + num_buttons = [ + ("A", "PREFIX::a"), + ("B", "PREFIX::b"), + ("C", "PREFIX::c"), + ("D", "PREFIX::d"), + ] + special_buttons = [] + attachments = build_button_attachments(num_buttons, special_buttons) + all_labels = [] + for att in attachments: + for action in att["actions"]: + all_labels.append(action["text"]) + assert "1️⃣ A" in all_labels + assert "2️⃣ B" in all_labels + assert "3️⃣ C" in all_labels + assert "4️⃣ D" in all_labels + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_special_buttons_no_numbers(self): + """Sonderschaltflächen haben KEINE Nummern.""" + num_buttons = [("Test", "PREFIX::test")] + special_buttons = [ + ("↩️ Zurück", "REVIEW_ROOM_BACK", "default"), + ("⏭️ Skip", "REVIEW_ROOM_SKIP", "default"), + ] + attachments = build_button_attachments(num_buttons, special_buttons) + special_att = attachments[-1] + for action in special_att["actions"]: + label = action["text"] + for num_emoji in ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"]: + assert num_emoji not in label, \ + f"Special button '{label}' hat Nummer {num_emoji}" + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_special_buttons_in_separate_attachment(self): + """Sonderschaltflächen sind im letzten Attachment.""" + num_buttons = [ + ("A", "PREFIX::a"), + ("B", "PREFIX::b"), + ] + special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")] + attachments = build_button_attachments(num_buttons, special_buttons) + last_att = attachments[-1] + assert "↩️ Zurück" in [a["text"] for a in last_att["actions"]] + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_only_special_buttons(self): + """Nur Sonderschaltflächen → 1 Attachment.""" + num_buttons = [] + special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")] + attachments = build_button_attachments(num_buttons, special_buttons) + assert len(attachments) == 1 + assert len(attachments[0]["actions"]) == 1 + + @pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS, + reason="build_button_attachments noch nicht implementiert") + def test_only_numbered_buttons(self): + """Nur nummerierte Buttons → korrekte Aufteilung.""" + num_buttons = [ + ("A", "PREFIX::a"), + ("B", "PREFIX::b"), + ("C", "PREFIX::c"), + ("D", "PREFIX::d"), + ] + special_buttons = [] + attachments = build_button_attachments(num_buttons, special_buttons) + assert len(attachments) == 2 # 3 + 1 + assert len(attachments[0]["actions"]) == 3 + assert len(attachments[1]["actions"]) == 1 + + +class TestButtonRowsMax3: + """Regel 2: Kein Attachment hat >3 actions (Integrationstests).""" + + def _max_actions_per_attachment(self, attachments): + return max((len(att.get("actions", [])) for att in attachments), default=0) + + def test_room_edit_max_3_per_row(self): + """render_review_room_edit: max 3 actions pro Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", + "keywords_100": ["code", "bug"], "keywords_context": ["git"]}, + {"room_id": "r2", "name": "#Ops", "theme": "Betrieb", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_edit: max {max_actions} actions in einem Attachment" + + def test_keywords_edit_max_3_per_row(self): + """render_review_room_keywords_edit: max 3 actions pro Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", + "keywords_100": ["code", "bug", "test", "deploy", "ci", "docker", "git"], + "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_keywords_edit: max {max_actions} actions in einem Attachment" + + def test_catchall_toggle_max_3_per_row(self): + """render_review_room_catch_all_toggle: max 3 actions pro Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords": ["server"], "catch_all": True}, + ]) + _, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_catch_all_toggle: max {max_actions} actions in einem Attachment" + + def test_remove_max_3_per_row(self): + """render_review_room_remove: max 3 actions pro Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords": ["server"], "catch_all": True}, + ]) + _, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_remove: max {max_actions} actions in einem Attachment" + + def test_room_step_max_3_per_row(self): + """render_review_room_step: max 3 actions pro Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + {"room_id": "r3", "name": "#QA", "theme": "qa", "keywords_100": ["test"], "keywords_context": []}, + {"room_id": "r4", "name": "#HR", "theme": "hr", "keywords_100": ["people"], "keywords_context": []}, + ]) + _, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_step: max {max_actions} actions in einem Attachment" + + def test_add_new_max_3_per_row(self): + """render_review_room_add_new: max 3 actions pro Attachment.""" + available = [ + {"id": "new1", "name": "#Alpha", "type": "c"}, + {"id": "new2", "name": "#Beta", "type": "c"}, + {"id": "new3", "name": "#Gamma", "type": "c"}, + {"id": "new4", "name": "#Delta", "type": "c"}, + ] + _, attachments = render_review_room_add_new(available, _mock_build_buttons) + max_actions = self._max_actions_per_attachment(attachments) + assert max_actions <= 3, f"render_review_room_add_new: max {max_actions} actions in einem Attachment" + + +class TestNumbersInText: + """Regel 1: Nummern im Nachrichtentext UND auf Schaltflächen.""" + + def test_room_edit_numbers_in_text(self): + """render_review_room_edit: Text enthält 1️⃣-5️⃣.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", + "keywords_100": ["code", "bug"], "keywords_context": ["git"]}, + {"room_id": "r2", "name": "#Ops", "theme": "Betrieb", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + text, _ = render_review_room_edit(rm, "r1", _mock_build_buttons) + assert "1️⃣" in text, "Text enthält nicht 1️⃣" + assert "2️⃣" in text, "Text enthält nicht 2️⃣" + assert "3️⃣" in text, "Text enthält nicht 3️⃣" + assert "4️⃣" in text, "Text enthält nicht 4️⃣" + assert "5️⃣" in text, "Text enthält nicht 5️⃣" + + def test_room_edit_numbers_on_buttons(self): + """render_review_room_edit: Buttons haben 1️⃣-5️⃣.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", + "keywords_100": ["code", "bug"], "keywords_context": ["git"]}, + {"room_id": "r2", "name": "#Ops", "theme": "Betrieb", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons) + all_labels = [] + for att in attachments: + for action in att.get("actions", []): + all_labels.append(action.get("text", "")) + all_text = " ".join(all_labels) + assert "1️⃣" in all_text, f"Buttons enthalten nicht 1️⃣: {all_labels}" + assert "2️⃣" in all_text, f"Buttons enthalten nicht 2️⃣: {all_labels}" + assert "3️⃣" in all_text, f"Buttons enthalten nicht 3️⃣: {all_labels}" + assert "4️⃣" in all_text, f"Buttons enthalten nicht 4️⃣: {all_labels}" + assert "5️⃣" in all_text, f"Buttons enthalten nicht 5️⃣: {all_labels}" + + +class TestSpecialButtonsSeparateRow: + """Regel 3: Sonderschaltflächen in separater Reihe.""" + + def _get_special_labels(self, attachments): + """Extrahiert Labels aus dem letzten Attachment.""" + if not attachments: + return [] + return [a.get("text", "") for a in attachments[-1].get("actions", [])] + + def test_room_edit_back_in_separate_row(self): + """render_review_room_edit: ↩️ Zurück in separatem Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", + "keywords_100": ["code", "bug"], "keywords_context": ["git"]}, + {"room_id": "r2", "name": "#Ops", "theme": "Betrieb", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "↩️ Zurück" in special_labels, \ + f"↩️ Zurück nicht in letztem Attachment: {special_labels}" + + def test_keywords_edit_back_in_separate_row(self): + """render_review_room_keywords_edit: ↩️ Zurück in separatem Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", + "keywords_100": ["code", "bug", "test", "deploy"], + "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "↩️ Zurück" in special_labels, \ + f"↩️ Zurück nicht in letztem Attachment: {special_labels}" + + def test_catchall_toggle_back_in_separate_row(self): + """render_review_room_catch_all_toggle: ↩️ Zurück in separatem Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords": ["server"], "catch_all": True}, + ]) + _, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "↩️ Zurück" in special_labels, \ + f"↩️ Zurück nicht in letztem Attachment: {special_labels}" + + def test_remove_back_in_separate_row(self): + """render_review_room_remove: ↩️ Abbrechen in separatem Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords": ["server"], "catch_all": True}, + ]) + _, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "↩️ Abbrechen" in special_labels, \ + f"↩️ Abbrechen nicht in letztem Attachment: {special_labels}" + + def test_room_step_special_in_separate_row(self): + """render_review_room_step: ➕ Neuer + ⏭️ Skip in separatem Attachment.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "➕ Neuer" in special_labels or "⏭️ Skip" in special_labels, \ + f"Sonderschaltflächen nicht in letztem Attachment: {special_labels}" + + def test_add_new_back_in_separate_row(self): + """render_review_room_add_new: ↩️ Zurück in separatem Attachment.""" + available = [ + {"id": "new1", "name": "#Alpha", "type": "c"}, + {"id": "new2", "name": "#Beta", "type": "c"}, + ] + _, attachments = render_review_room_add_new(available, _mock_build_buttons) + assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2" + special_labels = self._get_special_labels(attachments) + assert "↩️ Zurück" in special_labels, \ + f"↩️ Zurück nicht in letztem Attachment: {special_labels}" + + +class TestKeywordXButtonsNotNumbered: + """Keyword-X-Buttons haben KEINE Nummern (Regel 1 Ausnahme).""" + + def test_keyword_x_buttons_no_numbers(self): + """render_review_room_keywords_edit: X-Buttons ohne Nummern-Emoji.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", + "keywords_100": ["code", "bug", "test"], + "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons) + x_labels = [] + for att in attachments: + for action in att.get("actions", []): + label = action.get("text", "") + if "❌" in label: + x_labels.append(label) + assert len(x_labels) >= 3, f"Erwartet >=3 X-Buttons, gefunden: {x_labels}" + for label in x_labels: + for num_emoji in ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]: + assert num_emoji not in label, \ + f"X-Button '{label}' hat Nummer {num_emoji}" + + def test_keyword_x_buttons_in_3er_blocks(self): + """render_review_room_keywords_edit: 7 Keywords → 3+3+1 X-Buttons + Zurück.""" + rm = _load_room_map([ + {"room_id": "r1", "name": "#Dev", "theme": "dev", + "keywords_100": ["a", "b", "c", "d", "e", "f", "g"], + "keywords_context": []}, + {"room_id": "r2", "name": "#Ops", "theme": "ops", + "keywords_100": ["server"], "keywords_context": [], "catch_all": True}, + ]) + _, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons) + assert len(attachments) >= 3, \ + f"Erwartet >=3 Attachments (3+3+1 X + Zurück), gefunden: {len(attachments)}" + for att in attachments: + assert len(att["actions"]) <= 3, \ + f"Attachment hat {len(att['actions'])} actions (>3)"