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
This commit is contained in:
Bernd (Hermes)
2026-07-28 16:58:50 +02:00
parent 6a09caa1e5
commit 16c1ad927e
9 changed files with 708 additions and 57 deletions
+30 -8
View File
@@ -5,9 +5,10 @@ Fixtures, markers, skip logic, self-check, rate limiter, suite lock,
and cleanup for the REST-based test harness running on .101.
Usage:
pytest tests/live_rc/ -m live_rc
pytest tests/live_rc/ -m live_rc -v
Without RC_LIVE_URL set: all tests are skipped cleanly (no errors).
Without RC_LIVE_URL set: all tests are skipped cleanly (no errors)
at collection time via pytest_collection_modifyitems.
"""
from __future__ import annotations
@@ -26,7 +27,7 @@ import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from tests.live_rc.helpers.rc_rest import RCRestClient, RCRestError
from tests.live_rc.helpers.polling import get_latest_timestamp
from tests.live_rc.helpers.polling import get_latest_timestamp, RateLimitSkip
logger = logging.getLogger(__name__)
@@ -43,7 +44,7 @@ def pytest_configure(config):
# ═══════════════════════════════════════════════════════════════════════════
# Env-var check — skip entire suite if not configured
# Env-var check — skip entire suite at collection time if not configured
# ═══════════════════════════════════════════════════════════════════════════
@@ -65,8 +66,27 @@ def _is_live_configured() -> bool:
return all(_env_required(v) for v in required)
def pytest_collection_modifyitems(config, items):
"""Skip all live_rc tests at collection time if RC_LIVE_URL is not set.
This is the earliest possible skip point — before any fixtures are
instantiated, before any imports are resolved. Tests that would
otherwise fail due to missing env vars are cleanly skipped.
"""
if not _is_live_configured():
skip_reason = (
"RC_LIVE_URL not set — skipping all live RC tests. "
"Set RC_LIVE_URL, RC_LIVE_TOKEN, RC_LIVE_USER_ID, "
"RC_LIVE_TEST_ROOM, RC_LIVE_BOT_USERNAME, RC_LIVE_BOT_USER_ID "
"to run live tests."
)
for item in items:
if item.get_closest_marker("live_rc"):
item.add_marker(pytest.mark.skip(reason=skip_reason))
# ═══════════════════════════════════════════════════════════════════════════
# Token-Bucket Rate Limiter (max 60 calls/minute)
# Token-Bucket Rate Limiter (max 30 calls/minute)
# ═══════════════════════════════════════════════════════════════════════════
@@ -74,9 +94,10 @@ class RateLimiter:
"""Simple token-bucket rate limiter.
Allows max_tokens calls per window_seconds. Thread-safe via lock.
Default: 30 calls/minute (was 60 — RC triggers 429 at 3-4 calls in <10s).
"""
def __init__(self, max_tokens: int = 60, window_seconds: float = 60.0):
def __init__(self, max_tokens: int = 30, window_seconds: float = 60.0):
self.max_tokens = max_tokens
self.window_seconds = window_seconds
self.tokens = float(max_tokens)
@@ -117,7 +138,7 @@ _rate_limiter: RateLimiter | None = None
def _get_rate_limiter() -> RateLimiter:
global _rate_limiter
if _rate_limiter is None:
_rate_limiter = RateLimiter(max_tokens=60, window_seconds=60.0)
_rate_limiter = RateLimiter(max_tokens=30, window_seconds=60.0)
return _rate_limiter
@@ -172,6 +193,7 @@ def rc_config() -> dict:
"""Provide the RC live test configuration from env vars.
Skips the entire session if RC_LIVE_URL is not set.
(Redundant with pytest_collection_modifyitems, but kept as safety net.)
"""
if not _is_live_configured():
pytest.skip("RC_LIVE_URL not set — skipping live RC tests")
@@ -289,7 +311,7 @@ def bot_status_check(rc_client: RCRestClient, bot_user_id: str, bot_username: st
@pytest.fixture
def rate_limiter() -> RateLimiter:
"""Rate limiter to stay under 60 calls/minute."""
"""Rate limiter to stay under 30 calls/minute."""
return _get_rate_limiter()