Files
Hermes_rocket.chat_Plugin/tests/live_rc/test_02_button_click.py
T
Bernd (Hermes) aa37de3e6e rate-limiting feinschliff: 429-retry, API-call reduction, auto-route detection
AUFGABE 1 — test_03 API-calls reduzieren:
- Skip get_latest_timestamp on source room; use post_message's returned ts as cursor (saves 1 channels.history call)
- Source polling: initial_interval=5s (was 2s), timeout=30s (was 25s)
- Target polling: timeout=60s (was 25s), initial_interval=8s (was 2s)
- post_message() now returns (msg_id, ts) tuple — all call sites updated

AUFGABE 2 — 429-retry strategy verbessern:
- rc_rest.py: 5 retries with 3s/6s/12s/20s/30s backoff (was 3 retries 3s/6s/12s)
- polling.py: 5 consecutive 429s before RateLimitSkip (was 3)
- polling.py: 429 backoff max 30s (was 24s)

AUFGABE 3 — rate-limit-cooldown erhöhen:
- conftest.py: 20s between tests (was 15s)

AUFGABE 4 — test_03 auto-route robustness:
- Detect auto-route (wechseln/sehe dich/thema) vs button-move-request (kopieren/rüber/attachments)
- Auto-route: pytest.skip with reason, no button click, no target verification
- Button-request: proceed with existing button-click + target-verification flow
2026-07-28 18:34:07 +02:00

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=18.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")