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]
This commit is contained in:
@@ -28,6 +28,11 @@ 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, RateLimitSkip
|
||||
from tests.live_rc.helpers.pacing import (
|
||||
Pacer,
|
||||
PacingConfig,
|
||||
config_from_env,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -43,6 +48,116 @@ def pytest_configure(config):
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# F172 — Human-Tempo-Pacing CLI-Flags (Architektur §3.1)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
#
|
||||
# Priorität: ENV > CLI > Code-Default (Architektur §3.2).
|
||||
# ``--fast-mode`` ist ein Alias für ``--human-tempo=off`` (Unit-Tests ohne LLM).
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
group = parser.getgroup("f172-pacing", "F172 Human-Tempo-Pacing")
|
||||
group.addoption(
|
||||
"--human-tempo",
|
||||
action="store",
|
||||
default=None,
|
||||
choices=("on", "off"),
|
||||
help="Human-Tempo-Pacing aktivieren (on, Default) oder deaktivieren (off).",
|
||||
)
|
||||
group.addoption(
|
||||
"--fast-mode",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Alias für --human-tempo=off (deaktiviert Pacing, für Unit-Tests ohne LLM).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-think-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_think-Pause in Sekunden (Default 30).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-think-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_think-Pause in Sekunden (Default 60).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-read-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_read-Pause in Sekunden (Default 2).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-read-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_read-Pause in Sekunden (Default 5).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-click-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_click-Pause in Sekunden (Default 3).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-click-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_click-Pause in Sekunden (Default 8).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-jitter",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Anteilige Streuung (Default 0.2 = ±20%%).",
|
||||
)
|
||||
|
||||
|
||||
def _build_pacing_config(config) -> PacingConfig:
|
||||
"""Baut die PacingConfig aus ENV + CLI (CLI hat Vorrang vor ENV)."""
|
||||
cfg = config_from_env()
|
||||
|
||||
# --fast-mode gewinnt über alles (expliziter Off-Schalter).
|
||||
if config.getoption("--fast-mode"):
|
||||
cfg.enabled = False
|
||||
|
||||
# --human-tempo explizit gesetzt?
|
||||
ht = config.getoption("--human-tempo")
|
||||
if ht is not None:
|
||||
cfg.enabled = ht == "on"
|
||||
|
||||
def _opt(name):
|
||||
return config.getoption(name)
|
||||
|
||||
# CLI-Ranges überschreiben ENV/Default nur wenn explizit gesetzt.
|
||||
if _opt("--pacing-think-min") is not None:
|
||||
cfg.think_min_s = _opt("--pacing-think-min")
|
||||
if _opt("--pacing-think-max") is not None:
|
||||
cfg.think_max_s = _opt("--pacing-think-max")
|
||||
if _opt("--pacing-read-min") is not None:
|
||||
cfg.read_min_s = _opt("--pacing-read-min")
|
||||
if _opt("--pacing-read-max") is not None:
|
||||
cfg.read_max_s = _opt("--pacing-read-max")
|
||||
if _opt("--pacing-click-min") is not None:
|
||||
cfg.click_min_s = _opt("--pacing-click-min")
|
||||
if _opt("--pacing-click-max") is not None:
|
||||
cfg.click_max_s = _opt("--pacing-click-max")
|
||||
if _opt("--pacing-jitter") is not None:
|
||||
cfg.jitter = _opt("--pacing-jitter")
|
||||
|
||||
return cfg
|
||||
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Env-var check — skip entire suite at collection time if not configured
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -332,6 +447,53 @@ def rate_limiter() -> RateLimiter:
|
||||
return _get_rate_limiter()
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# F172 — Pacing-Fixture (Architektur §4.2)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def pacer(request) -> Pacer:
|
||||
"""Session-scoped Pacer, konfiguriert aus ENV + CLI-Flags.
|
||||
|
||||
Tests rufen ``pacer.wait("think"|"read"|"click"|"idle")`` explizit
|
||||
zwischen REST-Post und Polling auf (Architektur §2.2: Harness setzt
|
||||
den Pacing-Typ explizit, keine Inferenz).
|
||||
"""
|
||||
cfg = _build_pacing_config(request.config)
|
||||
logger.info(
|
||||
"F172: Pacing %s (think %.0f-%.0fs, read %.0f-%.0fs, click %.0f-%.0fs, jitter %.2f)",
|
||||
"AKTIV" if cfg.enabled else "DEAKTIVIERT",
|
||||
cfg.think_min_s, cfg.think_max_s,
|
||||
cfg.read_min_s, cfg.read_max_s,
|
||||
cfg.click_min_s, cfg.click_max_s,
|
||||
cfg.jitter,
|
||||
)
|
||||
return Pacer(config=cfg)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def _reset_timeout_before_suite(request, rc_client: RCRestClient, rc_config: dict):
|
||||
"""F169-Reset VOR Test-Start (Rainers Veto, Architektur §5.2).
|
||||
|
||||
Postet ``::reset-timeout`` einmalig vor dem ersten Test, damit die
|
||||
adaptive Timeout-Kalibrierung (Welford) nicht auf Bot-Tempo läuft.
|
||||
Ohne diesen Reset kalibriert F169 auf die Burst-Spitzen des
|
||||
Bot-Feuerwerks und der Timeout driftet zu lang (P-195-Kandidat).
|
||||
"""
|
||||
room_id = rc_config["test_room"]
|
||||
try:
|
||||
msg_id, _ = rc_client.post_message(room_id, "::reset-timeout")
|
||||
logger.info(
|
||||
"F169: ::reset-timeout vor Test-Start gesendet (msg %s)",
|
||||
msg_id[:12],
|
||||
)
|
||||
except RCRestError as e:
|
||||
# Nicht fatal — Reset ist Best-Effort, Test läuft weiter.
|
||||
logger.warning("F169: ::reset-timeout fehlgeschlagen: %s", e)
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cursor(rc_client: RCRestClient, test_room_id: str, rate_limiter: RateLimiter) -> str:
|
||||
"""Get the latest message timestamp as a cursor.
|
||||
|
||||
Reference in New Issue
Block a user