feat(F071,F068,F070): Welle 2 — Refactor-Audit, Stabilitaets-Monitor, Contract-Test-Framework @implements: [F-071] [F-068] [F-070]

This commit is contained in:
Bernd (Hermes)
2026-09-17 17:40:10 +02:00
parent df8be1c0d7
commit 31ca0f2533
13 changed files with 1527 additions and 0 deletions
+62
View File
@@ -1550,6 +1550,18 @@ class RocketChatAdapter(BasePlatformAdapter):
from archivar.inline_commands import InlineCommandRegistry
self._inline_commands = InlineCommandRegistry()
self._register_inline_commands()
# F068: 7-Tage-Stabilitätstest — Monitor persistiert State und zählt
# Messages/Fehler/Neustarts während eines laufenden Testfensters.
try:
from archivar.stability_monitor import stability_monitor
self._stability_monitor = stability_monitor
self._stability_monitor.load()
self._stability_monitor.record_restart()
except Exception as e: # noqa: BLE001 - graceful degradation
self._stability_monitor = None
logger.warning("[f068] Stabilitäts-Monitor nicht initialisierbar: %s", e)
# R5: Username des letzten Inline-Command-Aufrufs (für ::reasoning
# Session-Key-Ableitung). Wird in _handle_inline_command gesetzt.
self._last_inline_username: str = ""
@@ -3218,6 +3230,15 @@ class RocketChatAdapter(BasePlatformAdapter):
# Update activity
self._last_activity = time.time()
# F068: Stabilitätstelemetrie — eingehende verarbeitete Nachricht zählen
_st_mon = getattr(self, "_stability_monitor", None)
if _st_mon is not None:
try:
_st_mon.record_message()
except Exception: # noqa: BLE001 - Telemetrie nie crashen
pass
room_name = self._room_info.get(room_id, {}).get("name", room_id)
room_type = self._room_info.get(room_id, {}).get("type", "unknown")
logger.info("[rocketchat] Message from %s in %s [%s]: %s", username, room_name, room_type, text[:80])
@@ -5321,6 +5342,40 @@ class RocketChatAdapter(BasePlatformAdapter):
category="Plugin",
)
# F068: 7-Tage-Stabilitätstest — Start/Bericht
self._inline_commands.register(
"stability-test", self._cmd_stability_test,
help_text="Startet den 7-Tage-Stabilitätstest (F068)",
description="Startet (oder setzt fort) den Stabilitätstest, der "
"7 Tage lang Telemetrie sammelt (Messages, Fehler, "
"Neustarts) und danach einen Bericht erstellt.",
category="Plugin",
)
self._inline_commands.register(
"stability-report", self._cmd_stability_report,
help_text="Erstellt den Stabilitätsbericht (F068)",
description="Erstellt jetzt den Stabilitätsbericht. Nach Ablauf "
"des 7-Tage-Fensters wird der Test als abgeschlossen "
"markiert.",
category="Plugin",
)
async def _cmd_stability_test(self, room_id: str, args: str) -> str:
"""::stability-test — Startet den 7-Tage-Stabilitätstest (F068)."""
monitor = getattr(self, "_stability_monitor", None)
if monitor is None:
return "⚠️ Stabilitäts-Monitor nicht verfügbar (Init-Fehler)."
return monitor.start()
async def _cmd_stability_report(self, room_id: str, args: str) -> str:
"""::stability-report — Erstellt den Stabilitätsbericht (F068)."""
monitor = getattr(self, "_stability_monitor", None)
if monitor is None:
return "⚠️ Stabilitäts-Monitor nicht verfügbar (Init-Fehler)."
if monitor.status.value == "inactive":
return "Kein Test aktiv. Start mit `::stability-test`."
return monitor.generate_report_snapshot()
async def _handle_inline_command(
self, text: str, room_id: str, room_name: str, username: str
) -> bool:
@@ -10570,6 +10625,13 @@ class RocketChatAdapter(BasePlatformAdapter):
break
except Exception as e:
logger.error("[rocketchat] Listener error: %s", e)
# F068: Fehler-Telemetrie — Listener-Fehler zählen
_st_err = getattr(self, "_stability_monitor", None)
if _st_err is not None:
try:
_st_err.record_error()
except Exception: # noqa: BLE001 - Telemetrie nie crashen
pass
await asyncio.sleep(1)
def _ddp_queue_get(self, timeout: float):