P1-Fix: build_help_text Längenbegrenzung + RoomMap.save Refuse-Guard
- build_help_text: Wenn Hilfe-Text > 4000 Zeichen, wird room_map_summary durch Platzhalter ersetzt. Verhindert HTTP 400 bei Rocket.Chat (Payload-Limit ~5000 Zeichen, ::hilfe mit 5 Räumen war 4571 Zeichen). - RoomMap.save: Refuse-Guard prüft vor dem Schreiben, ob die existierende Disk-Datei mehr Räume enthält als die In-Memory-Map. Verweigert das Schreiben mit Warning wenn Disk > In-Memory. Verhindert Datenverlust beim Multiroom-Toggle (false→true schrieb leere Map). - Tests: test_build_help_text_length_limit (max 4000 Zeichen), test_build_help_text_keeps_summary_when_short, TestRoomMapSaveRefuseGuard (4 Tests: refuse, allow-more, allow-equal, allow-no-disk). Closes: Rainers Review P1-Fixes 1+2+3
This commit is contained in:
@@ -262,6 +262,61 @@ class TestBuildHelpText:
|
||||
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
|
||||
|
||||
|
||||
class TestBuildStatusText:
|
||||
"""Tests für build_status_text."""
|
||||
|
||||
Reference in New Issue
Block a user