136 lines
4.2 KiB
Python
136 lines
4.2 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 18s)
|
|
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,
|
|
PollTimeout,
|
|
RateLimitSkip,
|
|
)
|
|
|
|
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=120.0,
|
|
rate_limiter=rate_limiter,
|
|
)
|
|
except RateLimitSkip as e:
|
|
pytest.skip(f"Rate limit triggered: {e}")
|
|
except PollTimeout as e:
|
|
pytest.fail(
|
|
f"Bot did not respond to ::-text within 18s. "
|
|
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")
|