Files
Hermes_rocket.chat_Plugin/tests/live_rc/test_01_echo.py
T
Bernd (Hermes) 16c1ad927e live_rc: Rate-Limiter-Kalibrierung + Test 03/04 implementiert + ENV-Skip-Fix + README
AUFGABE 1 — Rate-Limiter-Kalibrierung:
- Polling-Intervalle: 2s → 3s → 5s → 8s (statt 100ms→200ms→500ms)
- 429-Backoff: 3s → 6s → 12s → 24s (exponentiell)
- Max 30 Calls/Minute (statt 60) — RC triggert 429 bei 3-4 Calls in <10s
- 3 consecutive 429s → RateLimitSkip (Test wird geskippt, nicht failed)
- Cursor-Caching: channels.history nur beim ersten Poll, dann Cache-Scan

AUFGABE 2 — ENV-Skip-Logik:
- pytest_collection_modifyitems in conftest.py: alle live_rc-Tests werden
  bereits bei Collection geskippt wenn RC_LIVE_URL nicht gesetzt ist
- Kein Fixture-Overhead, keine Imports — sauberer Early-Skip

AUFGABE 3 — TEST 03: Move-Request (vollständig):
- Keyword 'rocketchat' in test-rc-source triggert Archivar
- Bot sendet Move-Request-Buttons (verifiziert)
- Button-Klick via MOVE_REQ:<rid>::confirm_move Payload
- Bot kopiert Nachricht nach test-rc-target mit Präfix
- Verifikation: kopierte Nachricht enthält Original-Text + Präfix
- ENV: RC_LIVE_SOURCE_ROOM, RC_LIVE_TARGET_ROOM

AUFGABE 4 — TEST 04: Multi-Room (DM-Proxy → Archivar → Projektraum):
- Haupt-Testraum als DM-Proxy
- Keyword_100-Match 'rocketchat' → FAISS-Auto-Route in Projektraum
- Verifikation: kopierte Nachricht im Projektraum (wenn FAISS >= 0.85)
- Graceful: kein Fail wenn Auto-Route nicht triggert (Butler-Mode)
- ENV: RC_LIVE_PROJECT_ROOM

AUFGABE 5 — TEST 05+06: Skeletons mit TODO-Markern:
- test_05_stream_retry: skip mit Begründung (Stream-Retry auf .45 pending)
- test_06_concurrent: skip mit Begründung (Themenring auf .45 pending)
- Beide mit vollständigen Implementierungsschritten als TODO-Kommentare

AUFGABE 6 — README.md:
- Alle ENV-Variablen dokumentiert (Pflicht + Optional)
- Ausführ-Anleitung mit Beispielen
- Test-Übersichtstabelle mit Status
- Rate-Limiting-Dokumentation
- Architektur-Übersicht
2026-07-28 16:58:50 +02:00

105 lines
2.9 KiB
Python

"""
Test 01 — Echo / Smoke Test: Bot antwortet überhaupt.
Verifiziert die grundlegende Funktionsfähigkeit:
1. Bernd postet eine einfache Nachricht via REST API
2. MyTestBot (.45) empfängt via DDP und antwortet
3. Die Antwort wird via REST channels.history verifiziert
4. Message-Ownership: Antwort stammt von mytestbot (nicht von bernd)
"""
from __future__ import annotations
import logging
import time
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_01_echo_bot_responds(
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,
):
"""Smoke-Test: Bot antwortet auf eine einfache Nachricht.
Steps:
1. Poste "Hallo Bot, bitte antworte mit 'Echo-Test OK'"
2. Warte auf Antwort von mytestbot (max 18s)
3. Verifiziere: Antwort enthält Text
4. Verifiziere: Antwort stammt von mytestbot (nicht von bernd)
"""
# Step 1: Post test message
test_text = "Hallo Bot, bitte antworte mit 'Echo-Test OK'"
msg_id = post_test_message(
rc_client, test_room_id, test_text,
posted_message_ids, rate_limiter,
)
logger.info("Test 01: posted message %s", 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 within 18s. "
f"Check that .45 MyTestBot is running and subscribed to room {test_room_id[:12]}. "
f"Error: {e}"
)
# Step 3: Verify response has text
response_text = response.get("msg", "")
assert response_text, (
f"Bot response has no text. Full message: {response}"
)
logger.info("Test 01: bot responded with %d chars", len(response_text))
# Step 4: Verify message ownership — must be from mytestbot
assert_bot_message(
response,
expected_username=bot_username,
context="test_01_echo",
)
# Also verify the bot user ID matches
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 01 PASSED: echo smoke test OK")