1958a53f0e
FIX A1: Adapter-Integration nachgeliefert - adapter.py: init self._outbound_gate nach Z.1177, Gate-Check in send() nach Red-Flag, send_clarify() Gate-Check, release in _process_incoming finally und _dispatch_agent finally, _post_message_unlocked für Quick-Reply - archivar/SKILL.md: Z.20-21 ergänzt + Outbound-Sicht V9.x Abschnitt - archivar/adapter_integration.py: bind_outbound_gate Hook FIX A2: Tests grün (7/7, keine Warnings) - pytest-asyncio bereits installiert (pytest 9.1.0) - @pytest.mark.outbound_gate in conftest.py registriert FIX A3: try_acquire Spec-Abweichung behoben - try_acquire jetzt ASYNC (await asyncio.Lock) - Rückgabetyp: GateDecision Dataclass (allow, reason, blocking_room_id) - Reasons: gate_clear, same_room_same_token, same_room_different_token, different_room_busy FIX A4: wait_until_clear Spec-Abweichung behoben - blocking_room_id Parameter hinzugefügt - _waiters per-Raum Dict (nicht flat List) → kein False-Wake-Bug - _TurnHandle jetzt Dataclass mit task und chat_id Feldern W2: Sweep-Loop als asyncio.create_task im Adapter - _gate_sweep_loop() alle 30s, nicht threading.Timer - Gestartet in connect() nach _listen_loop Tests: 1359 passed, 0 failed, 0 regressions.
202 lines
5.8 KiB
Python
202 lines
5.8 KiB
Python
"""
|
|
V8.2.1: pytest-Fixtures für saubere Pfad-Tests.
|
|
|
|
Statt nested patches in jedem Test wird der room-map.json Pfad
|
|
pro Test umgebogen. Verwendet tempfile.TemporaryDirectory für
|
|
Isolation.
|
|
|
|
V8.3.3: Erweiterte Fixtures für echte Integration-Tests mit
|
|
RoomMap, FAISS-Index und Mock-LLM.
|
|
"""
|
|
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
# P5 V9.x: OutboundGate Marker registrieren
|
|
def pytest_configure(config):
|
|
config.addinivalue_line(
|
|
"markers", "outbound_gate: P5 V9.x OutboundGate Parallel-Stream-Schutz Tests"
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_room_map_path():
|
|
"""Erzeugt eine temporäre room-map.json mit minimalem Test-Setup.
|
|
|
|
Returns:
|
|
Path: Pfad zur temporären room-map.json.
|
|
"""
|
|
tmp = tempfile.TemporaryDirectory()
|
|
map_path = Path(tmp.name) / "room-map.json"
|
|
|
|
test_data = {
|
|
"version": 2,
|
|
"rooms": {
|
|
"catchall_id": {
|
|
"name": "#CatchAll",
|
|
"theme": "Catch-all room",
|
|
"keywords_100": [],
|
|
"keywords_context": [],
|
|
"catch_all": True,
|
|
},
|
|
"plugin_room_id": {
|
|
"name": "#Rocketchat-Plugin",
|
|
"theme": "Plugin-Entwicklung",
|
|
"keywords_100": ["plugin"],
|
|
"keywords_context": ["adapter"],
|
|
"catch_all": False,
|
|
},
|
|
},
|
|
"excluded_rooms": [],
|
|
"fact_store_path": str(Path(tmp.name) / "docs"),
|
|
}
|
|
with open(map_path, "w") as f:
|
|
json.dump(test_data, f)
|
|
|
|
yield map_path
|
|
tmp.cleanup()
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_state_path():
|
|
"""Erzeugt einen temporären Pfad für archivar_state.json.
|
|
|
|
Returns:
|
|
str: Pfad zur temporären State-Datei.
|
|
"""
|
|
tmp = tempfile.TemporaryDirectory()
|
|
state_path = str(Path(tmp.name) / "archivar_state.json")
|
|
yield state_path
|
|
tmp.cleanup()
|
|
|
|
|
|
# ── V8.3.3: Erweiterte Fixtures für echte Integration-Tests ──────────────
|
|
|
|
|
|
@pytest.fixture
|
|
def multi_room_map_path():
|
|
"""Erzeugt eine temporäre room-map.json mit 4 Räumen + Catch-All.
|
|
|
|
Räume:
|
|
- #RC-Plugin (keywords_100: plugin, rocketchat; context: adapter, gateway)
|
|
- #LAN-Doku (keywords_100: dokumentation, doku; context: netzwerk, lan)
|
|
- #BAT-Team (keywords_100: bat, team; context: support, hilfe)
|
|
- #DevOps (keywords_100: devops, deployment; context: ci, cd, pipeline)
|
|
- #CatchAll (catch_all)
|
|
|
|
Returns:
|
|
Path: Pfad zur temporären room-map.json.
|
|
"""
|
|
tmp = tempfile.TemporaryDirectory()
|
|
map_path = Path(tmp.name) / "room-map.json"
|
|
|
|
test_data = {
|
|
"version": 5,
|
|
"rooms": {
|
|
"room_rc_plugin": {
|
|
"name": "#RC-Plugin",
|
|
"theme": "Rocket.Chat Plugin Entwicklung und Wartung",
|
|
"description": "Entwicklung des Hermes Rocket.Chat Plugins",
|
|
"keywords_100": ["plugin", "rocketchat"],
|
|
"keywords_context": ["adapter", "gateway"],
|
|
"catch_all": False,
|
|
},
|
|
"room_lan_doku": {
|
|
"name": "#LAN-Doku",
|
|
"theme": "LAN Dokumentation und Netzwerk",
|
|
"description": "Dokumentation des LAN-Netzwerks",
|
|
"keywords_100": ["dokumentation", "doku"],
|
|
"keywords_context": ["netzwerk", "lan"],
|
|
"catch_all": False,
|
|
},
|
|
"room_bat_team": {
|
|
"name": "#BAT-Team",
|
|
"theme": "BAT Team Koordination",
|
|
"description": "Koordination des BAT-Teams",
|
|
"keywords_100": ["bat", "team"],
|
|
"keywords_context": ["support", "hilfe"],
|
|
"catch_all": False,
|
|
},
|
|
"room_devops": {
|
|
"name": "#DevOps",
|
|
"theme": "DevOps und Deployment",
|
|
"description": "CI/CD und Deployment-Infrastruktur",
|
|
"keywords_100": ["devops", "deployment"],
|
|
"keywords_context": ["ci", "cd", "pipeline"],
|
|
"catch_all": False,
|
|
},
|
|
"room_catchall": {
|
|
"name": "#CatchAll",
|
|
"theme": "Catch-all room",
|
|
"keywords_100": [],
|
|
"keywords_context": [],
|
|
"catch_all": True,
|
|
},
|
|
},
|
|
"excluded_rooms": [],
|
|
"butler_mode": "cognitive",
|
|
"fact_store_path": str(Path(tmp.name) / "docs"),
|
|
}
|
|
with open(map_path, "w") as f:
|
|
json.dump(test_data, f)
|
|
|
|
yield map_path
|
|
tmp.cleanup()
|
|
|
|
|
|
@pytest.fixture
|
|
def multi_room_map(multi_room_map_path):
|
|
"""Lädt eine echte RoomMap aus multi_room_map_path.
|
|
|
|
Returns:
|
|
RoomMap: Geladene RoomMap mit 4 Räumen + Catch-All.
|
|
"""
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
|
|
|
from plugin.archivar.room_map import RoomMap
|
|
|
|
return RoomMap.load(path=Path(str(multi_room_map_path)))
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_llm_stay():
|
|
"""Mock-LLM das immer STAY zurückgibt.
|
|
|
|
Returns:
|
|
callable: Async-Funktion die (None, False, False) zurückgibt (STAY).
|
|
"""
|
|
async def _mock_llm(prompt: str):
|
|
return "STAY" # STAY
|
|
return _mock_llm
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_llm_route():
|
|
"""Mock-LLM das immer ROUTE zu room_rc_plugin zurückgibt.
|
|
|
|
Returns:
|
|
callable: Async-Funktion die (RoomEntry, False, False) zurückgibt.
|
|
"""
|
|
async def _mock_llm(prompt: str):
|
|
return "room_rc_plugin" # ROUTE to #RC-Plugin
|
|
return _mock_llm
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_llm_failed():
|
|
"""Mock-LLM das immer fehlschlägt (None zurückgibt).
|
|
|
|
Returns:
|
|
callable: Async-Funktion die (None, False, True) zurückgibt (FAILED).
|
|
"""
|
|
async def _mock_llm(prompt: str):
|
|
return None # FAILED
|
|
return _mock_llm
|