fix(archivar): P-108 Sticky-Scope bleibt im Ursprungsraum bei themenarmer Folge-Nachricht
This commit is contained in:
@@ -238,11 +238,12 @@ class TestV843B2FallthroughRedFlag(unittest.TestCase):
|
||||
self.adapter, self.mock_rest = _build_mock_adapter(self._room_map_path)
|
||||
|
||||
def test_b2_no_topic_falls_through_to_classify_and_route(self):
|
||||
"""B2 No-Topic: classify_and_route wird aufgerufen (nicht übergangen).
|
||||
"""B2 No-Topic: classify_and_route wird NICHT aufgerufen (P-108).
|
||||
|
||||
Sticky ist aktiv, aber die Nachricht enthält KEIN 100%-Keyword.
|
||||
Vor V8.4.3: classify_and_route wurde NIE aufgerufen.
|
||||
Nach V8.4.3: classify_and_route wird aufgerufen → Red Flag kann feuern.
|
||||
Vor P-108 (V8.4.3): classify_and_route wurde aufgerufen (Fall-through).
|
||||
Nach P-108: Sticky wird ignoriert, Nachricht bleibt im Ursprungsraum —
|
||||
KEIN Archivar-Routing, die Nachricht wird normal an den Agent dispatcht.
|
||||
"""
|
||||
# Set up sticky session preference: origin room → target room
|
||||
self.adapter._session_room_preferences["room_bat_team"] = {
|
||||
@@ -260,43 +261,29 @@ class TestV843B2FallthroughRedFlag(unittest.TestCase):
|
||||
"u": {"username": "testuser"},
|
||||
}
|
||||
|
||||
# Patch classify_and_route to track calls AND return a Red Flag decision
|
||||
from plugin.archivar.router import RoutingDecision
|
||||
|
||||
red_flag_decision = RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=0.0,
|
||||
stay_in_room=True,
|
||||
is_red_flag=True,
|
||||
red_flag_rooms=["#LAN-Doku", "#BAT-Team"],
|
||||
red_flag_prompt="ROUTER UNSICHER: ...",
|
||||
)
|
||||
|
||||
original_classify = self.adapter.archivar.classify_and_route
|
||||
# Patch classify_and_route to track calls
|
||||
call_count = [0]
|
||||
|
||||
async def tracking_classify(text, origin_room_id="", **kwargs):
|
||||
call_count[0] += 1
|
||||
return red_flag_decision
|
||||
return None
|
||||
|
||||
self.adapter.archivar.classify_and_route = tracking_classify
|
||||
|
||||
asyncio.run(self.adapter._process_incoming(msg_obj))
|
||||
|
||||
# Verify: classify_and_route WAS called
|
||||
self.assertEqual(call_count[0], 1,
|
||||
f"classify_and_route should be called once, got {call_count[0]} calls")
|
||||
# P-108: classify_and_route wird NICHT aufgerufen — Nachricht bleibt
|
||||
# im Ursprungsraum, kein Archivar-Routing.
|
||||
self.assertEqual(call_count[0], 0,
|
||||
f"classify_and_route should NOT be called on B2 no-topic (P-108), got {call_count[0]} calls")
|
||||
|
||||
def test_b2_no_topic_red_flag_decision_reaches_dispatch(self):
|
||||
"""B2 No-Topic: is_red_flag=True erreicht den Pre-Dispatch-Hook.
|
||||
"""B2 No-Topic: Nachricht wird normal dispatcht, OHNE Red-Flag (P-108).
|
||||
|
||||
Der Red-Flag-Prompt wird in den System-Prompt injiziert.
|
||||
Vor V8.4.3: is_red_flag=True wurde NIE erreicht weil
|
||||
classify_and_route nie aufgerufen wurde.
|
||||
Sticky aktiv + Nachricht ohne 100%-Keyword → Sticky ignoriert, kein
|
||||
Archivar-Routing → kein Red-Flag-Prompt. Die Nachricht wird normal an
|
||||
den Agent dispatcht (handle_message aufgerufen).
|
||||
"""
|
||||
from plugin.archivar.router import RoutingDecision
|
||||
|
||||
# Set up sticky session preference
|
||||
self.adapter._session_room_preferences["room_bat_team"] = {
|
||||
"target_room": "room_rc_plugin",
|
||||
@@ -305,21 +292,9 @@ class TestV843B2FallthroughRedFlag(unittest.TestCase):
|
||||
"expires_at": time.time() + 1800,
|
||||
}
|
||||
|
||||
red_flag_decision = RoutingDecision(
|
||||
category="direct_question",
|
||||
target_room="",
|
||||
confidence=0.0,
|
||||
stay_in_room=True,
|
||||
is_red_flag=True,
|
||||
red_flag_rooms=["#LAN-Doku", "#BAT-Team"],
|
||||
red_flag_prompt="ROUTER UNSICHER: Wähle einen Raum.\n\n"
|
||||
"1. #LAN-Doku - LAN Dokumentation\n"
|
||||
"2. #BAT-Team - BAT Team Koordination\n\n"
|
||||
"Antworte mit: ROOM: <raumname>",
|
||||
)
|
||||
|
||||
async def tracking_classify(text, origin_room_id="", **kwargs):
|
||||
return red_flag_decision
|
||||
# Sollte nie aufgerufen werden (P-108)
|
||||
raise AssertionError("classify_and_route must not be called on B2 no-topic")
|
||||
|
||||
self.adapter.archivar.classify_and_route = tracking_classify
|
||||
|
||||
@@ -332,16 +307,16 @@ class TestV843B2FallthroughRedFlag(unittest.TestCase):
|
||||
|
||||
asyncio.run(self.adapter._process_incoming(msg_obj))
|
||||
|
||||
# Verify: handle_message was called (flow completed)
|
||||
# Verify: handle_message was called (flow completed — normal dispatch)
|
||||
self.adapter.handle_message.assert_called_once()
|
||||
|
||||
# Verify: Red Flag prompt was injected into chat_topic (system prompt)
|
||||
# Verify: KEIN Red-Flag-Prompt injiziert (kein Archivar-Routing)
|
||||
call_args = self.adapter.handle_message.call_args[0]
|
||||
event = call_args[0] # MessageEvent
|
||||
source = getattr(event, 'source', None)
|
||||
chat_topic = getattr(source, 'chat_topic', '') if source else ''
|
||||
self.assertIn("ROUTER UNSICHER", chat_topic,
|
||||
f"Red Flag prompt should be in source.chat_topic, got: {chat_topic[:200]}")
|
||||
self.assertNotIn("ROUTER UNSICHER", chat_topic,
|
||||
f"Red Flag prompt should NOT be injected on B2 no-topic (P-108), got: {chat_topic[:200]}")
|
||||
|
||||
def test_b2_no_topic_with_real_router_red_flag(self):
|
||||
"""B2 No-Topic: classify_and_route wird aufgerufen → Red Flag erreichbar.
|
||||
|
||||
Reference in New Issue
Block a user