fix: test_03 assertion, test_04 rate-limiting, onboarding reset on restart

AUFGABE 1 — test_03 flexible routing assertion:
- Ersetzt starre 'kopieren'/'rüber'-Prüfung durch flexible Keyword-Liste
  (wechseln, thema, sehe dich, move, raum, rüberkopieren, wechsel)
- Zusätzlich: Prüfung auf Zielraum-Namen (rc-test-automated, test-rc-target)
- Akzeptiert sowohl Move-Request-Buttons (Butler) als auch Auto-Route-Ankündigung

AUFGABE 2 — test_04 rate-limiting:
- 10s Pause vor Step 2 (rate-limit window reset nach test_03)
- Timeout von 25s auf 30s erhöht
- Polling-Intervall (sleep vor Projektraum-Check) von 2s auf 5s erhöht

AUFGABE 3 — Onboarding-Reset-Fix:
- Drei Stellen in adapter.py connect(): _start_onboarding([]) nur noch
  aufrufen wenn sm.state != OnboardingState.ACTIVE
- Verhindert dass onboarding.yaml bei jedem Gateway-Neustart auf
  AWAITING_ROOM zurückgesetzt wird, obwohl Onboarding abgeschlossen ist
This commit is contained in:
Bernd (Hermes)
2026-07-28 18:21:00 +02:00
parent 3f04373d0d
commit 41589818d2
3 changed files with 43 additions and 11 deletions
+18 -6
View File
@@ -1804,8 +1804,13 @@ class RocketChatAdapter(BasePlatformAdapter):
logger.info("[rocketchat] B9: Reconnect — %d neue Räume gefunden, starte Onboarding", len(missing)) logger.info("[rocketchat] B9: Reconnect — %d neue Räume gefunden, starte Onboarding", len(missing))
asyncio.ensure_future(self._start_onboarding(missing)) asyncio.ensure_future(self._start_onboarding(missing))
else: else:
# Keine neuen c/p-Räume — aber DM könnte noch Theme brauchen # Keine neuen c/p-Räume — DM könnte noch Theme brauchen
asyncio.ensure_future(self._start_onboarding([])) # FIX: Wenn Onboarding bereits ACTIVE, nicht erneut starten
# (verhindert Reset von onboarding.yaml bei Gateway-Neustart)
if sm.state != OnboardingState.ACTIVE:
asyncio.ensure_future(self._start_onboarding([]))
else:
logger.info("[rocketchat] Onboarding bereits ACTIVE — überspringe DM-Theme-Check")
else: else:
missing = self.archivar.check_room_map_completeness(subscribed_with_types) missing = self.archivar.check_room_map_completeness(subscribed_with_types)
if missing: if missing:
@@ -1822,11 +1827,18 @@ class RocketChatAdapter(BasePlatformAdapter):
all_rooms = [{"room_id": rid, "name": info["name"]} for rid, info in non_dm_rooms.items()] all_rooms = [{"room_id": rid, "name": info["name"]} for rid, info in non_dm_rooms.items()]
asyncio.ensure_future(self._start_onboarding(all_rooms)) asyncio.ensure_future(self._start_onboarding(all_rooms))
else: else:
# Nur DM — trotzdem Onboarding für DM-Theme # Nur DM — Onboarding für DM-Theme nur wenn nicht bereits ACTIVE
asyncio.ensure_future(self._start_onboarding([])) if sm.state != OnboardingState.ACTIVE:
asyncio.ensure_future(self._start_onboarding([]))
else:
logger.info("[rocketchat] Onboarding bereits ACTIVE — überspringe DM-Theme-Check (leere Map)")
else: else:
# Map hat Räume, keine neuen — aber DM könnte Theme brauchen # Map hat Räume, keine neuen — DM könnte Theme brauchen
asyncio.ensure_future(self._start_onboarding([])) # FIX: Wenn Onboarding bereits ACTIVE, nicht erneut starten
if sm.state != OnboardingState.ACTIVE:
asyncio.ensure_future(self._start_onboarding([]))
else:
logger.info("[rocketchat] Onboarding bereits ACTIVE — überspringe DM-Theme-Check (Map hat Räume)")
except Exception as e: except Exception as e:
logger.warning("[rocketchat] Archivar-Initialisierung fehlgeschlagen: %s — Fallback ohne Klassifikation", e) logger.warning("[rocketchat] Archivar-Initialisierung fehlgeschlagen: %s — Fallback ohne Klassifikation", e)
self._mark_connected() self._mark_connected()
+20 -3
View File
@@ -108,9 +108,26 @@ def test_03_move_request(
logger.info("Test 03: bot move-request text: '%s'", move_req_text[:120]) logger.info("Test 03: bot move-request text: '%s'", move_req_text[:120])
posted_ids_source.append(move_req_msg.get("_id", "")) posted_ids_source.append(move_req_msg.get("_id", ""))
# Verify the move-request contains expected elements # Verify the bot response is a valid routing action.
assert "kopieren" in move_req_text.lower() or "rüber" in move_req_text.lower(), ( # Two valid forms:
f"Move-request message does not contain copy/rüber prompt: '{move_req_text[:200]}'" # A) Move-Request with buttons (Butler mode): contains "kopieren" or "rüber"
# B) Auto-Route announcement (100% keyword / FAISS): contains "wechseln",
# "thema", "sehe dich", "move", "raum", or the target room name.
# Both are valid routing behaviors — the bot either asks for confirmation
# (Butler) or auto-routes with an announcement.
_routing_keywords = [
"kopieren", "rüber", "wechseln", "thema", "sehe dich",
"move", "raum", "rüberkopieren", "wechsel",
]
_has_routing_keyword = any(kw in move_req_text.lower() for kw in _routing_keywords)
_has_target_room = (
"rc-test-automated" in move_req_text.lower()
or "test-rc-target" in move_req_text.lower()
)
assert _has_routing_keyword or _has_target_room, (
f"Bot response is neither a move-request nor an auto-route announcement. "
f"Expected routing keywords ({_routing_keywords}) or target room name. "
f"Got: '{move_req_text[:200]}'"
) )
# Step 3: Simulate button click — post MOVE_REQ:<source_room>::confirm_move # Step 3: Simulate button click — post MOVE_REQ:<source_room>::confirm_move
+5 -2
View File
@@ -91,13 +91,15 @@ def test_04_multi_room(
# Step 2: Wait for bot response in main room # Step 2: Wait for bot response in main room
# The bot should acknowledge the message (even if auto-routed) # The bot should acknowledge the message (even if auto-routed)
# Pause 10s to let rate-limit window reset after test_03
time.sleep(10.0)
try: try:
bot_response = wait_for_bot_message( bot_response = wait_for_bot_message(
client=rc_client, client=rc_client,
room_id=test_room_id, room_id=test_room_id,
bot_username=bot_username, bot_username=bot_username,
cursor=main_cursor, cursor=main_cursor,
timeout=25.0, timeout=30.0, # increased from 25s
rate_limiter=rate_limiter, rate_limiter=rate_limiter,
) )
except RateLimitSkip as e: except RateLimitSkip as e:
@@ -120,7 +122,8 @@ def test_04_multi_room(
logger.info("Test 04: project room cursor = %s", project_cursor[:19]) logger.info("Test 04: project room cursor = %s", project_cursor[:19])
# Give the Archivar a moment to complete the copy # Give the Archivar a moment to complete the copy
time.sleep(2.0) # Increased from 2s to 5s — fewer API calls, less rate-limit pressure
time.sleep(5.0)
try: try:
rate_limiter.acquire() rate_limiter.acquire()