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
+18
View File
@@ -370,6 +370,15 @@ def check_room_map_completeness(
# nicht in der Map ist → automatisch als catch_all eintragen
if len(relevant_rooms) == 1:
single_room_id = list(relevant_rooms.keys())[0]
# P-086: Ein excluded Raum darf NICHT via Single-Room-Regel als
# catch_all auto-assigned werden — er ist bewusst ausgeklammert.
if room_map.is_excluded(single_room_id):
logger.info(
"check_room_map_completeness: Einziger Raum '%s' ist excluded "
"— kein Auto-Assign, kein Onboarding-Trigger",
relevant_rooms[single_room_id].get("name", single_room_id),
)
return []
if single_room_id not in room_map.rooms:
global _single_room_catch_all_overwrite_attempted
_single_room_catch_all_overwrite_attempted += 1
@@ -490,6 +499,15 @@ def check_room_map_completeness(
room_info.get("name", room_id),
)
continue
# P-086: excluded_rooms berücksichtigen — ein excluded Raum ist
# NICHT missing (kein Onboarding-Trigger, kein B9-Reconnect-Loop).
if room_map.is_excluded(room_id):
logger.info(
"check_room_map_completeness: Raum '%s' ist excluded "
"— kein Onboarding-Trigger",
room_info.get("name", room_id),
)
continue
if room_id not in room_map.rooms:
missing.append({"room_id": room_id, "name": room_info["name"]})
+17
View File
@@ -1028,6 +1028,23 @@ class RoomMap:
self._excluded_room_ids.add(room_id)
self._version += 1
def add_excluded_room(self, room_id: str) -> None:
"""Fügt eine room_id zu excluded_room_ids hinzu (idempotent).
P-086: Wird vom Onboarding-'Überspringen'-Flow genutzt, um einen
übersprungenen Raum dauerhaft auszuklammern (überlebt Gateway-Restart).
Im Gegensatz zu ``remove_room`` wird KEIN Eintrag in ``rooms{}``
vorausgesetzt — der Raum kann (und wird typischerweise) noch gar nicht
in der Map existieren.
Args:
room_id: Die Raum-ID.
"""
if room_id in self._excluded_room_ids:
return
self._excluded_room_ids.add(room_id)
self._version += 1
def increment_stay_count(self, room_id: str, keyword: str) -> int:
"""Inkrementiert den stay-Count für ein Keyword.
@@ -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