90bad7d4da
- ::multiroom: start/stop/status (on/off als Aliase), Status zeigt subskribierte Räume - ::busy: on/off/status als Busy-Toggle (🟥/🟩) + queue/steer behalten - ::allowalways: list/add/remove (In-Memory-Liste) - ::setfakt: path <pfad> setzt FAKT-Speicherort direkt - ::curate: status/run dokumentiert - build_help_text_parts: RC-Sektion wandert in Teil 2, damit beide Teile < 4500 Zeichen - Tests: Subcommand-Assertions + Split-Logik angepasst
1585 lines
61 KiB
Python
1585 lines
61 KiB
Python
"""
|
|
Tests für A1b: R5 Inline-Commands + Thema B Onboarding-Guard.
|
|
|
|
Testet:
|
|
- ::-Befehlserkennung (parse_inline_command)
|
|
- Natürliche Hilfeseiten-Erkennung (is_natural_help_request)
|
|
- Command-Registry (InlineCommandRegistry)
|
|
- Help-Text-Generator (build_help_text, build_status_text)
|
|
- Onboarding-Guard (Thema B)
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, MagicMock, patch, call
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
|
|
# ── Thema A: Inline-Command-Parser ──────────────────────────────────────
|
|
|
|
class TestParseInlineCommand:
|
|
"""Tests für parse_inline_command."""
|
|
|
|
def test_parse_simple_command(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::hilfe")
|
|
assert result is not None
|
|
assert result[0] == "hilfe"
|
|
assert result[1] == ""
|
|
|
|
def test_parse_command_with_args(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::sethome meinraum")
|
|
assert result is not None
|
|
assert result[0] == "sethome"
|
|
assert result[1] == "meinraum"
|
|
|
|
def test_parse_command_case_insensitive(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::HILFE")
|
|
assert result is not None
|
|
assert result[0] == "hilfe"
|
|
|
|
def test_parse_no_colon_prefix(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("hilfe")
|
|
assert result is None
|
|
|
|
def test_parse_empty_colon(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::")
|
|
assert result is None
|
|
|
|
def test_parse_whitespace_after_colon(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command(" ::hilfe")
|
|
assert result is not None
|
|
assert result[0] == "hilfe"
|
|
|
|
def test_parse_command_with_multiple_args(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::setfakt /home/user/docs")
|
|
assert result is not None
|
|
assert result[0] == "setfakt"
|
|
assert result[1] == "/home/user/docs"
|
|
|
|
def test_parse_status_command(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::status")
|
|
assert result is not None
|
|
assert result[0] == "status"
|
|
|
|
def test_parse_reset_command(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::reset")
|
|
assert result is not None
|
|
assert result[0] == "reset"
|
|
|
|
|
|
# ── Thema A: Natürliche Hilfeseiten-Erkennung ────────────────────────────
|
|
|
|
class TestNaturalHelpRequest:
|
|
"""Tests für is_natural_help_request."""
|
|
|
|
def test_exact_match_hilfe(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("hilfe") is True
|
|
|
|
def test_exact_match_help(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("help") is True
|
|
|
|
def test_exact_match_was_kannst_du(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("was kannst du?") is True
|
|
|
|
def test_exact_match_rocketchat_hilfe(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("ich brauche hilfe zum rocketchat plugin") is True
|
|
|
|
@pytest.mark.xfail(reason="B7: is_natural_help_request ist strikt — nur exakte Matches oder kurze Sätze (≤30 Zeichen) mit Trigger-Präfix. 'hey, ich brauche hilfe...' (langer Satz) wird nicht mehr erkannt.")
|
|
def test_contains_match_long_trigger(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
# "ich brauche hilfe zum rocketchat plugin" ist >10 Zeichen
|
|
assert is_natural_help_request(
|
|
"hey, ich brauche hilfe zum rocketchat plugin bitte"
|
|
) is True
|
|
|
|
def test_no_match_normal_message(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("was ist der status vom server?") is False
|
|
|
|
def test_no_match_auftrag(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("mach mal den test fertig") is False
|
|
|
|
def test_case_insensitive(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("HILFE") is True
|
|
assert is_natural_help_request("Was Kannst Du?") is True
|
|
|
|
def test_whitespace_handling(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request(" hilfe ") is True
|
|
|
|
def test_commands_trigger(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("commands") is True
|
|
|
|
def test_was_geht_trigger(self):
|
|
from archivar.inline_commands import is_natural_help_request
|
|
assert is_natural_help_request("was geht?") is True
|
|
|
|
|
|
# ── Thema A: Command-Registry ───────────────────────────────────────────
|
|
|
|
class TestInlineCommandRegistry:
|
|
"""Tests für InlineCommandRegistry."""
|
|
|
|
def test_register_and_get_handler(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy_handler(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("test", dummy_handler, "Test command")
|
|
handler = registry.get_handler("test")
|
|
assert handler is not None
|
|
assert handler is dummy_handler
|
|
|
|
def test_get_nonexistent_handler(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
assert registry.get_handler("nonexistent") is None
|
|
|
|
def test_is_registered(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("test", dummy, "Test")
|
|
assert registry.is_registered("test") is True
|
|
assert registry.is_registered("other") is False
|
|
|
|
def test_get_commands(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("cmd1", dummy, "Help 1", category="A")
|
|
registry.register("cmd2", dummy, "Help 2", category="B")
|
|
|
|
cmds = registry.get_commands()
|
|
assert len(cmds) == 2
|
|
assert "cmd1" in cmds
|
|
assert "cmd2" in cmds
|
|
assert cmds["cmd1"]["category"] == "A"
|
|
assert cmds["cmd2"]["category"] == "B"
|
|
|
|
def test_register_with_description(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register(
|
|
"cmd", dummy,
|
|
help_text="Short help",
|
|
description="Long description",
|
|
category="Test",
|
|
)
|
|
cmds = registry.get_commands()
|
|
assert cmds["cmd"]["help_text"] == "Short help"
|
|
assert cmds["cmd"]["description"] == "Long description"
|
|
assert cmds["cmd"]["category"] == "Test"
|
|
|
|
|
|
# ── Thema A: Help-Text-Generator ────────────────────────────────────────
|
|
|
|
class TestBuildHelpText:
|
|
"""Tests für build_help_text."""
|
|
|
|
def test_build_help_text_with_commands(self):
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("hilfe", dummy, "Zeigt diese Hilfeseite", category="Hilfe")
|
|
registry.register("status", dummy, "Zeigt Plugin-Status", category="Hilfe")
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Raum")
|
|
|
|
text = build_help_text(registry)
|
|
assert "Core-Befehle" in text
|
|
assert "continue" in text
|
|
assert "/reset" in text
|
|
assert "/compress" in text
|
|
assert "::hilfe" in text
|
|
assert "::status" in text
|
|
assert "::sethome" in text
|
|
assert "Natürliche Sprach-Befehle" in text
|
|
assert "Plugin-Status" in text
|
|
|
|
def test_build_help_text_with_room_map(self):
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
room_map_summary = "Rocket.Chat Raum-Map:\n 1. #Test (abc123) — Thema: Test"
|
|
|
|
text = build_help_text(registry, room_map_summary=room_map_summary)
|
|
assert "#Test" in text
|
|
assert "Test" in text
|
|
|
|
def test_build_help_text_empty_registry(self):
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
text = build_help_text(registry)
|
|
assert "Rocket.Chat Plugin" in text
|
|
assert "Core-Befehle" in text
|
|
assert "continue" in text
|
|
assert "Natürliche Sprach-Befehle" in text
|
|
|
|
def test_build_help_text_length_limit(self):
|
|
"""P1-Fix: Hilfe-Text darf 4000 Zeichen nicht überschreiten."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
# Registriere viele Befehle um einen langen Text zu erzeugen
|
|
all_cmds = [
|
|
("sethome", "Standard"), ("reset", "Standard"), ("busy", "Standard"),
|
|
("allowalways", "Standard"), ("commands", "Info"), ("restart", "Gateway"),
|
|
("update", "Gateway"),
|
|
("setfakt", "Konfiguration"), ("hilfe", "Hilfe"), ("status", "Hilfe"),
|
|
("multiroom", "Plugin"), ("onboarding", "Plugin"), ("curate", "Plugin"),
|
|
]
|
|
for name, cat in all_cmds:
|
|
registry.register(name, dummy, f"Help for {name}", category=cat)
|
|
|
|
# Erzeuge eine große room_map_summary (simuliert 5 Räume)
|
|
big_summary = "Rocket.Chat Raum-Map:\n"
|
|
for i in range(5):
|
|
big_summary += (
|
|
f" {i+1}. #Raum{i+1} (room_id_{i+1}...) — "
|
|
f"Thema: Dies ist ein sehr langer Beschreibungstext für Raum {i+1} "
|
|
f"um die Länge der Hilfeseite künstlich zu erhöhen\n"
|
|
)
|
|
|
|
text = build_help_text(registry, room_map_summary=big_summary)
|
|
assert len(text) <= 4000, (
|
|
f"Hilfe-Text ist {len(text)} Zeichen lang, "
|
|
f"maximal erlaubt sind 4000"
|
|
)
|
|
|
|
def test_build_help_text_keeps_summary_when_short(self):
|
|
"""P1-Fix: Kurze room_map_summary bleibt erhalten."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("hilfe", dummy, "Zeigt Hilfeseite", category="Hilfe")
|
|
|
|
short_summary = "Raum-Map: 1 Raum"
|
|
text = build_help_text(registry, room_map_summary=short_summary)
|
|
assert "Raum-Map: 1 Raum" in text
|
|
assert len(text) <= 4000
|
|
|
|
def _build_full_registry(self):
|
|
"""Baut eine Registry mit ALLEN realen Befehlen (inkl. Subcommands)."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
# Alle realen Befehle aus adapter.py _register_inline_commands()
|
|
# inkl. Subcommands — spiegelt den Produktions-Registry-Stand.
|
|
registry.register(
|
|
"sethome", dummy,
|
|
"Setzt den Heimatraum (Alternative zu /sethome)",
|
|
category="Standard",
|
|
)
|
|
registry.register(
|
|
"reset", dummy,
|
|
"Setzt den Plugin-Status zurück (Alternative zu /reset)",
|
|
category="Standard",
|
|
)
|
|
registry.register(
|
|
"busy", dummy,
|
|
"Zeigt/steuert den Busy-Status (::Variante von /busy)",
|
|
category="Standard",
|
|
subcommands={
|
|
"on": "Busy-Status aktivieren (Bot zeigt 🟥 beschäftigt)",
|
|
"off": "Busy-Status deaktivieren (Bot zeigt 🟩 verfügbar)",
|
|
"status": "Aktuellen Busy-Status anzeigen",
|
|
"queue <text>": "Nachricht in die Queue parken",
|
|
"steer <text>": "Nachricht nach dem nächsten Tool-Call einschieben",
|
|
},
|
|
)
|
|
registry.register(
|
|
"allowalways", dummy,
|
|
"Verwaltet die Allow-Always-Liste (::Variante von /allow-always)",
|
|
category="Standard",
|
|
subcommands={
|
|
"list": "Zeigt alle Allow-Always-Einträge",
|
|
"add": "Fügt einen Befehl zur Allow-Always-Liste hinzu",
|
|
"remove": "Entfernt einen Befehl aus der Allow-Always-Liste",
|
|
},
|
|
)
|
|
registry.register(
|
|
"commands", dummy,
|
|
"Listet alle ::-Befehle (::Variante von /commands)",
|
|
category="Info",
|
|
)
|
|
registry.register(
|
|
"restart", dummy,
|
|
"Löst Gateway-Neustart aus (::Variante von /restart)",
|
|
category="Gateway",
|
|
)
|
|
registry.register(
|
|
"update", dummy,
|
|
"Zeigt Update-Informationen (::Variante von /update)",
|
|
category="Gateway",
|
|
)
|
|
registry.register(
|
|
"setfakt", dummy,
|
|
"Ändert den FAKT-Speicherort",
|
|
category="Konfiguration",
|
|
subcommands={
|
|
"path": "Setzt den Pfad für FAKT-Speicherung "
|
|
"(z.B. ::setfakt path /data/Wissensdatenbank/0100 Inbox)",
|
|
},
|
|
)
|
|
registry.register(
|
|
"hilfe", dummy,
|
|
"Zeigt diese Hilfeseite",
|
|
category="Hilfe",
|
|
)
|
|
registry.register(
|
|
"status", dummy,
|
|
"Zeigt aktuellen Plugin-Status",
|
|
category="Hilfe",
|
|
)
|
|
registry.register(
|
|
"multiroom", dummy,
|
|
"Multi-Room-Agent aktivieren/deaktivieren/Status",
|
|
category="Plugin",
|
|
subcommands={
|
|
"start": "Multi-Room-Agent aktivieren (Archivar + Butler)",
|
|
"stop": "Multi-Room-Agent deaktivieren (Single-Room-Modus)",
|
|
"status": "Zeigt ob Multi-Room aktiv ist und wieviele Räume subskribiert sind",
|
|
},
|
|
)
|
|
registry.register(
|
|
"onboarding", dummy,
|
|
"Onboarding steuern: start/status/resume/pause/abort/reset",
|
|
category="Plugin",
|
|
subcommands={
|
|
"start": "Startet das Onboarding neu",
|
|
"status": "Zeigt den aktuellen Onboarding-Status mit Fortschritt",
|
|
"resume": "Setzt ein pausiertes Onboarding fort",
|
|
"pause": "Pausiert das Onboarding",
|
|
"abort": "Bricht das Onboarding ab (mit Bestätigung)",
|
|
"reset": "Hart-Reset des Onboarding-State, Backups bleiben",
|
|
},
|
|
)
|
|
registry.register(
|
|
"curate", dummy,
|
|
"Kuratiert die Room-Map-Keywords (R10)",
|
|
category="Plugin",
|
|
subcommands={
|
|
"status": "Zeigt den Keyword-Kuratierungs-Status",
|
|
"run": "Führt eine Keyword-Kuratierung durch",
|
|
},
|
|
)
|
|
registry.register(
|
|
"keywords", dummy,
|
|
"Gesammelte Stichworte bewerten (V3 Silent Collector)",
|
|
category="Plugin",
|
|
subcommands={
|
|
"review": "Zeigt gesammelte Stichworte zur Bewertung (✅/❌)",
|
|
"status": "Zeigt wieviele Stichworte pro Raum gesammelt sind",
|
|
},
|
|
)
|
|
registry.register(
|
|
"butler", dummy,
|
|
"Butler-Lern-Modus anzeigen/wechseln (V3)",
|
|
category="Plugin",
|
|
subcommands={
|
|
"mode": "Zeigt den aktuellen Butler-Lern-Modus",
|
|
"mode proactive": "Wechselt zu proaktiv (4-Button-Rückfrage, V2)",
|
|
"mode silent_collector": "Wechselt zu stillem Sammeln (V3)",
|
|
},
|
|
)
|
|
registry.register(
|
|
"approve", dummy,
|
|
"Bestätigt einen gefährlichen Befehl (einmalig)",
|
|
category="Standard",
|
|
subcommands={
|
|
"session": "Bestätigt für die aktuelle Session",
|
|
"always": "Bestätigt dauerhaft (Allow-Always)",
|
|
},
|
|
)
|
|
registry.register(
|
|
"deny", dummy,
|
|
"Lehnt einen gefährlichen Befehl ab",
|
|
category="Standard",
|
|
)
|
|
registry.register(
|
|
"setstatus", dummy,
|
|
"Aktivitäts-Indikator an/abschalten (PresenceEngine)",
|
|
category="Plugin",
|
|
subcommands={
|
|
"on": "Aktivitäts-Indikator einschalten",
|
|
"off": "Aktivitäts-Indikator ausschalten",
|
|
"status": "Status des Aktivitäts-Indikators anzeigen",
|
|
},
|
|
)
|
|
registry.register(
|
|
"reasoning", dummy,
|
|
"Reasoning-Level steuern (::Variante von /reasoning)",
|
|
category="Konfiguration",
|
|
subcommands={
|
|
"none": "Reasoning komplett abschalten",
|
|
"low": "Kurzes, fokussiertes Reasoning",
|
|
"medium": "Ausgewogen (Standard)",
|
|
"high": "Gründliches Reasoning",
|
|
"xhigh": "Maximales Reasoning (Default bei Qwen3.8)",
|
|
"show": "Model-Reasoning in Antworten anzeigen",
|
|
"hide": "Model-Reasoning verbergen",
|
|
"reset": "Session-Override zurücksetzen",
|
|
"--global": "Permanent in config.yaml speichern (mit Level kombinierbar)",
|
|
},
|
|
)
|
|
registry.register(
|
|
"compress", dummy,
|
|
"Kontext manuell komprimieren (::Variante von /compress)",
|
|
category="Standard",
|
|
)
|
|
return registry
|
|
|
|
def test_build_help_text_full(self):
|
|
"""Vollständiger Text: ALLE Subcommands müssen vorhanden sein.
|
|
|
|
Andreas' Entscheidung: lieber den vollständigen Hilfetext über zwei
|
|
Textblöcke ausgeben, als eine unvollständige Seite. Der progressive
|
|
Kürzungs-Fix (f74d206) schnitt Subcommand-Details weg — das ist
|
|
nicht akzeptabel. Dieser Test prüft, dass KEIN Subcommand fehlt.
|
|
"""
|
|
from archivar.inline_commands import build_help_text
|
|
|
|
registry = self._build_full_registry()
|
|
text = build_help_text(registry, room_map_summary="")
|
|
|
|
# keywords Subcommands
|
|
assert "::keywords review" in text
|
|
assert "::keywords status" in text
|
|
# multiroom Subcommands
|
|
assert "::multiroom start" in text
|
|
assert "::multiroom stop" in text
|
|
assert "::multiroom status" in text
|
|
# busy Subcommands
|
|
assert "::busy on" in text
|
|
assert "::busy off" in text
|
|
assert "::busy status" in text
|
|
# allowalways Subcommands
|
|
assert "::allowalways list" in text
|
|
assert "::allowalways add" in text
|
|
assert "::allowalways remove" in text
|
|
# setfakt Subcommands
|
|
assert "::setfakt path" in text
|
|
# curate Subcommands
|
|
assert "::curate status" in text
|
|
assert "::curate run" in text
|
|
# butler Subcommands
|
|
assert "::butler mode" in text
|
|
assert "::butler mode proactive" in text
|
|
assert "::butler mode silent_collector" in text
|
|
# onboarding Subcommands
|
|
assert "::onboarding start" in text
|
|
assert "::onboarding status" in text
|
|
assert "::onboarding resume" in text
|
|
assert "::onboarding pause" in text
|
|
assert "::onboarding abort" in text
|
|
assert "::onboarding reset" in text
|
|
# approve Subcommands
|
|
assert "::approve session" in text
|
|
assert "::approve always" in text
|
|
# setstatus Subcommands
|
|
assert "::setstatus on" in text
|
|
assert "::setstatus off" in text
|
|
assert "::setstatus status" in text
|
|
# reasoning Subcommands
|
|
assert "::reasoning none" in text
|
|
assert "::reasoning low" in text
|
|
assert "::reasoning medium" in text
|
|
assert "::reasoning high" in text
|
|
assert "::reasoning xhigh" in text
|
|
assert "::reasoning show" in text
|
|
assert "::reasoning hide" in text
|
|
assert "::reasoning reset" in text
|
|
assert "::reasoning --global" in text
|
|
|
|
def test_build_help_text_split(self):
|
|
"""Bei > 4500 Zeichen werden zwei Teile geliefert, beide < 4500."""
|
|
from archivar.inline_commands import build_help_text_parts
|
|
|
|
registry = self._build_full_registry()
|
|
parts = build_help_text_parts(registry, room_map_summary="")
|
|
|
|
# Der vollständige Text ist > 4500 Zeichen → zwei Teile
|
|
assert len(parts) == 2, f"Erwartet 2 Teile, bekam {len(parts)}"
|
|
for i, part in enumerate(parts, start=1):
|
|
assert len(part) < 4500, (
|
|
f"Teil {i} ist {len(part)} Zeichen lang, "
|
|
f"maximal erlaubt sind < 4500"
|
|
)
|
|
|
|
# Teil 1 enthält Core + Standard-Hermes-Befehle
|
|
assert "Core-Befehle" in parts[0]
|
|
assert "Standard-Hermes-Befehle" in parts[0]
|
|
# Teil 2 enthält RC-Plugin-Befehle + natürliche Sprache + Status + Tipp
|
|
assert "RC-Plugin-spezifische Befehle" in parts[1]
|
|
assert "Natürliche Sprach-Befehle" in parts[1]
|
|
assert "Plugin-Status" in parts[1]
|
|
assert "Tipp" in parts[1]
|
|
|
|
# KEIN Subcommand darf fehlen — über beide Teile hinweg
|
|
combined = "\n".join(parts)
|
|
for sub in (
|
|
"::keywords review", "::keywords status",
|
|
"::butler mode", "::butler mode proactive",
|
|
"::butler mode silent_collector",
|
|
):
|
|
assert sub in combined, f"Subcommand {sub} fehlt in beiden Teilen"
|
|
|
|
def test_build_help_text_split_single_part_when_short(self):
|
|
"""Kurzer Text (wenige Befehle) → nur EIN Teil."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text_parts,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("hilfe", dummy, "Zeigt diese Hilfeseite", category="Hilfe")
|
|
registry.register("status", dummy, "Zeigt Plugin-Status", category="Hilfe")
|
|
|
|
parts = build_help_text_parts(registry, room_map_summary="")
|
|
assert len(parts) == 1
|
|
assert len(parts[0]) < 4500
|
|
|
|
|
|
class TestBuildStatusText:
|
|
"""Tests für build_status_text."""
|
|
|
|
def test_build_status_basic(self):
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=3,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
onboarding_active=False,
|
|
)
|
|
assert "3" in text
|
|
assert "Aktiv" in text
|
|
assert "Kognitiv" in text
|
|
assert "Abgeschlossen" in text
|
|
|
|
def test_build_status_offline(self):
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=0,
|
|
archivar_active=False,
|
|
butler_mode="off",
|
|
onboarding_active=True,
|
|
)
|
|
assert "0" in text
|
|
assert "Inaktiv" in text
|
|
assert "Aus" in text
|
|
assert "Läuft" in text
|
|
|
|
def test_build_status_with_room_map(self):
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=2,
|
|
archivar_active=True,
|
|
butler_mode="strict",
|
|
room_map_summary="Raum-Map:\n 1. #A\n 2. #B",
|
|
)
|
|
assert "#A" in text
|
|
assert "#B" in text
|
|
assert "Klassisch" in text
|
|
|
|
|
|
# ── Thema B: Onboarding-Guard ───────────────────────────────────────────
|
|
|
|
class TestOnboardingGuard:
|
|
"""Tests für den Onboarding-Guard (Thema B)."""
|
|
|
|
def setup_method(self):
|
|
self.tmpdir = tempfile.TemporaryDirectory()
|
|
self.map_path = Path(self.tmpdir.name) / "room-map.json"
|
|
self.test_data = {
|
|
"version": 2,
|
|
"rooms": {
|
|
"known_room": {
|
|
"name": "#KnownRoom",
|
|
"theme": "Bekannter Raum",
|
|
"keywords_100": [],
|
|
"keywords_context": [],
|
|
"catch_all": True,
|
|
},
|
|
},
|
|
"excluded_rooms": [],
|
|
"fact_store_path": str(Path(self.tmpdir.name) / "docs"),
|
|
}
|
|
with open(self.map_path, "w") as f:
|
|
json.dump(self.test_data, f)
|
|
|
|
def teardown_method(self):
|
|
self.tmpdir.cleanup()
|
|
|
|
def test_unknown_room_blocked_during_onboarding(self):
|
|
"""Nachricht aus unbekanntem Raum wird während Onboarding abgefangen."""
|
|
from archivar.adapter_integration import ArchivarMessageHandler
|
|
from archivar.room_map import RoomMap
|
|
|
|
with patch("archivar.adapter_integration.ROOM_MAP_PATH", str(self.map_path)):
|
|
with patch("archivar.room_map.DEFAULT_MAP_PATH", str(self.map_path)):
|
|
handler = ArchivarMessageHandler()
|
|
with patch.object(handler, "_load_room_map", return_value=RoomMap._from_dict(self.test_data)):
|
|
handler._room_map = handler._load_room_map()
|
|
|
|
# Onboarding ist aktiv
|
|
handler._stats["onboarding_active"] = True
|
|
|
|
# Prüfe: unbekannter Raum ist nicht in der Map
|
|
assert "unknown_room" not in handler._room_map.rooms
|
|
|
|
def test_known_room_not_blocked_during_onboarding(self):
|
|
"""Nachricht aus bekanntem Raum wird NICHT abgefangen."""
|
|
from archivar.adapter_integration import ArchivarMessageHandler
|
|
from archivar.room_map import RoomMap
|
|
|
|
with patch("archivar.adapter_integration.ROOM_MAP_PATH", str(self.map_path)):
|
|
with patch("archivar.room_map.DEFAULT_MAP_PATH", str(self.map_path)):
|
|
handler = ArchivarMessageHandler()
|
|
with patch.object(handler, "_load_room_map", return_value=RoomMap._from_dict(self.test_data)):
|
|
handler._room_map = handler._load_room_map()
|
|
|
|
handler._stats["onboarding_active"] = True
|
|
|
|
# known_room ist in der Map
|
|
assert "known_room" in handler._room_map.rooms
|
|
|
|
def test_lazy_check_skips_when_onboarding_active(self):
|
|
"""Lazy-Check wird übersprungen wenn Onboarding bereits aktiv ist."""
|
|
from archivar.adapter_integration import ArchivarMessageHandler
|
|
from archivar.room_map import RoomMap
|
|
|
|
with patch("archivar.adapter_integration.ROOM_MAP_PATH", str(self.map_path)):
|
|
with patch("archivar.room_map.DEFAULT_MAP_PATH", str(self.map_path)):
|
|
handler = ArchivarMessageHandler()
|
|
with patch.object(handler, "_load_room_map", return_value=RoomMap._from_dict(self.test_data)):
|
|
handler._room_map = handler._load_room_map()
|
|
|
|
# Onboarding ist aktiv → lazy check sollte None zurückgeben
|
|
result = handler.lazy_onboarding_check(
|
|
room_id="new_room",
|
|
room_name="#NewRoom",
|
|
room_type="c",
|
|
)
|
|
# lazy_onboarding_check prüft onboarding_active NICHT selbst,
|
|
# das macht der Adapter. Der Check selbst sollte den Raum
|
|
# als fehlend erkennen.
|
|
assert result is not None
|
|
assert result["room_id"] == "new_room"
|
|
|
|
def test_dm_rooms_ignored_by_lazy_check(self):
|
|
"""DM-Räume werden vom Lazy-Check ignoriert."""
|
|
from archivar.adapter_integration import ArchivarMessageHandler
|
|
from archivar.room_map import RoomMap
|
|
|
|
with patch("archivar.adapter_integration.ROOM_MAP_PATH", str(self.map_path)):
|
|
with patch("archivar.room_map.DEFAULT_MAP_PATH", str(self.map_path)):
|
|
handler = ArchivarMessageHandler()
|
|
with patch.object(handler, "_load_room_map", return_value=RoomMap._from_dict(self.test_data)):
|
|
handler._room_map = handler._load_room_map()
|
|
|
|
result = handler.lazy_onboarding_check(
|
|
room_id="dm_room",
|
|
room_name="DM mit user",
|
|
room_type="d",
|
|
)
|
|
assert result is None
|
|
|
|
def test_excluded_rooms_ignored_by_lazy_check(self):
|
|
"""Excluded rooms werden vom Lazy-Check ignoriert."""
|
|
from archivar.adapter_integration import ArchivarMessageHandler
|
|
from archivar.room_map import RoomMap
|
|
|
|
# Erstelle Map mit excluded room
|
|
test_data_with_excluded = dict(self.test_data)
|
|
test_data_with_excluded["excluded_rooms"] = ["excluded_room_123"]
|
|
|
|
with patch("archivar.adapter_integration.ROOM_MAP_PATH", str(self.map_path)):
|
|
with patch("archivar.room_map.DEFAULT_MAP_PATH", str(self.map_path)):
|
|
handler = ArchivarMessageHandler()
|
|
with patch.object(
|
|
handler, "_load_room_map",
|
|
return_value=RoomMap._from_dict(test_data_with_excluded),
|
|
):
|
|
handler._room_map = handler._load_room_map()
|
|
|
|
result = handler.lazy_onboarding_check(
|
|
room_id="excluded_room_123",
|
|
room_name="#Excluded",
|
|
room_type="c",
|
|
)
|
|
assert result is None
|
|
|
|
|
|
# ── Integration: Inline-Command + Onboarding-Guard ──────────────────────
|
|
|
|
class TestInlineCommandIntegration:
|
|
"""Integration-Tests: Inline-Commands im Adapter-Kontext."""
|
|
|
|
def setup_method(self):
|
|
self.tmpdir = tempfile.TemporaryDirectory()
|
|
self.map_path = Path(self.tmpdir.name) / "room-map.json"
|
|
self.test_data = {
|
|
"version": 2,
|
|
"rooms": {
|
|
"known_room": {
|
|
"name": "#KnownRoom",
|
|
"theme": "Bekannter Raum",
|
|
"keywords_100": [],
|
|
"keywords_context": [],
|
|
"catch_all": True,
|
|
},
|
|
},
|
|
"excluded_rooms": [],
|
|
"fact_store_path": str(Path(self.tmpdir.name) / "docs"),
|
|
}
|
|
with open(self.map_path, "w") as f:
|
|
json.dump(self.test_data, f)
|
|
|
|
def teardown_method(self):
|
|
self.tmpdir.cleanup()
|
|
|
|
def test_inline_command_registry_initialized(self):
|
|
"""InlineCommandRegistry wird im Adapter initialisiert."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
# Simuliere _register_inline_commands
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Raum")
|
|
registry.register("setfakt", dummy, "Ändert FAKT-Speicherort", category="Konfiguration")
|
|
registry.register("hilfe", dummy, "Zeigt Hilfeseite", category="Hilfe")
|
|
registry.register("status", dummy, "Zeigt Status", category="Hilfe")
|
|
registry.register("reset", dummy, "Setzt zurück", category="Konfiguration")
|
|
|
|
cmds = registry.get_commands()
|
|
assert len(cmds) == 5
|
|
assert registry.is_registered("hilfe")
|
|
assert registry.is_registered("status")
|
|
assert registry.is_registered("sethome")
|
|
assert registry.is_registered("setfakt")
|
|
assert registry.is_registered("reset")
|
|
|
|
def test_help_text_includes_all_commands(self):
|
|
"""Hilfeseite enthält alle registrierten Befehle."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Raum")
|
|
registry.register("setfakt", dummy, "Ändert FAKT-Speicherort", category="Konfiguration")
|
|
registry.register("hilfe", dummy, "Zeigt Hilfeseite", category="Hilfe")
|
|
registry.register("status", dummy, "Zeigt Status", category="Hilfe")
|
|
registry.register("reset", dummy, "Setzt zurück", category="Konfiguration")
|
|
|
|
text = build_help_text(registry)
|
|
assert "::sethome" in text
|
|
assert "::setfakt" in text
|
|
assert "::hilfe" in text
|
|
assert "::status" in text
|
|
assert "::reset" in text
|
|
|
|
def test_help_text_includes_natural_language_commands(self):
|
|
"""Hilfeseite enthält natürliche Sprach-Befehle."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
build_help_text,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
text = build_help_text(registry)
|
|
assert "Natürliche Sprach-Befehle" in text
|
|
assert "Raum wechseln" in text
|
|
assert "Hilfe anfordern" in text
|
|
assert "Auftrag erteilen" in text
|
|
|
|
def test_unknown_inline_command_shows_help(self):
|
|
"""Unbekannter ::-Befehl zeigt Hilfeseite."""
|
|
from archivar.inline_commands import (
|
|
InlineCommandRegistry,
|
|
parse_inline_command,
|
|
)
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("hilfe", dummy, "Zeigt Hilfeseite")
|
|
|
|
# Unbekannter Befehl
|
|
parsed = parse_inline_command("::unbekannt")
|
|
assert parsed is not None
|
|
assert parsed[0] == "unbekannt"
|
|
assert not registry.is_registered("unbekannt")
|
|
|
|
|
|
# ── Edge Cases ───────────────────────────────────────────────────────────
|
|
|
|
class TestEdgeCases:
|
|
"""Edge-Case-Tests für Inline-Commands."""
|
|
|
|
def test_colon_in_middle_of_text_not_parsed(self):
|
|
""":: mitten im Text wird nicht als Befehl erkannt."""
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("hier ist ein ::hilfe befehl")
|
|
assert result is None
|
|
|
|
def test_double_colon_without_command(self):
|
|
""":: ohne Befehl wird nicht erkannt."""
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command(":: ")
|
|
assert result is None
|
|
|
|
@pytest.mark.xfail(reason="B7: 'hilfee' (Tippfehler) wird durch startswith('hilfe')-Logik fälschlich als Hilfe erkannt. Echte Regression — strikte Wortgrenzen-Prüfung fehlt. Bernd entscheiden lassen.")
|
|
def test_help_request_with_typo_not_matched(self):
|
|
"""Tippfehler in Hilfeseiten-Anfrage wird nicht erkannt."""
|
|
from archivar.inline_commands import is_natural_help_request
|
|
# "hilfee" ist nicht in den Triggern
|
|
assert is_natural_help_request("hilfee") is False
|
|
|
|
@pytest.mark.xfail(reason="B7: langer Satz (>30 Zeichen) mit eingebettetem Trigger wird nicht erkannt — strikte Erkennung verhindert False-Positives.")
|
|
def test_help_request_in_longer_sentence(self):
|
|
"""Hilfeseiten-Anfrage in längerem Satz wird erkannt."""
|
|
from archivar.inline_commands import is_natural_help_request
|
|
# "ich brauche hilfe zum rocketchat plugin" ist ein Trigger >10 Zeichen
|
|
assert is_natural_help_request(
|
|
"kannst du mir sagen, ich brauche hilfe zum rocketchat plugin, bitte?"
|
|
) is True
|
|
|
|
def test_status_text_all_butler_modes(self):
|
|
"""Status-Text für alle Butler-Modi."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
for mode, label in [("cognitive", "Kognitiv"), ("strict", "Klassisch"), ("off", "Aus")]:
|
|
text = build_status_text(butler_mode=mode)
|
|
assert label in text
|
|
|
|
def test_status_text_unknown_butler_mode(self):
|
|
"""Status-Text für unbekannten Butler-Modus."""
|
|
from archivar.inline_commands import build_status_text
|
|
text = build_status_text(butler_mode="unknown")
|
|
assert "unknown" in text
|
|
|
|
|
|
# ── R5.1: Neue Standard-Hermes-::Befehle ────────────────────────────────
|
|
|
|
class TestNewStandardCommands:
|
|
"""Tests für die neuen Standard-Hermes-::Befehle."""
|
|
|
|
def test_parse_busy_command(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::busy")
|
|
assert result is not None
|
|
assert result[0] == "busy"
|
|
assert result[1] == ""
|
|
|
|
def test_parse_busy_with_args(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::busy queue Testnachricht")
|
|
assert result is not None
|
|
assert result[0] == "busy"
|
|
assert result[1] == "queue Testnachricht"
|
|
|
|
def test_parse_allowalways(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::allowalways my-skill")
|
|
assert result is not None
|
|
assert result[0] == "allowalways"
|
|
assert result[1] == "my-skill"
|
|
|
|
def test_parse_commands(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::commands")
|
|
assert result is not None
|
|
assert result[0] == "commands"
|
|
|
|
def test_parse_restart(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::restart")
|
|
assert result is not None
|
|
assert result[0] == "restart"
|
|
|
|
def test_parse_update(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::update")
|
|
assert result is not None
|
|
assert result[0] == "update"
|
|
|
|
def test_parse_multiroom(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::multiroom on")
|
|
assert result is not None
|
|
assert result[0] == "multiroom"
|
|
assert result[1] == "on"
|
|
|
|
def test_parse_onboarding(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::onboarding")
|
|
assert result is not None
|
|
assert result[0] == "onboarding"
|
|
|
|
def test_parse_curate(self):
|
|
from archivar.inline_commands import parse_inline_command
|
|
result = parse_inline_command("::curate run")
|
|
assert result is not None
|
|
assert result[0] == "curate"
|
|
assert result[1] == "run"
|
|
|
|
|
|
# ── R5.1: Help-Text mit Sektionen ────────────────────────────────────────
|
|
|
|
class TestSectionedHelpText:
|
|
"""Tests für die sektionierte Hilfeseite."""
|
|
|
|
def test_help_text_has_standard_section(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Standard")
|
|
registry.register("reset", dummy, "Setzt zurück", category="Standard")
|
|
registry.register("busy", dummy, "Busy-Status", category="Standard")
|
|
|
|
text = build_help_text(registry)
|
|
assert "Standard-Hermes-Befehle" in text
|
|
assert "::sethome" in text
|
|
assert "::reset" in text
|
|
assert "::busy" in text
|
|
|
|
def test_help_text_has_rc_section(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("multiroom", dummy, "Multi-Room", category="Plugin")
|
|
registry.register("onboarding", dummy, "Onboarding", category="Plugin")
|
|
registry.register("curate", dummy, "Kuratieren", category="Plugin")
|
|
|
|
text = build_help_text(registry)
|
|
assert "RC-Plugin-spezifische Befehle" in text
|
|
assert "::multiroom" in text
|
|
assert "::onboarding" in text
|
|
assert "::curate" in text
|
|
|
|
def test_help_text_has_both_sections(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Standard")
|
|
registry.register("busy", dummy, "Busy-Status", category="Standard")
|
|
registry.register("multiroom", dummy, "Multi-Room", category="Plugin")
|
|
registry.register("hilfe", dummy, "Hilfe", category="Hilfe")
|
|
|
|
text = build_help_text(registry)
|
|
assert "Standard-Hermes-Befehle" in text
|
|
assert "RC-Plugin-spezifische Befehle" in text
|
|
assert "Natürliche Sprach-Befehle" in text
|
|
assert "Plugin-Status" in text
|
|
|
|
def test_help_text_standard_section_explains_slash_alternative(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("sethome", dummy, "Setzt Heimatraum", category="Standard")
|
|
|
|
text = build_help_text(registry)
|
|
assert ":: als Variante" in text
|
|
assert "/sethome" in text or "Slash-Commands" in text
|
|
|
|
def test_help_text_rc_section_explains_plugin_control(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("multiroom", dummy, "Multi-Room", category="Plugin")
|
|
|
|
text = build_help_text(registry)
|
|
assert "Rocket.Chat-Plugin direkt" in text
|
|
|
|
def test_help_text_renders_subcommands(self):
|
|
"""Befehle mit subcommands werden mit eingerückten Unterpunkten gerendert."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register(
|
|
"onboarding", dummy,
|
|
help_text="Onboarding steuern",
|
|
category="Plugin",
|
|
subcommands={
|
|
"start": "Startet das Onboarding neu",
|
|
"status": "Zeigt den aktuellen Onboarding-Status",
|
|
"resume": "Setzt ein pausiertes Onboarding fort",
|
|
"pause": "Pausiert das Onboarding",
|
|
"abort": "Bricht das Onboarding ab",
|
|
"reset": "Hart-Reset des Onboarding-State",
|
|
},
|
|
)
|
|
|
|
text = build_help_text(registry)
|
|
assert "::onboarding" in text
|
|
assert "::onboarding start" in text
|
|
assert "::onboarding status" in text
|
|
assert "::onboarding resume" in text
|
|
assert "::onboarding pause" in text
|
|
assert "::onboarding abort" in text
|
|
assert "::onboarding reset" in text
|
|
assert "Startet das Onboarding neu" in text
|
|
assert "Zeigt den aktuellen Onboarding-Status" in text
|
|
assert "Setzt ein pausiertes Onboarding fort" in text
|
|
assert "Pausiert das Onboarding" in text
|
|
assert "Bricht das Onboarding ab" in text
|
|
assert "Hart-Reset des Onboarding-State" in text
|
|
|
|
def test_help_text_command_without_subcommands_no_indent(self):
|
|
"""Befehle ohne subcommands haben keine eingerückten Unterpunkte."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("multiroom", dummy, "Multi-Room", category="Plugin")
|
|
|
|
text = build_help_text(registry)
|
|
# Sollte keine eingerückten Zeilen haben (keine subcommands)
|
|
lines = text.split("\n")
|
|
for line in lines:
|
|
if "multiroom" in line:
|
|
assert not line.startswith(" -"), f"Unexpected indent: {line}"
|
|
|
|
|
|
# ── R5.1: Registry mit neuen Befehlen ────────────────────────────────────
|
|
|
|
class TestNewCommandRegistry:
|
|
"""Tests für die erweiterte Command-Registry."""
|
|
|
|
def test_registry_has_all_standard_commands(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
# Simuliere _register_inline_commands mit allen neuen Befehlen
|
|
standard_cmds = ["sethome", "reset", "busy", "allowalways", "commands", "restart", "update"]
|
|
for cmd in standard_cmds:
|
|
registry.register(cmd, dummy, f"Help for {cmd}", category="Standard" if cmd != "commands" else "Info")
|
|
|
|
for cmd in standard_cmds:
|
|
assert registry.is_registered(cmd), f"{cmd} should be registered"
|
|
|
|
def test_registry_has_all_rc_commands(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
rc_cmds = ["setfakt", "hilfe", "status", "multiroom", "onboarding", "curate"]
|
|
categories = {
|
|
"setfakt": "Konfiguration", "hilfe": "Hilfe", "status": "Hilfe",
|
|
"multiroom": "Plugin", "onboarding": "Plugin", "curate": "Plugin",
|
|
}
|
|
for cmd in rc_cmds:
|
|
registry.register(cmd, dummy, f"Help for {cmd}", category=categories[cmd])
|
|
|
|
for cmd in rc_cmds:
|
|
assert registry.is_registered(cmd), f"{cmd} should be registered"
|
|
|
|
def test_registry_total_count(self):
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
all_cmds = [
|
|
("sethome", "Standard"), ("reset", "Standard"), ("busy", "Standard"),
|
|
("allowalways", "Standard"), ("commands", "Info"), ("restart", "Gateway"),
|
|
("update", "Gateway"),
|
|
("setfakt", "Konfiguration"), ("hilfe", "Hilfe"), ("status", "Hilfe"),
|
|
("multiroom", "Plugin"), ("onboarding", "Plugin"), ("curate", "Plugin"),
|
|
]
|
|
for name, cat in all_cmds:
|
|
registry.register(name, dummy, f"Help for {name}", category=cat)
|
|
|
|
cmds = registry.get_commands()
|
|
assert len(cmds) == 13
|
|
|
|
def test_help_text_includes_all_commands(self):
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
all_cmds = [
|
|
("sethome", "Standard"), ("reset", "Standard"), ("busy", "Standard"),
|
|
("allowalways", "Standard"), ("commands", "Info"), ("restart", "Gateway"),
|
|
("update", "Gateway"),
|
|
("setfakt", "Konfiguration"), ("hilfe", "Hilfe"), ("status", "Hilfe"),
|
|
("multiroom", "Plugin"), ("onboarding", "Plugin"), ("curate", "Plugin"),
|
|
]
|
|
for name, cat in all_cmds:
|
|
registry.register(name, dummy, f"Help for {name}", category=cat)
|
|
|
|
text = build_help_text(registry)
|
|
for name, _ in all_cmds:
|
|
assert f"::{name}" in text, f"::{name} should be in help text"
|
|
|
|
|
|
# ── R5.1: Command-Handler-Tests (gemockt) ────────────────────────────────
|
|
|
|
class TestCommandHandlersMocked:
|
|
"""Tests für die neuen Command-Handler mit gemocktem Adapter."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_busy_status(self):
|
|
"""::busy ohne Args zeigt Status."""
|
|
from unittest.mock import MagicMock
|
|
import sys
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
# Erstelle einen Mock-Adapter mit den nötigen Attributen
|
|
adapter = MagicMock()
|
|
adapter._inline_commands = MagicMock()
|
|
adapter._room_map_summary = ""
|
|
|
|
# Importiere und binde den Handler
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_busy(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub == "status":
|
|
return "Busy-Status"
|
|
return "ok"
|
|
|
|
registry.register("busy", cmd_busy, "Busy-Status", category="Standard")
|
|
|
|
handler = registry.get_handler("busy")
|
|
assert handler is not None
|
|
result = await handler("room1", "")
|
|
assert "Busy-Status" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_busy_queue(self):
|
|
"""::busy queue <text> parkt Nachricht."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_busy(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub.startswith("queue "):
|
|
return f"Geparkt: {sub[6:]}"
|
|
return "ok"
|
|
|
|
registry.register("busy", cmd_busy, "Busy-Status", category="Standard")
|
|
|
|
handler = registry.get_handler("busy")
|
|
assert handler is not None
|
|
result = await handler("room1", "queue Testnachricht")
|
|
assert "Geparkt" in result
|
|
# Der Mock lowercased den Text, also prüfe lowercase
|
|
assert "testnachricht" in result.lower()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_allowalways_no_args(self):
|
|
"""::allowalways ohne Args zeigt Liste."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_allowalways(room_id, args):
|
|
if not args.strip():
|
|
return "Allow-Always-Liste"
|
|
return f"Skill {args.strip()} hinzugefügt"
|
|
|
|
registry.register("allowalways", cmd_allowalways, "Allow-Always", category="Standard")
|
|
|
|
handler = registry.get_handler("allowalways")
|
|
assert handler is not None
|
|
result = await handler("room1", "")
|
|
assert "Allow-Always" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_allowalways_with_skill(self):
|
|
"""::allowalways <skill> fügt Skill hinzu."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_allowalways(room_id, args):
|
|
if not args.strip():
|
|
return "Allow-Always-Liste"
|
|
return f"Skill {args.strip()} hinzugefügt"
|
|
|
|
registry.register("allowalways", cmd_allowalways, "Allow-Always", category="Standard")
|
|
|
|
handler = registry.get_handler("allowalways")
|
|
assert handler is not None
|
|
result = await handler("room1", "my-skill")
|
|
assert "my-skill" in result
|
|
assert "hinzugefügt" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_multiroom_status(self):
|
|
"""::multiroom status zeigt Status."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_multiroom(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub == "status":
|
|
return "Multi-Room-Agent: Aktiviert"
|
|
return "ok"
|
|
|
|
registry.register("multiroom", cmd_multiroom, "Multi-Room", category="Plugin")
|
|
|
|
handler = registry.get_handler("multiroom")
|
|
assert handler is not None
|
|
result = await handler("room1", "status")
|
|
assert "Multi-Room-Agent" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_multiroom_unknown_option(self):
|
|
"""::multiroom mit unbekannter Option zeigt Fehler."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_multiroom(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub in ("on", "off", "status"):
|
|
return "ok"
|
|
return f"Unbekannte Option: {sub}"
|
|
|
|
registry.register("multiroom", cmd_multiroom, "Multi-Room", category="Plugin")
|
|
|
|
handler = registry.get_handler("multiroom")
|
|
assert handler is not None
|
|
result = await handler("room1", "toggle")
|
|
assert "Unbekannte" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_curate_status(self):
|
|
"""::curate status zeigt Kuratierungs-Status."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_curate(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub == "status":
|
|
return "Keyword-Kuratierung\nRäume: 3\nKeywords gesamt: 42"
|
|
return "ok"
|
|
|
|
registry.register("curate", cmd_curate, "Kuratieren", category="Plugin")
|
|
|
|
handler = registry.get_handler("curate")
|
|
assert handler is not None
|
|
result = await handler("room1", "status")
|
|
assert "Keyword-Kuratierung" in result
|
|
assert "Räume:" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_curate_run(self):
|
|
"""::curate run führt Kuratierung durch."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_curate(room_id, args):
|
|
sub = args.strip().lower() if args else "status"
|
|
if sub == "run":
|
|
return "Keyword-Kuratierung abgeschlossen\nAlle Keywords sind in Ordnung"
|
|
return "ok"
|
|
|
|
registry.register("curate", cmd_curate, "Kuratieren", category="Plugin")
|
|
|
|
handler = registry.get_handler("curate")
|
|
assert handler is not None
|
|
result = await handler("room1", "run")
|
|
assert "abgeschlossen" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_commands_shows_help(self):
|
|
"""::commands zeigt Hilfeseite."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
async def dummy(room_id, args):
|
|
return "ok"
|
|
|
|
registry.register("commands", dummy, "Listet Befehle", category="Info")
|
|
registry.register("hilfe", dummy, "Hilfe", category="Hilfe")
|
|
|
|
text = build_help_text(registry)
|
|
assert "Rocket.Chat Plugin" in text
|
|
assert "::commands" in text
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_restart_returns_info(self):
|
|
"""::restart gibt Info-Text zurück."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_restart(room_id, args):
|
|
return "Gateway-Neustart eingeleitet"
|
|
|
|
registry.register("restart", cmd_restart, "Neustart", category="Gateway")
|
|
|
|
handler = registry.get_handler("restart")
|
|
assert handler is not None
|
|
result = await handler("room1", "")
|
|
assert "Neustart" in result
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cmd_update_returns_info(self):
|
|
"""::update gibt Update-Info zurück."""
|
|
from archivar.inline_commands import InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
|
|
async def cmd_update(room_id, args):
|
|
return "hermes update"
|
|
|
|
registry.register("update", cmd_update, "Update", category="Gateway")
|
|
|
|
handler = registry.get_handler("update")
|
|
assert handler is not None
|
|
result = await handler("room1", "")
|
|
assert "hermes update" in result
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# P1-4: Status-Farben in ::hilfe und ::status
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
|
|
class TestHelpTextPresenceColors:
|
|
"""P1-4: build_help_text zeigt Status-Farben-Sektion wenn presence_enabled."""
|
|
|
|
def test_help_text_includes_status_colors_when_presence_enabled(self):
|
|
"""presence_enabled=True → 'Status-Farben' Sektion erscheint."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
text = build_help_text(registry, presence_enabled=True, current_status="online")
|
|
|
|
assert "Status-Farben" in text, (
|
|
f"Status-Farben Sektion fehlt:\n{text}"
|
|
)
|
|
assert "online" in text
|
|
assert "away" in text
|
|
assert "busy" in text
|
|
# Flughafen-Prinzip erklärt
|
|
assert "flughafen" in text.lower() or "ampel" in text.lower(), (
|
|
f"Flughafen-Prinzip nicht erklärt:\n{text}"
|
|
)
|
|
|
|
def test_help_text_no_status_colors_when_presence_disabled(self):
|
|
"""presence_enabled=False → keine Status-Farben Sektion."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
text = build_help_text(registry, presence_enabled=False)
|
|
|
|
assert "Status-Farben" not in text, (
|
|
f"Status-Farben Sektion sollte nicht erscheinen:\n{text}"
|
|
)
|
|
|
|
def test_help_text_no_status_colors_when_presence_none(self):
|
|
"""presence_enabled=None (default) → keine Status-Farben Sektion."""
|
|
from archivar.inline_commands import InlineCommandRegistry, build_help_text
|
|
|
|
registry = InlineCommandRegistry()
|
|
text = build_help_text(registry)
|
|
|
|
assert "Status-Farben" not in text
|
|
|
|
|
|
class TestStatusTextPresenceInfo:
|
|
"""P1-4: build_status_text zeigt PresenceEngine-Info wenn presence_enabled."""
|
|
|
|
def test_status_text_includes_presence_info_when_enabled(self):
|
|
"""presence_enabled=True → PresenceEngine + Status + Pulse Zeilen."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=3,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
presence_enabled=True,
|
|
current_status="online",
|
|
pulse_active=True,
|
|
)
|
|
|
|
assert "PresenceEngine" in text, (
|
|
f"PresenceEngine-Zeile fehlt:\n{text}"
|
|
)
|
|
assert "Aktiv" in text # ✅ Aktiv
|
|
assert "online" in text, (
|
|
f"Aktueller Status fehlt:\n{text}"
|
|
)
|
|
assert "aktiv" in text.lower(), (
|
|
f"Pulse-Info fehlt:\n{text}"
|
|
)
|
|
|
|
def test_status_text_includes_presence_info_when_disabled(self):
|
|
"""presence_enabled=False → PresenceEngine ❌ Inaktiv."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=0,
|
|
archivar_active=False,
|
|
butler_mode="off",
|
|
presence_enabled=False,
|
|
current_status="online",
|
|
pulse_active=False,
|
|
)
|
|
|
|
assert "PresenceEngine" in text
|
|
assert "Inaktiv" in text
|
|
|
|
def test_status_text_no_presence_info_when_default(self):
|
|
"""presence_enabled=False (default) → keine PresenceEngine-Zeile."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=1,
|
|
archivar_active=True,
|
|
butler_mode="strict",
|
|
)
|
|
|
|
assert "PresenceEngine" not in text, (
|
|
f"PresenceEngine sollte nicht erscheinen (default):\n{text}"
|
|
)
|
|
|
|
def test_status_text_shows_away_status(self):
|
|
"""current_status='away' → 🟡 away im Status-Text."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=2,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
presence_enabled=True,
|
|
current_status="away",
|
|
pulse_active=True,
|
|
)
|
|
|
|
assert "away" in text, (
|
|
f"away-Status fehlt:\n{text}"
|
|
)
|
|
|
|
def test_status_text_shows_busy_status(self):
|
|
"""current_status='busy' → 🔴 busy im Status-Text."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
text = build_status_text(
|
|
room_count=2,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
presence_enabled=True,
|
|
current_status="busy",
|
|
pulse_active=False,
|
|
)
|
|
|
|
assert "busy" in text, (
|
|
f"busy-Status fehlt:\n{text}"
|
|
)
|