Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dff524d3e7 | |||
| d36ac73212 |
+5
-7
@@ -520,9 +520,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
else:
|
else:
|
||||||
self.archivar = None
|
self.archivar = None
|
||||||
self._conversation_history = None
|
self._conversation_history = None
|
||||||
# User-Flow C: Move-Requests + Sticky Rooms
|
# User-Flow C: Move-Requests
|
||||||
self._pending_move_requests: Dict[str, dict] = {}
|
self._pending_move_requests: Dict[str, dict] = {}
|
||||||
self._sticky_rooms: Dict[str, float] = {} # room_id → timestamp
|
# V7-2: _sticky_rooms removed — thematic never_route replaces spatial bypass.
|
||||||
|
# The router's _check_never_route_topic handles per-topic blocking now.
|
||||||
# Clarify state: maps clarify_id → session_key for gateway resolution
|
# Clarify state: maps clarify_id → session_key for gateway resolution
|
||||||
self._clarify_state: Dict[str, str] = {}
|
self._clarify_state: Dict[str, str] = {}
|
||||||
# Auto-Onboarding v2: structured interview state
|
# Auto-Onboarding v2: structured interview state
|
||||||
@@ -1312,7 +1313,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
elif choice in ("2", "2️⃣", "generell", "generell hier bleiben", "stay_here"):
|
elif choice in ("2", "2️⃣", "generell", "generell hier bleiben", "stay_here"):
|
||||||
# 2️⃣ Generell hier bleiben → Antwort im Ursprungsraum + Sticky-Eintrag
|
# 2️⃣ Generell hier bleiben → Antwort im Ursprungsraum + Sticky-Eintrag
|
||||||
# P0-B: Thematischer Sticky (v7) — Thema aus Match-Ergebnis extrahieren
|
# P0-B: Thematischer Sticky (v7) — Thema aus Match-Ergebnis extrahieren
|
||||||
self._sticky_rooms[room_id] = time.time()
|
# V7-2: _sticky_rooms entfernt — thematisches never_route ersetzt räumlichen Bypass
|
||||||
if _MULTIROOM() and self.archivar is not None:
|
if _MULTIROOM() and self.archivar is not None:
|
||||||
try:
|
try:
|
||||||
# Extrahiere Topic aus dem gematchten Raum-Namen
|
# Extrahiere Topic aus dem gematchten Raum-Namen
|
||||||
@@ -1350,7 +1351,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
topic = room_name_to_topic(target_name)
|
topic = room_name_to_topic(target_name)
|
||||||
if topic:
|
if topic:
|
||||||
self.archivar._state.set_never_route(room_id, topic)
|
self.archivar._state.set_never_route(room_id, topic)
|
||||||
self._sticky_rooms[room_id] = time.time()
|
# V7-2: _sticky_rooms entfernt — thematisches never_route reicht
|
||||||
logger.info("[rocketchat] Auto-promoted to never_route after %d stays in room %s, topic '%s'", count, room_id[:8], topic)
|
logger.info("[rocketchat] Auto-promoted to never_route after %d stays in room %s, topic '%s'", count, room_id[:8], topic)
|
||||||
await self._post_message_with_retry(room_id, "🔒 Ich habe gemerkt, dass du hier bleiben möchtest — dieser Raum wird ab jetzt nicht mehr automatisch geroutet.")
|
await self._post_message_with_retry(room_id, "🔒 Ich habe gemerkt, dass du hier bleiben möchtest — dieser Raum wird ab jetzt nicht mehr automatisch geroutet.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1418,9 +1419,6 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
logger.debug("[rocketchat] Room %s had pending question — Archivar bypassed", room_id)
|
logger.debug("[rocketchat] Room %s had pending question — Archivar bypassed", room_id)
|
||||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: Archivar bypassed — pending_questions")
|
logger.debug("[rocketchat] ARCHIVAR-DEBUG: Archivar bypassed — pending_questions")
|
||||||
self._rooms_with_pending_questions.discard(room_id)
|
self._rooms_with_pending_questions.discard(room_id)
|
||||||
elif room_id in self._sticky_rooms:
|
|
||||||
logger.debug("[rocketchat] Room %s is sticky — Archivar bypassed", room_id[:8])
|
|
||||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: Archivar bypassed — sticky_room=%s", room_id[:8])
|
|
||||||
elif self.archivar._state.should_stay_in_room(room_id) == "always":
|
elif self.archivar._state.should_stay_in_room(room_id) == "always":
|
||||||
# Bug 4 fix: Persistierte Entscheidung (always) aus ArchivarState lesen.
|
# Bug 4 fix: Persistierte Entscheidung (always) aus ArchivarState lesen.
|
||||||
# P0-B: "never_route" ist jetzt thematisch (v7) — wird im Router
|
# P0-B: "never_route" ist jetzt thematisch (v7) — wird im Router
|
||||||
|
|||||||
@@ -112,4 +112,146 @@ class TestRouterIntegration:
|
|||||||
# For this test, we're checking that the router can be instantiated and used
|
# For this test, we're checking that the router can be instantiated and used
|
||||||
# The actual routing logic is tested in room_map tests
|
# The actual routing logic is tested in room_map tests
|
||||||
assert router is not None
|
assert router is not None
|
||||||
assert router._room_map is not None
|
assert router._room_map is not None
|
||||||
|
|
||||||
|
|
||||||
|
# ── V7-2: Thematisches never_route ────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
class TestNeverRouteThematic:
|
||||||
|
"""V7-2: never_route ist thematisch, nicht räumlich.
|
||||||
|
|
||||||
|
Ein never_route für 'lan-dokumentation' blockt NICHT 'protonbridge'
|
||||||
|
im selben Raum. Der Butler darf bei einem anderen Thema wieder fragen.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def state(self) -> ArchivarState:
|
||||||
|
"""ArchivarState mit v7 never_route Schema."""
|
||||||
|
s = ArchivarState()
|
||||||
|
s._loaded = True # Skip file I/O
|
||||||
|
return s
|
||||||
|
|
||||||
|
def test_never_route_topic_blocks_same_topic(self, state):
|
||||||
|
"""never_route für 'lan-dokumentation' blockt 'lan-dokumentation'."""
|
||||||
|
room_id = "test_room_123"
|
||||||
|
state.set_never_route(room_id, "lan-dokumentation")
|
||||||
|
|
||||||
|
# Gleiches Thema → blockiert
|
||||||
|
assert state.is_never_route(room_id, "lan-dokumentation") is True
|
||||||
|
|
||||||
|
def test_never_route_topic_allows_different_topic(self, state):
|
||||||
|
"""never_route für 'lan-dokumentation' blockt NICHT 'protonbridge'."""
|
||||||
|
room_id = "test_room_123"
|
||||||
|
state.set_never_route(room_id, "lan-dokumentation")
|
||||||
|
|
||||||
|
# Anderes Thema → nicht blockiert
|
||||||
|
assert state.is_never_route(room_id, "protonbridge") is False
|
||||||
|
|
||||||
|
def test_never_route_topic_allows_unknown_topic(self, state):
|
||||||
|
"""never_route für 'lan-dokumentation' blockt NICHT None/leer."""
|
||||||
|
room_id = "test_room_123"
|
||||||
|
state.set_never_route(room_id, "lan-dokumentation")
|
||||||
|
|
||||||
|
# Kein Thema → nicht blockiert (Butler darf fragen)
|
||||||
|
assert state.is_never_route(room_id, None) is False
|
||||||
|
|
||||||
|
def test_never_route_multiple_topics_same_room(self, state):
|
||||||
|
"""Mehrere Themen im selben Raum: jedes unabhängig."""
|
||||||
|
room_id = "test_room_123"
|
||||||
|
state.set_never_route(room_id, "lan-dokumentation")
|
||||||
|
state.set_never_route(room_id, "devops")
|
||||||
|
|
||||||
|
# Beide gesetzten Themen blockiert
|
||||||
|
assert state.is_never_route(room_id, "lan-dokumentation") is True
|
||||||
|
assert state.is_never_route(room_id, "devops") is True
|
||||||
|
|
||||||
|
# Anderes Thema nicht blockiert
|
||||||
|
assert state.is_never_route(room_id, "protonbridge") is False
|
||||||
|
|
||||||
|
def test_never_route_different_room_not_affected(self, state):
|
||||||
|
"""never_route in Raum A betrifft Raum B nicht."""
|
||||||
|
state.set_never_route("room_a", "lan-dokumentation")
|
||||||
|
|
||||||
|
# Gleiches Thema in anderem Raum → nicht blockiert
|
||||||
|
assert state.is_never_route("room_b", "lan-dokumentation") is False
|
||||||
|
|
||||||
|
def test_router_check_never_route_topic_blocks_matched_room(self):
|
||||||
|
"""Router._check_never_route_topic blockt wenn Thema in never_route."""
|
||||||
|
json_str = _make_map_json(
|
||||||
|
rooms=[
|
||||||
|
{"room_id": "r_lan", "name": "#LAN-Dokumentation",
|
||||||
|
"theme": "lan docs", "keywords": ["lan", "dokumentation", "netzwerk"]},
|
||||||
|
{"room_id": "r_proton", "name": "#ProtonBridge",
|
||||||
|
"theme": "proton mail bridge", "keywords": ["protonbridge", "protonmail", "bridge"]},
|
||||||
|
{"room_id": "r_admin", "name": "DM Admin",
|
||||||
|
"theme": "admin", "keywords": [], "catch_all": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
path = _tmp_map(json_str)
|
||||||
|
try:
|
||||||
|
room_map = RoomMap.load(path)
|
||||||
|
state = ArchivarState()
|
||||||
|
state._loaded = True
|
||||||
|
|
||||||
|
# Setze never_route für 'lan-dokumentation' im Ursprungsraum
|
||||||
|
origin_room = "r_proton" # User ist im #ProtonBridge-Raum
|
||||||
|
state.set_never_route(origin_room, "lan-dokumentation")
|
||||||
|
|
||||||
|
router = BidirectionalRouter(room_map, None, state) # type: ignore
|
||||||
|
|
||||||
|
# Nachricht matcht #LAN-Dokumentation → sollte geblockt werden
|
||||||
|
lan_room = room_map.get_room_by_id("r_lan")
|
||||||
|
assert lan_room is not None
|
||||||
|
blocked = router._check_never_route_topic(origin_room, lan_room)
|
||||||
|
assert blocked is True, (
|
||||||
|
"never_route für 'lan-dokumentation' sollte LAN-Match blocken"
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
def test_router_check_never_route_topic_allows_other_topic(self):
|
||||||
|
"""Router._check_never_route_topic erlaubt anderes Thema im selben Raum."""
|
||||||
|
json_str = _make_map_json(
|
||||||
|
rooms=[
|
||||||
|
{"room_id": "r_lan", "name": "#LAN-Dokumentation",
|
||||||
|
"theme": "lan docs", "keywords": ["lan", "dokumentation", "netzwerk"]},
|
||||||
|
{"room_id": "r_proton", "name": "#ProtonBridge",
|
||||||
|
"theme": "proton mail bridge", "keywords": ["protonbridge", "protonmail", "bridge"]},
|
||||||
|
{"room_id": "r_admin", "name": "DM Admin",
|
||||||
|
"theme": "admin", "keywords": [], "catch_all": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
path = _tmp_map(json_str)
|
||||||
|
try:
|
||||||
|
room_map = RoomMap.load(path)
|
||||||
|
state = ArchivarState()
|
||||||
|
state._loaded = True
|
||||||
|
|
||||||
|
# Setze never_route für 'lan-dokumentation' im Ursprungsraum
|
||||||
|
origin_room = "r_proton"
|
||||||
|
state.set_never_route(origin_room, "lan-dokumentation")
|
||||||
|
|
||||||
|
router = BidirectionalRouter(room_map, None, state) # type: ignore
|
||||||
|
|
||||||
|
# Nachricht matcht #ProtonBridge (anderes Thema) → NICHT geblockt
|
||||||
|
proton_room = room_map.get_room_by_id("r_proton")
|
||||||
|
assert proton_room is not None
|
||||||
|
blocked = router._check_never_route_topic(origin_room, proton_room)
|
||||||
|
assert blocked is False, (
|
||||||
|
"never_route für 'lan-dokumentation' sollte ProtonBridge-Match "
|
||||||
|
"NICHT blocken — anderes Thema!"
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
def test_room_name_to_topic_conversion(self):
|
||||||
|
"""room_name_to_topic konvertiert Raum-Namen korrekt."""
|
||||||
|
from plugin.archivar.router import room_name_to_topic
|
||||||
|
|
||||||
|
assert room_name_to_topic("#LAN-Dokumentation") == "lan-dokumentation"
|
||||||
|
assert room_name_to_topic("LAN-Dokumentation") == "lan-dokumentation"
|
||||||
|
assert room_name_to_topic("#ProtonBridge") == "protonbridge"
|
||||||
|
assert room_name_to_topic("#DevOps") == "devops"
|
||||||
|
# _room_name_to_topic stripped nur '#', nicht Whitespace
|
||||||
|
assert room_name_to_topic("Mein Raum") == "mein-raum"
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"rooms": {},
|
||||||
|
"keyword_weights": {},
|
||||||
|
"sticky_keywords": {},
|
||||||
|
"manual_overrides": {},
|
||||||
|
"promotion_candidates": {},
|
||||||
|
"stay_tracker": {},
|
||||||
|
"onboarding_state": {},
|
||||||
|
"never_route": {
|
||||||
|
"r_proton": {
|
||||||
|
"lan-dokumentation": {
|
||||||
|
"state": "AKTIV",
|
||||||
|
"timestamp": "2026-07-13T15:47:31.199595",
|
||||||
|
"last_extended": "2026-07-13T15:47:31.199595",
|
||||||
|
"extension_count": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user