""" 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