6a09caa1e5
Implementiert die vollständige Test-Harness für Rocket.Chat Live-Tests von .101 (Bernd) gegen .45 (MyTestBot) via REST API. ARCHITEKTUR: - tests/live_rc/conftest.py: Fixtures, Marker, Skip-Logik, Self-Check, Token-Bucket-Rate-Limiter (60 calls/min), Suite-Lock (/tmp/rc-live-tests.lock), Cleanup-Fixture, Message-Ownership-Assert, Bot-Status-Check - helpers/rc_rest.py: REST-Client-Wrapper (post, history, users.info, self-check) - helpers/polling.py: Cursor-basiertes Polling mit Rate-Limiter-Integration und exponentiellen Backoff bei HTTP 429 TESTS: - test_01_echo.py: Smoke-Test — Bot antwortet auf einfache Nachricht - test_02_button_click.py: ::-Text als Button-Klick-Simulation (E3) - test_03-06: Skeletons mit @pytest.mark.skip VERIFIZIERT: - Ohne Env-Variablen: komplettes SKIP, keine Fehler - Mit Env-Variablen + Bot im Onboarding: SKIP mit klarer Diagnose - Rate-Limiter verhindert HTTP 429 (vorher: 100% Fehlerrate) - Self-Check validiert Token/User-Identity vor jedem Lauf - Suite-Lock verhindert parallele Läufe
130 lines
4.0 KiB
Python
130 lines
4.0 KiB
Python
"""
|
|
Test 02 — ::-Text als Button-Klick-Simulation (E3: Verifikation der Grundannahme).
|
|
|
|
Verifiziert, dass der Bot eine via REST chat.postMessage gesendete
|
|
Nachricht mit ::-Syntax als Button-Klick interpretiert.
|
|
|
|
HINTERGRUND (aus adapter.py _process_incoming, Zeile 1987-1999):
|
|
is_button_response = (
|
|
(native button event) OR
|
|
(text enthält "::" AND nicht CLARIFY:/ARCHIVAR_CLARIFY:/MOVE_REQ:
|
|
AND Teil vor "::" ist nicht leer) OR
|
|
(text startswith "CLARIFY:") OR
|
|
(text startswith "ARCHIVAR_CLARIFY:")
|
|
)
|
|
|
|
ONBOARD:<rid>::select_<rid> erfüllt Bedingung 2:
|
|
- Enthält "::" ✓
|
|
- Startet nicht mit CLARIFY:/ARCHIVAR_CLARIFY:/MOVE_REQ: ✓
|
|
- Teil vor "::" ist "ONBOARD:<rid>" (nicht leer) ✓
|
|
→ is_button_response = True
|
|
|
|
TEST-SZENARIO:
|
|
1. Poste "ONBOARD:<test_room_id>::select_<test_room_id>" via REST
|
|
2. Warte auf Bot-Antwort (max 10s)
|
|
3. Verifiziere: Bot hat geantwortet (Nachricht wurde empfangen + verarbeitet)
|
|
4. Verifiziere: Antwort stammt von mytestbot
|
|
|
|
Da kein Onboarding aktiv ist, wird die Nachricht als Button-Response
|
|
an den Agenten dispatched (is_button_response=True), aber nicht vom
|
|
Onboarding-Handler abgefangen. Der Bot sollte trotzdem antworten.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from tests.live_rc.conftest import (
|
|
assert_bot_message,
|
|
post_test_message,
|
|
)
|
|
from tests.live_rc.helpers.polling import wait_for_bot_message
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@pytest.mark.live_rc
|
|
def test_02_button_click_simulation(
|
|
rc_client,
|
|
test_room_id: str,
|
|
bot_username: str,
|
|
bot_user_id: str,
|
|
cursor: str,
|
|
posted_message_ids: list,
|
|
rate_limiter,
|
|
cleanup_messages,
|
|
bot_status_check,
|
|
):
|
|
"""E3: Verifiziere dass ::-Text als Button-Klick behandelt wird.
|
|
|
|
Die Grundannahme: Wenn der Bot eine Nachricht mit ::-Syntax empfängt,
|
|
wird is_button_response=True gesetzt und die Nachricht entsprechend
|
|
geroutet (nicht als normale Textnachricht).
|
|
|
|
Steps:
|
|
1. Poste ONBOARD:<rid>::select_<rid> als Plain-Text via REST
|
|
2. Warte auf Bot-Antwort
|
|
3. Verifiziere: Bot hat geantwortet (Beweis: Nachricht wurde empfangen)
|
|
4. Verifiziere: Antwort stammt von mytestbot
|
|
"""
|
|
# Step 1: Post ::-text as button-click simulation
|
|
button_text = f"ONBOARD:{test_room_id}::select_{test_room_id}"
|
|
msg_id = post_test_message(
|
|
rc_client, test_room_id, button_text,
|
|
posted_message_ids, rate_limiter,
|
|
)
|
|
logger.info(
|
|
"Test 02: posted button-click simulation '%s' → msg %s",
|
|
button_text[:60], msg_id[:12],
|
|
)
|
|
|
|
# Step 2: Wait for bot response
|
|
try:
|
|
response = wait_for_bot_message(
|
|
client=rc_client,
|
|
room_id=test_room_id,
|
|
bot_username=bot_username,
|
|
cursor=cursor,
|
|
timeout=12.0,
|
|
rate_limiter=rate_limiter,
|
|
)
|
|
except Exception as e:
|
|
pytest.fail(
|
|
f"Bot did not respond to ::-text within 12s. "
|
|
f"The ::-dispatch may be broken — check adapter.py "
|
|
f"_process_incoming is_button_response detection. "
|
|
f"Error: {e}"
|
|
)
|
|
|
|
# Step 3: Verify response has text
|
|
response_text = response.get("msg", "")
|
|
assert response_text, (
|
|
f"Bot response to ::-text has no text. Full message: {response}"
|
|
)
|
|
logger.info(
|
|
"Test 02: bot responded to ::-text with %d chars: '%s'",
|
|
len(response_text), response_text[:100],
|
|
)
|
|
|
|
# Step 4: Verify message ownership
|
|
assert_bot_message(
|
|
response,
|
|
expected_username=bot_username,
|
|
context="test_02_button_click",
|
|
)
|
|
|
|
actual_user_id = response.get("u", {}).get("_id", "")
|
|
assert actual_user_id == bot_user_id, (
|
|
f"Bot user ID mismatch: expected {bot_user_id[:12]}, "
|
|
f"got {actual_user_id[:12]}"
|
|
)
|
|
|
|
# Track bot response for cleanup
|
|
response_id = response.get("_id", "")
|
|
if response_id:
|
|
posted_message_ids.append(response_id)
|
|
|
|
logger.info("Test 02 PASSED: ::-text button-click simulation OK")
|