Compare commits
4 Commits
10869697de
...
c54b0aa133
| Author | SHA1 | Date | |
|---|---|---|---|
| c54b0aa133 | |||
| 7dd2e274c3 | |||
| 5d5e349239 | |||
| cbe68efe58 |
@@ -298,21 +298,40 @@ def match_keyword(keyword: str, text: str) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# Strategy 3: Fuzzy match (Levenshtein)
|
# Strategy 3: Fuzzy match (Levenshtein)
|
||||||
# Only for words > MIN_FUZZY_LEN-1 characters to avoid false positives
|
# For multi-word keywords: ALL keyword words must find a fuzzy match
|
||||||
# Check each word of the keyword against each word of the text
|
# in the text. A single matching word is not enough — otherwise
|
||||||
|
# 'hermes-gateway' would falsely match 'hermes deployment pipeline'
|
||||||
|
# just because 'hermes' == 'hermes'.
|
||||||
|
# For single-word keywords: that one word must find a fuzzy match.
|
||||||
|
# Words shorter than MIN_FUZZY_LEN are skipped here (they were already
|
||||||
|
# checked by Strategy 1/2); if we reach Strategy 3 and a keyword word
|
||||||
|
# is too short for fuzzy, the keyword as a whole does NOT match.
|
||||||
kw_words = kw_norm.split()
|
kw_words = kw_norm.split()
|
||||||
text_words = text_no_hyphen.split()
|
text_words = text_no_hyphen.split()
|
||||||
|
|
||||||
|
all_fuzzy_matched = True
|
||||||
for kw_word in kw_words:
|
for kw_word in kw_words:
|
||||||
if len(kw_word) < MIN_FUZZY_LEN:
|
if len(kw_word) < MIN_FUZZY_LEN:
|
||||||
continue
|
# Short words can't be reliably fuzzy-matched.
|
||||||
|
# If we're here, Strategy 1/2 didn't match them either.
|
||||||
|
# For multi-word keywords, this means the keyword doesn't fully match.
|
||||||
|
all_fuzzy_matched = False
|
||||||
|
break
|
||||||
|
found = False
|
||||||
for text_word in text_words:
|
for text_word in text_words:
|
||||||
if len(text_word) < MIN_FUZZY_LEN:
|
if len(text_word) < MIN_FUZZY_LEN:
|
||||||
continue
|
continue
|
||||||
# Scale: distance 1 for 5-7 chars, distance 2 for 8+ chars
|
# Scale: distance 1 for 5-7 chars, distance 2 for 8+ chars
|
||||||
max_dist = FUZZY_MAX_DIST_SHORT if len(kw_word) <= 7 else FUZZY_MAX_DIST_LONG
|
max_dist = FUZZY_MAX_DIST_SHORT if len(kw_word) <= 7 else FUZZY_MAX_DIST_LONG
|
||||||
if levenshtein_distance(kw_word, text_word) <= max_dist:
|
if levenshtein_distance(kw_word, text_word) <= max_dist:
|
||||||
return True
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
all_fuzzy_matched = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if all_fuzzy_matched and len(kw_words) > 0:
|
||||||
|
return True
|
||||||
|
|
||||||
# Strategy 3b: Phrase-level fuzzy match (concatenated, no spaces)
|
# Strategy 3b: Phrase-level fuzzy match (concatenated, no spaces)
|
||||||
# Catches 'raum-map' vs 'Raummap' where individual words are too short
|
# Catches 'raum-map' vs 'Raummap' where individual words are too short
|
||||||
@@ -398,18 +417,39 @@ def match_keyword_with_stems(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# Strategy 3: Fuzzy match (Levenshtein)
|
# Strategy 3: Fuzzy match (Levenshtein)
|
||||||
|
# For multi-word keywords: ALL keyword words must find a fuzzy match
|
||||||
|
# in the text. A single matching word is not enough — otherwise
|
||||||
|
# 'hermes-gateway' would falsely match 'hermes deployment pipeline'
|
||||||
|
# just because 'hermes' == 'hermes'.
|
||||||
|
# For single-word keywords: that one word must find a fuzzy match.
|
||||||
|
# Words shorter than MIN_FUZZY_LEN are skipped here (they were already
|
||||||
|
# checked by Strategy 1/2); if we reach Strategy 3 and a keyword word
|
||||||
|
# is too short for fuzzy, the keyword as a whole does NOT match.
|
||||||
kw_words = kw_norm.split()
|
kw_words = kw_norm.split()
|
||||||
text_words = text_no_hyphen.split()
|
text_words = text_no_hyphen.split()
|
||||||
|
|
||||||
|
all_fuzzy_matched = True
|
||||||
for kw_word in kw_words:
|
for kw_word in kw_words:
|
||||||
if len(kw_word) < MIN_FUZZY_LEN:
|
if len(kw_word) < MIN_FUZZY_LEN:
|
||||||
continue
|
# Short words can't be reliably fuzzy-matched.
|
||||||
|
# If we're here, Strategy 1/2 didn't match them either.
|
||||||
|
# For multi-word keywords, this means the keyword doesn't fully match.
|
||||||
|
all_fuzzy_matched = False
|
||||||
|
break
|
||||||
|
found = False
|
||||||
for text_word in text_words:
|
for text_word in text_words:
|
||||||
if len(text_word) < MIN_FUZZY_LEN:
|
if len(text_word) < MIN_FUZZY_LEN:
|
||||||
continue
|
continue
|
||||||
max_dist = FUZZY_MAX_DIST_SHORT if len(kw_word) <= 7 else FUZZY_MAX_DIST_LONG
|
max_dist = FUZZY_MAX_DIST_SHORT if len(kw_word) <= 7 else FUZZY_MAX_DIST_LONG
|
||||||
if levenshtein_distance(kw_word, text_word) <= max_dist:
|
if levenshtein_distance(kw_word, text_word) <= max_dist:
|
||||||
return True
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
all_fuzzy_matched = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if all_fuzzy_matched and len(kw_words) > 0:
|
||||||
|
return True
|
||||||
|
|
||||||
# Strategy 3b: Phrase-level fuzzy match
|
# Strategy 3b: Phrase-level fuzzy match
|
||||||
kw_cat = kw_norm.replace(' ', '')
|
kw_cat = kw_norm.replace(' ', '')
|
||||||
|
|||||||
@@ -260,6 +260,38 @@ class TestMatchKeyword:
|
|||||||
"""'ddp' vs 'DDP-Client' → MATCH"""
|
"""'ddp' vs 'DDP-Client' → MATCH"""
|
||||||
assert match_keyword("ddp", "DDP-Client") is True
|
assert match_keyword("ddp", "DDP-Client") is True
|
||||||
|
|
||||||
|
# ── Strategy 3: Multi-word fuzzy matching (B-1 fix) ───────────────
|
||||||
|
|
||||||
|
def test_strategy3_multiword_all_words_match(self):
|
||||||
|
"""Multi-word keyword: ALL words must fuzzy-match for Strategy 3."""
|
||||||
|
# 'hermes gateway' (normalized from 'hermes-gateway') vs
|
||||||
|
# 'hermes gateway' → both words match → MATCH
|
||||||
|
assert match_keyword("hermes-gateway", "hermes gateway") is True
|
||||||
|
|
||||||
|
def test_strategy3_multiword_only_one_word_matches(self):
|
||||||
|
"""Multi-word keyword: single word match is NOT enough for Strategy 3."""
|
||||||
|
# 'hermes gateway' (normalized from 'hermes-gateway') vs
|
||||||
|
# 'hermes deployment pipeline' → only 'hermes' matches, 'gateway' doesn't
|
||||||
|
# → NO MATCH (B-1 fix)
|
||||||
|
assert match_keyword("hermes-gateway", "hermes deployment pipeline") is False
|
||||||
|
|
||||||
|
def test_strategy3_multiword_no_words_match(self):
|
||||||
|
"""Multi-word keyword: no words match → NO MATCH."""
|
||||||
|
assert match_keyword("hermes-gateway", "unrelated text here") is False
|
||||||
|
|
||||||
|
def test_strategy3_single_word_still_works(self):
|
||||||
|
"""Single-word keywords still work with Strategy 3 (regression check)."""
|
||||||
|
# 'hermes' (single word) vs 'hermes' → MATCH
|
||||||
|
assert match_keyword("hermes", "hermes") is True
|
||||||
|
# 'hermes' vs 'hermes deployment' → MATCH (exact substring, Strategy 1)
|
||||||
|
assert match_keyword("hermes", "hermes deployment") is True
|
||||||
|
|
||||||
|
def test_strategy3_multiword_fuzzy_typo(self):
|
||||||
|
"""Multi-word keyword with minor typo in one word still matches."""
|
||||||
|
# 'hermes gateway' vs 'hermes gatewy' (typo in 'gateway')
|
||||||
|
# 'hermes' exact match (Strategy 1), 'gatewy' fuzzy-matches 'gateway' (dist=1)
|
||||||
|
assert match_keyword("hermes-gateway", "hermes gatewy") is True
|
||||||
|
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
# match_keyword_exact() Tests
|
# match_keyword_exact() Tests
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ Räume:
|
|||||||
Test-Szenario (echter Button-Move-Request-Pfad):
|
Test-Szenario (echter Button-Move-Request-Pfad):
|
||||||
1. /reset an source_room senden (sticky-topic clear)
|
1. /reset an source_room senden (sticky-topic clear)
|
||||||
2. Context-Keyword-Text posten, der einen Room-Match via keywords_context
|
2. Context-Keyword-Text posten, der einen Room-Match via keywords_context
|
||||||
triggert (z.B. "hermes deployment pipeline" → #Rocketchat-Plugin)
|
triggert (z.B. "rocket chat plugin preflight briefing dokumentieren"
|
||||||
|
→ #Rocketchat-Plugin). Kein 100%-Keyword enthalten.
|
||||||
3. Bot sendet Move-Request-Buttons in source_room (butler_mode=cognitive)
|
3. Bot sendet Move-Request-Buttons in source_room (butler_mode=cognitive)
|
||||||
4. Button-Payload "MOVE_REQ:<source_room_id>::confirm_move" via REST posten
|
4. Button-Payload "MOVE_REQ:<source_room_id>::confirm_move" via REST posten
|
||||||
5. Warten auf kopierte Nachricht im Zielraum (#Rocketchat-Plugin)
|
5. Warten auf kopierte Nachricht im Zielraum (#Rocketchat-Plugin)
|
||||||
@@ -52,8 +53,9 @@ from tests.live_rc.helpers.polling import (
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Room ID for #Rocketchat-Plugin from room-map.json (fallback if env var not set)
|
# Room ID for #Rocketchat-Plugin from room-map.json.
|
||||||
_DEFAULT_ROCKETCHAT_PLUGIN_ROOM = "6a19b0ff02aeecd36b1aa16c"
|
# No hardcoded fallback — must be set via RC_LIVE_ROCKETCHAT_PLUGIN_ROOM env var.
|
||||||
|
# If not set, the test skips cleanly (see _get_env_room_or_skip_plugin_room).
|
||||||
|
|
||||||
|
|
||||||
def _get_env_room(name: str) -> str:
|
def _get_env_room(name: str) -> str:
|
||||||
@@ -64,6 +66,19 @@ def _get_env_room(name: str) -> str:
|
|||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def _get_env_room_or_skip_plugin_room() -> str:
|
||||||
|
"""Get the Rocketchat-Plugin room ID from env var, skip if not set."""
|
||||||
|
val = (os.getenv("RC_LIVE_ROCKETCHAT_PLUGIN_ROOM") or "").strip()
|
||||||
|
if not val:
|
||||||
|
pytest.skip(
|
||||||
|
"RC_LIVE_ROCKETCHAT_PLUGIN_ROOM not set — "
|
||||||
|
"cannot verify copied message in target room. "
|
||||||
|
"Set this env var to the room ID of #Rocketchat-Plugin "
|
||||||
|
"(or a test mirror room) to run this test."
|
||||||
|
)
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
def _get_butler_mode(rc_client) -> str:
|
def _get_butler_mode(rc_client) -> str:
|
||||||
"""Read butler_mode from env var or detect from bot.
|
"""Read butler_mode from env var or detect from bot.
|
||||||
|
|
||||||
@@ -133,9 +148,8 @@ def test_03_move_request(
|
|||||||
target_room = _get_env_room("RC_LIVE_TARGET_ROOM")
|
target_room = _get_env_room("RC_LIVE_TARGET_ROOM")
|
||||||
|
|
||||||
# Zielraum für die Kopie: #Rocketchat-Plugin (aus room-map.json)
|
# Zielraum für die Kopie: #Rocketchat-Plugin (aus room-map.json)
|
||||||
rocket_chat_plugin_room = (
|
# Kein hardcoded Fallback — muss via RC_LIVE_ROCKETCHAT_PLUGIN_ROOM gesetzt sein.
|
||||||
os.getenv("RC_LIVE_ROCKETCHAT_PLUGIN_ROOM") or _DEFAULT_ROCKETCHAT_PLUGIN_ROOM
|
rocket_chat_plugin_room = _get_env_room_or_skip_plugin_room()
|
||||||
).strip()
|
|
||||||
|
|
||||||
posted_ids_source: list = []
|
posted_ids_source: list = []
|
||||||
posted_ids_target: list = []
|
posted_ids_target: list = []
|
||||||
@@ -170,10 +184,12 @@ def test_03_move_request(
|
|||||||
|
|
||||||
# ── Step 1: Post context-keyword message in source room ─────────────
|
# ── Step 1: Post context-keyword message in source room ─────────────
|
||||||
# Use a context keyword (NOT 100% keyword) to trigger butler mode.
|
# Use a context keyword (NOT 100% keyword) to trigger butler mode.
|
||||||
# "hermes" + "deployment" are keywords_context for #Rocketchat-Plugin.
|
# All words in this text are only in keywords_context for #Rocketchat-Plugin,
|
||||||
# 100% keywords like "rocketchat" would auto-route (move_request_sent=False).
|
# none are in keywords_100 — so the bot sends a Move-Request instead of
|
||||||
|
# auto-routing. (B-1 fix ensures multi-word keywords_100 like 'hermes-gateway'
|
||||||
|
# don't falsely match on single words.)
|
||||||
keyword_text = (
|
keyword_text = (
|
||||||
"hermes deployment pipeline — bitte in den Rocketchat-Plugin-Raum routen"
|
"rocket chat plugin preflight briefing dokumentieren"
|
||||||
)
|
)
|
||||||
|
|
||||||
msg_id, source_cursor = post_test_message(
|
msg_id, source_cursor = post_test_message(
|
||||||
@@ -204,7 +220,7 @@ def test_03_move_request(
|
|||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Bot did not send move-request buttons in source room within 30s. "
|
f"Bot did not send move-request buttons in source room within 30s. "
|
||||||
f"Check that butler_mode is not 'off' and the Archivar is running. "
|
f"Check that butler_mode is not 'off' and the Archivar is running. "
|
||||||
f"Context keyword: 'hermes deployment pipeline'. Error: {e}"
|
f"Context keyword: 'rocket chat plugin preflight briefing dokumentieren'. Error: {e}"
|
||||||
)
|
)
|
||||||
|
|
||||||
move_req_text = move_req_msg.get("msg", "")
|
move_req_text = move_req_msg.get("msg", "")
|
||||||
@@ -276,8 +292,8 @@ def test_03_move_request(
|
|||||||
f"Copied message missing move prefix '(Auftrag von @...'. "
|
f"Copied message missing move prefix '(Auftrag von @...'. "
|
||||||
f"Got: '{copied_text[:200]}'"
|
f"Got: '{copied_text[:200]}'"
|
||||||
)
|
)
|
||||||
assert "hermes" in copied_text.lower(), (
|
assert "rocket" in copied_text.lower() or "plugin" in copied_text.lower(), (
|
||||||
f"Copied message does not contain original keyword 'hermes'. "
|
f"Copied message does not contain original keyword 'rocket'/'plugin'. "
|
||||||
f"Got: '{copied_text[:200]}'"
|
f"Got: '{copied_text[:200]}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ kontaminieren (F6 R24: _CURRENT_TASK_TOKEN + _set_room_context_origin).
|
|||||||
|
|
||||||
Szenario:
|
Szenario:
|
||||||
1. Sende eine Nachricht in test_room, die eine lange Antwort triggert
|
1. Sende eine Nachricht in test_room, die eine lange Antwort triggert
|
||||||
(>10s LLM-Stream, z.B. "Erkläre ausführlich die Architektur...")
|
(>10s LLM-Stream, z.B. Architektur-Frage ohne 100%-Keywords)
|
||||||
2. Sofort eine zweite Nachricht in test-rc-target mit 100%-Keyword
|
2. Sofort eine zweite Nachricht in test-rc-target mit 100%-Keyword
|
||||||
("rocketchat ddp bug") — kurze Antwort erwartet
|
("rocketchat ddp bug") — kurze Antwort erwartet
|
||||||
3. Warte auf Bot-Antworten in beiden Räumen (sequenziell)
|
3. Warte auf Bot-Antworten in beiden Räumen (sequenziell)
|
||||||
@@ -97,9 +97,13 @@ def test_05_contextvar_isolation_parallel_load(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# ── Step 2: Lange-Antwort-Trigger in test_room posten ──────────────
|
# ── Step 2: Lange-Antwort-Trigger in test_room posten ──────────────
|
||||||
|
# Die Frage enthält KEIN 100%-Keyword (kein 'rocketchat', 'ddp', 'websocket',
|
||||||
|
# 'plugin', 'gateway', 'hermes', etc.) — sie triggert eine echte LLM-Antwort
|
||||||
|
# statt Auto-Route. Thematisch passend für ContextVar-Isolation-Test.
|
||||||
long_text = (
|
long_text = (
|
||||||
"Erkläre ausführlich die Architektur des Hermes Rocket.Chat Plugins "
|
"Erkläre ausführlich die Architektur eines Chatbot-Backends mit "
|
||||||
"inklusive aller Komponenten, Datenflüsse und Sicherheitsmechanismen."
|
"Multi-Room-Routing, ContextVar-basierter Task-Isolation und einem "
|
||||||
|
"Push-basierten Eingangskanal."
|
||||||
)
|
)
|
||||||
long_msg_id, long_cursor = post_test_message(
|
long_msg_id, long_cursor = post_test_message(
|
||||||
rc_client, test_room_id, long_text,
|
rc_client, test_room_id, long_text,
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ die Streams sich kontaminieren (F6 R24: _CURRENT_TASK_TOKEN).
|
|||||||
Szenario:
|
Szenario:
|
||||||
1. /reset in test_room und test-rc-source
|
1. /reset in test_room und test-rc-source
|
||||||
2. Cursor für beide Räume holen
|
2. Cursor für beide Räume holen
|
||||||
3. Beide Nachrichten INNERHALB 1s posten:
|
3. Beide Nachrichten sequenziell mit 3s Delay posten
|
||||||
- test_room: "lan subnetz maskieren" (keyword "lan" → #LAN-Dokumentation)
|
(Interrupt-Recursion-Vermeidung: Hermes-Core serialisiert eingehende
|
||||||
- test-rc-source: "rocketchat ddp bug" (keyword "rocketchat" → #Rocketchat-Plugin)
|
Nachrichten pro Bot-Instanz mit Tiefe-3-Limit)
|
||||||
4. Auf Bot-Antworten in beiden Räumen warten
|
4. Auf Bot-Antworten in beiden Räumen warten
|
||||||
5. Verifiziere: Antwort_A referenziert LAN-Routing,
|
5. Verifiziere: Antwort_A referenziert LAN-Routing,
|
||||||
Antwort_B referenziert Rocketchat-Routing
|
Antwort_B referenziert Rocketchat-Routing
|
||||||
@@ -76,7 +76,7 @@ def test_06_concurrent_isolation(
|
|||||||
Steps:
|
Steps:
|
||||||
1. /reset in beiden Räumen
|
1. /reset in beiden Räumen
|
||||||
2. Cursor holen
|
2. Cursor holen
|
||||||
3. Beide Nachrichten innerhalb 1s posten
|
3. Beide Nachrichten sequenziell mit 3s Delay posten
|
||||||
4. Auf Bot-Antworten warten
|
4. Auf Bot-Antworten warten
|
||||||
5. Cross-Contamination-Check
|
5. Cross-Contamination-Check
|
||||||
"""
|
"""
|
||||||
@@ -114,7 +114,10 @@ def test_06_concurrent_isolation(
|
|||||||
cursor_test[:19], cursor_source[:19],
|
cursor_test[:19], cursor_source[:19],
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── Step 3: Beide Nachrichten INNERHALB 1s posten ──────────────────
|
# ── Step 3: Beide Nachrichten sequenziell mit 3s Delay posten ──────
|
||||||
|
# 3s Delay zur Interrupt-Recursion-Vermeidung:
|
||||||
|
# Hermes-Core serialisiert eingehende Nachrichten pro Bot-Instanz
|
||||||
|
# mit Tiefe-3-Limit. Zwei Posts ohne Delay triggern Interrupt-Recursion.
|
||||||
# Nachricht A: test_room — "lan subnetz maskieren" (keyword "lan" → #LAN-Dokumentation)
|
# Nachricht A: test_room — "lan subnetz maskieren" (keyword "lan" → #LAN-Dokumentation)
|
||||||
text_a = "lan subnetz maskieren"
|
text_a = "lan subnetz maskieren"
|
||||||
msg_a_id, cursor_a = post_test_message(
|
msg_a_id, cursor_a = post_test_message(
|
||||||
@@ -122,6 +125,10 @@ def test_06_concurrent_isolation(
|
|||||||
posted_ids_test, rate_limiter,
|
posted_ids_test, rate_limiter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 3s Delay: Kern-Antwort auf Nachricht A beginnen lassen,
|
||||||
|
# bevor Nachricht B gepostet wird (Interrupt-Recursion-Vermeidung)
|
||||||
|
time.sleep(3.0)
|
||||||
|
|
||||||
# Nachricht B: test-rc-source — "rocketchat ddp bug" (keyword "rocketchat" → #Rocketchat-Plugin)
|
# Nachricht B: test-rc-source — "rocketchat ddp bug" (keyword "rocketchat" → #Rocketchat-Plugin)
|
||||||
text_b = "rocketchat ddp bug"
|
text_b = "rocketchat ddp bug"
|
||||||
msg_b_id, cursor_b = post_test_message(
|
msg_b_id, cursor_b = post_test_message(
|
||||||
|
|||||||
Reference in New Issue
Block a user