fix(P1-3): None-Guard für _presence_engine in _send_onboarding_message und _complete_onboarding
- _send_onboarding_message (Z.4322-4323): _has_presence-Guard vor set_onboarding_active/update_presence - _complete_onboarding (Z.5867-5868): _has_presence-Guard vor set_onboarding_active/update_presence - Pattern konsistent mit bestehenden Guards an Z.1675/1927/2568/2868 - 2 neue Tests: TestPresenceEngineNoneGuard (test_send_onboarding_message_without_presence_engine, test_complete_onboarding_without_presence_engine)
This commit is contained in:
+8
-4
@@ -4319,8 +4319,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
if _MULTIROOM() and self.archivar is not None:
|
if _MULTIROOM() and self.archivar is not None:
|
||||||
self.archivar._stats["onboarding_active"] = True
|
self.archivar._stats["onboarding_active"] = True
|
||||||
# ── V8.6: PresenceEngine — Onboarding start → away ──
|
# ── V8.6: PresenceEngine — Onboarding start → away ──
|
||||||
self._presence_engine.set_onboarding_active(True)
|
_has_presence = hasattr(self, '_presence_engine') and self._presence_engine is not None
|
||||||
self._presence_engine.update_presence()
|
if _has_presence:
|
||||||
|
self._presence_engine.set_onboarding_active(True)
|
||||||
|
self._presence_engine.update_presence()
|
||||||
|
|
||||||
# Bug 3 fix: Robuster Zugriff auf _build_custom_buttons
|
# Bug 3 fix: Robuster Zugriff auf _build_custom_buttons
|
||||||
_build = self._get_build_custom_buttons()
|
_build = self._get_build_custom_buttons()
|
||||||
@@ -5864,8 +5866,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
self.archivar._state.clear_onboarding_state()
|
self.archivar._state.clear_onboarding_state()
|
||||||
self._onboarding_state = {}
|
self._onboarding_state = {}
|
||||||
# ── V8.6: PresenceEngine — Onboarding end → online ──
|
# ── V8.6: PresenceEngine — Onboarding end → online ──
|
||||||
self._presence_engine.set_onboarding_active(False)
|
_has_presence = hasattr(self, '_presence_engine') and self._presence_engine is not None
|
||||||
self._presence_engine.update_presence()
|
if _has_presence:
|
||||||
|
self._presence_engine.set_onboarding_active(False)
|
||||||
|
self._presence_engine.update_presence()
|
||||||
# F8: State Machine — AWAITING_TEST → ACTIVE
|
# F8: State Machine — AWAITING_TEST → ACTIVE
|
||||||
if hasattr(self, '_onboarding_sm'):
|
if hasattr(self, '_onboarding_sm'):
|
||||||
self._onboarding_sm.advance_test()
|
self._onboarding_sm.advance_test()
|
||||||
|
|||||||
@@ -282,3 +282,58 @@ class TestPresenceEngineInitErrorHandling:
|
|||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
logger.removeHandler(handler)
|
logger.removeHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPresenceEngineNoneGuard:
|
||||||
|
"""P1-3: _send_onboarding_message und _complete_onboarding müssen
|
||||||
|
ohne _presence_engine (None) keinen AttributeError werfen."""
|
||||||
|
|
||||||
|
def test_send_onboarding_message_without_presence_engine(self):
|
||||||
|
"""_send_onboarding_message: ohne _presence_engine → kein Crash."""
|
||||||
|
import asyncio
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
|
from plugin.adapter import RocketChatAdapter
|
||||||
|
|
||||||
|
adapter = RocketChatAdapter.__new__(RocketChatAdapter)
|
||||||
|
# _presence_engine NICHT setzen — simuliert graceful degradation
|
||||||
|
adapter.archivar = MagicMock()
|
||||||
|
adapter.archivar._state = MagicMock()
|
||||||
|
adapter.archivar._stats = {}
|
||||||
|
adapter._room_info = {}
|
||||||
|
adapter._onboarding_state = None
|
||||||
|
adapter._get_build_custom_buttons = MagicMock(return_value=MagicMock())
|
||||||
|
adapter._post_message_with_retry = AsyncMock()
|
||||||
|
|
||||||
|
missing_rooms = [{"room_id": "room1", "name": "#test"}]
|
||||||
|
|
||||||
|
with patch("plugin.adapter._MULTIROOM", return_value=True):
|
||||||
|
try:
|
||||||
|
asyncio.run(adapter._send_onboarding_message("op_room", missing_rooms))
|
||||||
|
except AttributeError as e:
|
||||||
|
pytest.fail(
|
||||||
|
f"_send_onboarding_message crashed ohne _presence_engine: {e}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_complete_onboarding_without_presence_engine(self):
|
||||||
|
"""_complete_onboarding: ohne _presence_engine → kein Crash."""
|
||||||
|
import asyncio
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from plugin.adapter import RocketChatAdapter
|
||||||
|
|
||||||
|
adapter = RocketChatAdapter.__new__(RocketChatAdapter)
|
||||||
|
# _presence_engine NICHT setzen
|
||||||
|
adapter.archivar = MagicMock()
|
||||||
|
adapter.archivar._stats = {}
|
||||||
|
adapter.archivar._state = MagicMock()
|
||||||
|
adapter._onboarding_state = {"missing_rooms": []}
|
||||||
|
adapter._room_map_summary = ""
|
||||||
|
|
||||||
|
with patch("archivar.onboarding.release_onboarding_lock"):
|
||||||
|
try:
|
||||||
|
asyncio.run(adapter._complete_onboarding("op_room"))
|
||||||
|
except AttributeError as e:
|
||||||
|
pytest.fail(
|
||||||
|
f"_complete_onboarding crashed ohne _presence_engine: {e}"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user