P-086: Onboarding respektiert excluded_rooms + Überspringen persistiert

Fix 1 (archivar/onboarding.py):
- check_room_map_completeness() prüft zusätzlich room_map.is_excluded(room_id)
  im missing-Loop → excluded Räume werden nicht mehr als missing gemeldet.
- Single-Room-Regel: excluded Raum wird nicht mehr als catch_all auto-assigned.

Fix 2 (adapter.py):
- _persist_excluded_rooms() Helper persistiert room_ids in room-map.json
  → excluded_rooms (idempotent, save+reload).
- 'Überspringen' (Einzelraum) und 'Alle überspringen' rufen den Helper auf,
  sodass der Entscheid einen Gateway-Restart überlebt (kein B9-Re-Trigger).

RoomMap (archivar/room_map.py):
- add_excluded_room() Methode (idempotent, kein rooms{}-Eintrag nötig).

Tests: test_p086_excluded_rooms.py (6 neue Tests).
This commit is contained in:
Bernd (Hermes)
2026-08-21 19:48:20 +02:00
parent c13e6efff7
commit 5720b48883
4 changed files with 234 additions and 0 deletions
@@ -0,0 +1,151 @@
"""Tests für P-086 — Onboarding überspringt excluded_rooms nicht.
Prüft:
1. check_room_map_completeness() meldet excluded Räume NICHT als missing.
2. RoomMap.add_excluded_room() ist idempotent und persistiert via save/reload.
3. Bestehende excluded_rooms werden respektiert (kein Onboarding-Trigger).
"""
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
from plugin.archivar.onboarding import check_room_map_completeness
# ── Helpers ────────────────────────────────────────────────────────────────
def _room(room_id: str, name: str, **kwargs) -> dict:
d = {
"room_id": room_id,
"name": name,
"theme": name,
"keywords_100": [],
"keywords_context": [],
"catch_all": False,
}
d.update(kwargs)
return d
def _make_map(rooms: list[dict], excluded: list[str] | None = None) -> RoomMap:
data: dict = {
"version": 2,
"rooms": {},
"excluded_rooms": excluded or [],
"fact_store_path": "/tmp/test_docs",
}
for room in rooms:
rid = room.pop("room_id")
data["rooms"][rid] = room
return RoomMap._from_dict(data)
# ── Tests ─────────────────────────────────────────────────────────────────
class TestExcludedRoomsNotMissing:
"""check_room_map_completeness() ignoriert excluded Räume."""
def test_excluded_room_not_reported_missing(self):
"""Ein excluded Raum wird NICHT als missing gemeldet."""
room_map = _make_map(
[
_room("r_catchall", "#CatchAll", catch_all=True),
],
excluded=["r_excluded"],
)
subscribed = {
"r_excluded": {"name": "#Excluded", "type": "c"},
"r_new": {"name": "#NeuerRaum", "type": "c"},
}
missing = check_room_map_completeness(
room_map=room_map,
subscribed_rooms=subscribed,
map_path="/tmp/test_map.json",
)
missing_ids = [m["room_id"] for m in missing]
assert "r_excluded" not in missing_ids
assert "r_new" in missing_ids
def test_excluded_room_not_in_map_still_ignored(self):
"""Excluded Raum, der gar nicht in rooms{} steht, wird ignoriert."""
room_map = _make_map(
[_room("r_catchall", "#CatchAll", catch_all=True)],
excluded=["r_ghost"],
)
subscribed = {
"r_ghost": {"name": "#Ghost", "type": "c"},
}
missing = check_room_map_completeness(
room_map=room_map,
subscribed_rooms=subscribed,
map_path="/tmp/test_map.json",
)
assert missing == []
def test_existing_excluded_rooms_respected(self):
"""Mehrere bestehende excluded_rooms werden alle respektiert."""
room_map = _make_map(
[_room("r_catchall", "#CatchAll", catch_all=True)],
excluded=["r_ex1", "r_ex2", "r_ex3"],
)
subscribed = {
"r_ex1": {"name": "#Ex1", "type": "c"},
"r_ex2": {"name": "#Ex2", "type": "c"},
"r_ex3": {"name": "#Ex3", "type": "c"},
"r_new": {"name": "#Neu", "type": "c"},
}
missing = check_room_map_completeness(
room_map=room_map,
subscribed_rooms=subscribed,
map_path="/tmp/test_map.json",
)
missing_ids = [m["room_id"] for m in missing]
assert missing_ids == ["r_new"]
class TestAddExcludedRoom:
"""RoomMap.add_excluded_room() — idempotent + persistierbar."""
def test_add_excluded_room_idempotent(self):
"""Doppeltes Hinzufügen erzeugt keinen Duplikat-Eintrag."""
room_map = _make_map([_room("r_catchall", "#CatchAll", catch_all=True)])
room_map.add_excluded_room("r_skip")
room_map.add_excluded_room("r_skip")
assert room_map.is_excluded("r_skip") is True
assert len(room_map.excluded_room_ids) == 1
def test_add_excluded_room_persists_through_save_reload(self):
"""add_excluded_room + save + reload überlebt (Gateway-Restart-Simulation)."""
tmp = tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False, encoding="utf-8"
)
tmp_path = Path(tmp.name)
tmp.close()
room_map = _make_map([_room("r_catchall", "#CatchAll", catch_all=True)])
room_map.add_excluded_room("r_skip")
RoomMap.save(room_map, tmp_path)
# Reload aus Disk — simuliert Gateway-Restart
reloaded = RoomMap.load(tmp_path)
assert reloaded.is_excluded("r_skip") is True
tmp_path.unlink(missing_ok=True)
def test_add_excluded_room_does_not_require_room_entry(self):
"""add_excluded_room funktioniert ohne Eintrag in rooms{}."""
room_map = _make_map([_room("r_catchall", "#CatchAll", catch_all=True)])
room_map.add_excluded_room("r_never_onboarded")
assert room_map.is_excluded("r_never_onboarded") is True
assert "r_never_onboarded" not in room_map.rooms