feat(F547,F548): DDP-Congestion-Prevention + P-025 Onboarding-Guard Fix
F547 — PresenceEngine DDP-Congestion-Prevention (id=5385): - Layer 1: DDPFirstSender.send() überspringt DDP-Method-Calls bei ddp_healthy=False und nutzt direkt REST (HALF_OPEN-Probe alle 30s). Fix gegen 1033 calls/h am 19.09. (23% DDP-Stream-Blockierung). - Layer 2: Backoff — ddp_healthy erst nach N=3 konsekutiven Erfolgen wieder True (1 Erfolg ist kein Gesundungs-Signal, P-090-Muster). - Layer 3: non-blocking Telemetrie (_telemetry_ddp_pauses/resumes). F548 — P-025 Onboarding-Guard Fix (id=5386): - Fix B/D: advance_test()/complete() leeren missing_rooms + current_room_index IMMER (Datenintegrität — kein Zombie-State für B9-Reconnect). - Fix A: _sanitize_missing_rooms_for_trigger() filtert Räume, die inzwischen in excluded_rooms sind → kein Onboarding-Neustart. - Fix C: skipped_rooms-Filter (Räume aus skipped_rooms werden gefiltert). - B9-Trigger in connect() nutzt Sanitization. Keine ENV-Vars (config.yaml/AGENTS.md: .env = secrets only). Keine __init__.py Änderungen (P-294). Tests: test_f547_ddp_congestion.py (12), test_f548_onboarding_guard.py (9), test_p041b_ddp_stability.py angepasst. 190 presence-tests + 147 onboarding-tests grün. @implements: [F-547] [F-548]
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
"""
|
||||
F-548: P-025 Onboarding-Guard Fix Tests.
|
||||
|
||||
Verifiziert Rainers Architektur-Vorgabe in der Reihenfolge B+D → A → C:
|
||||
|
||||
Fix B+D (Datenintegrität): advance_test()/complete() müssen missing_rooms
|
||||
IMMER leeren. Ein ACTIVE-State mit nicht-leerem missing_rooms ist der
|
||||
Root-Cause des P-025-Loops (B9-Reconnect-Trigger findet stale
|
||||
missing_rooms → startet Onboarding neu → Guard schluckt Nachrichten).
|
||||
|
||||
Fix A (Trigger-Schutz): B9-Reconnect-Trigger darf kein Onboarding neu
|
||||
starten, wenn missing_rooms NUR Räume enthält, die inzwischen in
|
||||
excluded_rooms sind (19.09.-Vorfall: 5 Gateway-Neustarts).
|
||||
|
||||
Fix C (skipped_rooms-Filter): Räume, die in skipped_rooms stehen, werden
|
||||
aus missing_rooms gefiltert.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
|
||||
from archivar.onboarding_state import (
|
||||
OnboardingState,
|
||||
OnboardingStateMachine,
|
||||
)
|
||||
|
||||
|
||||
# ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _make_sm_with_missing(tmp_path) -> OnboardingStateMachine:
|
||||
"""State Machine bis AWAITING_TEST mit nicht-leeren missing_rooms."""
|
||||
path = str(tmp_path / "onboarding.yaml")
|
||||
sm = OnboardingStateMachine(state_path=path)
|
||||
sm.load()
|
||||
sm.start(
|
||||
operator_room_id="dm1",
|
||||
missing_rooms=[
|
||||
{"room_id": "r1", "name": "#Raum1"},
|
||||
{"room_id": "r2", "name": "#Raum2"},
|
||||
],
|
||||
)
|
||||
sm.advance_room()
|
||||
sm.advance_intent()
|
||||
assert sm.state == OnboardingState.AWAITING_TEST
|
||||
assert sm._data.missing_rooms != []
|
||||
return sm
|
||||
|
||||
|
||||
def _make_adapter_stub(excluded: set | None = None, skipped: list | None = None):
|
||||
"""Minimal-Adapter-Stub mit den Attributen, die _sanitize_missing_rooms
|
||||
liest: self.archivar._room_map.excluded_room_ids und self._onboarding_sm.
|
||||
"""
|
||||
room_map = SimpleNamespace(excluded_room_ids=set(excluded or []))
|
||||
|
||||
class _SMData:
|
||||
skipped_rooms = list(skipped or [])
|
||||
|
||||
class _SM:
|
||||
_data = _SMData()
|
||||
|
||||
adapter = SimpleNamespace()
|
||||
adapter.archivar = SimpleNamespace(_room_map=room_map)
|
||||
adapter._onboarding_sm = _SM()
|
||||
return adapter
|
||||
|
||||
|
||||
# ── Fix B/D: Datenintegrität ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestFixBDDataIntegrity:
|
||||
"""advance_test()/complete() leeren missing_rooms IMMER."""
|
||||
|
||||
def test_advance_test_empties_missing_rooms(self, tmp_path):
|
||||
"""advance_test() → ACTIVE mit missing_rooms=[]."""
|
||||
sm = _make_sm_with_missing(tmp_path)
|
||||
assert sm.advance_test()
|
||||
assert sm.state == OnboardingState.ACTIVE
|
||||
assert sm._data.missing_rooms == []
|
||||
assert sm._data.current_room_index == -1
|
||||
|
||||
def test_advance_test_persists_empty_missing_rooms(self, tmp_path):
|
||||
"""Nach advance_test() ist missing_rooms=[] AUF DISK (Restart-sicher)."""
|
||||
sm = _make_sm_with_missing(tmp_path)
|
||||
assert sm.advance_test()
|
||||
|
||||
# Reload aus Disk — simuliert Gateway-Restart
|
||||
reloaded = OnboardingStateMachine(state_path=sm._state_path)
|
||||
reloaded.load()
|
||||
assert reloaded.state == OnboardingState.ACTIVE
|
||||
assert reloaded._data.missing_rooms == []
|
||||
|
||||
def test_complete_empties_missing_rooms(self, tmp_path):
|
||||
"""complete() (Skip-All-Pfad) → ACTIVE mit missing_rooms=[]."""
|
||||
path = str(tmp_path / "onboarding.yaml")
|
||||
sm = OnboardingStateMachine(state_path=path)
|
||||
sm.load()
|
||||
# Setze manuell missing_rooms um den Skip-All-Pfad zu simulieren
|
||||
sm._data.missing_rooms = [{"room_id": "r1", "name": "#Raum1"}]
|
||||
assert sm.complete()
|
||||
assert sm.state == OnboardingState.ACTIVE
|
||||
assert sm._data.missing_rooms == []
|
||||
|
||||
|
||||
# ── Fix A: Trigger-Schutz ────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestFixATriggerProtection:
|
||||
"""missing_rooms NUR aus excluded_rooms → kein Onboarding-Neustart."""
|
||||
|
||||
def _sanitize(self, missing, excluded):
|
||||
adapter = _make_adapter_stub(excluded=excluded)
|
||||
# Binde die Methode an den Stub
|
||||
from archivar.onboarding_state import OnboardingStateMachine
|
||||
# Import der Methode aus adapter ist teuer (schwerer Import); wir
|
||||
# testen die Logik über eine lokale Kopie, die identisch implementiert
|
||||
# ist. Stattdessen: direkten Import des echten Adapters vermeiden und
|
||||
# die Methode per unbound + __get__ binden.
|
||||
import plugin.adapter as _adapter_mod
|
||||
return _adapter_mod.RocketChatAdapter._sanitize_missing_rooms_for_trigger(
|
||||
adapter, missing
|
||||
)
|
||||
|
||||
def test_all_excluded_returns_empty(self):
|
||||
"""Alle missing_rooms sind excluded → leere Liste (kein Trigger)."""
|
||||
missing = [
|
||||
{"room_id": "r_ex1", "name": "#Ex1"},
|
||||
{"room_id": "r_ex2", "name": "#Ex2"},
|
||||
]
|
||||
result = self._sanitize(missing, excluded={"r_ex1", "r_ex2"})
|
||||
assert result == []
|
||||
|
||||
def test_partially_excluded_keeps_genuine(self):
|
||||
"""Nur echte (nicht-excluded) Räume bleiben erhalten."""
|
||||
missing = [
|
||||
{"room_id": "r_ex1", "name": "#Ex1"},
|
||||
{"room_id": "r_new", "name": "#Neu"},
|
||||
]
|
||||
result = self._sanitize(missing, excluded={"r_ex1"})
|
||||
assert [r["room_id"] for r in result] == ["r_new"]
|
||||
|
||||
def test_no_excluded_returns_all(self):
|
||||
"""Keine excluded → alle missing_rooms bleiben erhalten."""
|
||||
missing = [
|
||||
{"room_id": "r_new1", "name": "#Neu1"},
|
||||
{"room_id": "r_new2", "name": "#Neu2"},
|
||||
]
|
||||
result = self._sanitize(missing, excluded=set())
|
||||
assert [r["room_id"] for r in result] == ["r_new1", "r_new2"]
|
||||
|
||||
|
||||
# ── Fix C: skipped_rooms-Filter ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestFixCSkippedRoomsFilter:
|
||||
"""Räume in skipped_rooms werden aus missing_rooms gefiltert."""
|
||||
|
||||
def _sanitize(self, missing, skipped):
|
||||
adapter = _make_adapter_stub(excluded=set(), skipped=skipped)
|
||||
import plugin.adapter as _adapter_mod
|
||||
return _adapter_mod.RocketChatAdapter._sanitize_missing_rooms_for_trigger(
|
||||
adapter, missing
|
||||
)
|
||||
|
||||
def test_skipped_room_filtered(self):
|
||||
"""Ein skipped Raum wird gefiltert, ein echter bleibt."""
|
||||
missing = [
|
||||
{"room_id": "r_skip", "name": "#Skip"},
|
||||
{"room_id": "r_new", "name": "#Neu"},
|
||||
]
|
||||
result = self._sanitize(missing, skipped=["r_skip"])
|
||||
assert [r["room_id"] for r in result] == ["r_new"]
|
||||
|
||||
def test_all_skipped_returns_empty(self):
|
||||
"""Alle Räume skipped → leere Liste."""
|
||||
missing = [{"room_id": "r_skip1", "name": "#S1"}]
|
||||
result = self._sanitize(missing, skipped=["r_skip1"])
|
||||
assert result == []
|
||||
|
||||
|
||||
# ── Kombination A+C ──────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestFixACCombined:
|
||||
"""excluded UND skipped werden gleichzeitig gefiltert."""
|
||||
|
||||
def test_combined_filter(self):
|
||||
missing = [
|
||||
{"room_id": "r_ex", "name": "#Ex"},
|
||||
{"room_id": "r_skip", "name": "#Skip"},
|
||||
{"room_id": "r_real", "name": "#Real"},
|
||||
]
|
||||
adapter = _make_adapter_stub(excluded={"r_ex"}, skipped=["r_skip"])
|
||||
import plugin.adapter as _adapter_mod
|
||||
result = _adapter_mod.RocketChatAdapter._sanitize_missing_rooms_for_trigger(
|
||||
adapter, missing
|
||||
)
|
||||
assert [r["room_id"] for r in result] == ["r_real"]
|
||||
Reference in New Issue
Block a user