Files
Bernd (Hermes) 05531f1d8d feat(F172): Human-Tempo-Pacing im Laborassistent-Harness
Pacing-Modul (tests/live_rc/helpers/pacing.py) simuliert menschliche
Interaktionsrhythmen im Test-Runner — NICHT im Archivar (bleibt unverändert).

- 3 Pacing-Klassen: think (30-60s), read (2-5s), click (3-8s), idle (0s)
- Jitter ±20% (uniform) gegen Lock-Step mit Hintergrund-Tickern
- Konfiguration: ENV (RC_LIVE_*) > CLI-Flags > Code-Default
  --human-tempo={on,off}, --fast-mode, --pacing-{think,read,click}-{min,max}, --pacing-jitter
- F169-Reset: ::reset-timeout wird vor Test-Start gepostet (Rainers Veto)
- Quota-Schutz: avoided_llm_calls-Zähler protokolliert vermiedene LLM-Calls
- 22 Unit-Tests (tests/test_pacing.py) — Pacing wirkt, Kategorien korrekt,
  Config änderbar, Jitter-Korridor, Quota-Telemetrie
- test_01_echo als Referenz-Integration (pacer.wait('think') nach REST-Post)

@implements: [F-172]
2026-09-05 12:32:48 +02:00

111 lines
3.2 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,
pacer,
):
"""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])
# F172: Pacing — Mensch liest Antwort, überlegt, tippt (30-60s).
# Greift NUR im Test-Runner, NICHT im Archivar. Verhindert Bot-Feuerwerk
# (10-20 LLM-Calls/30s) und hält F120/F169 unter realer Last.
pacer.wait("think")
# 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 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")