Files
Hermes_rocket.chat_Plugin/plugin/archivar/tests/test_f549_boten_rooms.py
T
Bernd (Hermes) 3dcd024dd6 feat(F-549): boten_rooms Archivar-Bypass @implements: [F-549]
- room_map.py: boten_rooms-Feld (init/property/is_boten_room/parse/serialize/reload)
- room-map.schema.json: boten_rooms Schema
- templates/room-map.json: boten_rooms Default
- adapter.py: _boten_room_ids (populate via _sync_room_map_with_membership) + Archivar-Bypass (kein FAISS/Theme/Butler), Boten-Räume werden weiterhin subscribet/empfangen
- onboarding.py: boten_rooms kein Onboarding-Trigger (completeness/delta/lazy)
- test_f549_boten_rooms.py: 5 Tests (Round-Trip, is_boten_room, save, reload, Kompatibilität)
- STATUS.md aktualisiert
2026-09-19 14:18:57 +02:00

108 lines
3.5 KiB
Python

# @implements: [F-549] — boten_rooms: Round-Trip + is_boten_room + save/serialize
"""Tests für das F-549 boten_rooms-Feld im RoomMap-Datenmodell.
Prüft:
- Laden aus room-map.json (boten_rooms wird geparst)
- boten_room_ids-Property
- is_boten_room()
- save() serialisiert boten_rooms
- Abwärtskompatibilität (ohne boten_rooms-Feld → leer)
"""
from __future__ import annotations
import json
import sys
import tempfile
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
from plugin.archivar.room_map import RoomMap, RoomEntry
def _make_room(room_id: str, name: str, catch_all: bool = False) -> dict:
return {
"room_id": room_id,
"name": name,
"theme": "test",
"description": "test description long enough",
"keywords_100": [],
"keywords_context": [],
"catch_all": catch_all,
}
def _make_map_json(excluded: list[str] | None = None, boten: list[str] | None = None) -> str:
data: dict = {
"version": 1,
"rooms": {},
"excluded_rooms": excluded or [],
"fact_store_path": "/tmp/test_docs",
}
if boten is not None:
data["boten_rooms"] = boten
# Genau ein Catch-All-Raum (validate() erfordert das; load() ruft kein
# validate() auf, aber wir halten die Struktur gültig).
data["rooms"] = {
"catch": _make_room("catch", "Catch-All", catch_all=True),
"proj": _make_room("proj", "#Projekt"),
}
return json.dumps(data)
def _tmp_map(content: str) -> Path:
tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False, encoding="utf-8")
tmp.write(content)
tmp.close()
return Path(tmp.name)
def test_load_parses_boten_rooms():
"""boten_rooms wird aus room-map.json geparst."""
path = _tmp_map(_make_map_json(excluded=["excl1"], boten=["boten1", "boten2"]))
rm = RoomMap.load(path)
assert rm.boten_room_ids == {"boten1", "boten2"}
assert rm.is_boten_room("boten1") is True
assert rm.is_boten_room("proj") is False
assert rm.excluded_room_ids == {"excl1"}
def test_load_without_boten_rooms_field_is_empty():
"""Abwärtskompatibilität: ohne boten_rooms-Feld → leeres Set."""
path = _tmp_map(_make_map_json(excluded=["excl1"], boten=None))
rm = RoomMap.load(path)
assert rm.boten_room_ids == set()
assert rm.is_boten_room("irgendwas") is False
def test_boten_room_is_not_excluded():
"""Ein Boten-Raum ist NICHT excluded — getrennte Mengen."""
path = _tmp_map(_make_map_json(excluded=["excl1"], boten=["boten1"]))
rm = RoomMap.load(path)
assert rm.is_boten_room("boten1") is True
assert rm.is_excluded("boten1") is False
assert rm.is_boten_room("excl1") is False
def test_save_serializes_boten_rooms():
"""save() persistiert boten_rooms in die JSON."""
path = _tmp_map(_make_map_json(boten=["boten1"]))
rm = RoomMap.load(path)
RoomMap.save(rm, path)
reloaded = json.loads(path.read_text(encoding="utf-8"))
assert "boten_rooms" in reloaded
assert set(reloaded["boten_rooms"]) == {"boten1"}
def test_reload_preserves_boten_rooms():
"""reload() übernimmt boten_rooms aus der neu gelesenen Datei."""
path = _tmp_map(_make_map_json(boten=["boten1", "boten2"]))
rm = RoomMap.load(path)
# Datei ändern: boten_rooms auf einen Eintrag reduzieren.
path.write_text(_make_map_json(boten=["boten1"]), encoding="utf-8")
rm.reload(path)
assert rm.boten_room_ids == {"boten1"}