feat(F592): Clef Flash Phase-2 — 2-stufiger Klassifikator (Bit 6) @implements: [F-592]
Neue Datei clef_flash_router.py (ClefFlashRouter): async aiohttp-Client für den
SystemOne-Endpoint (POST /v1/systemone auf .101:11434). route(state_text,
room_criteria) → ClefFlashResult{choice, probabilities, confidence} oder None
bei Feature-Flag AUS/Fehler/Timeout. Rainer-Auflage P-308: aiohttp statt urllib.
Integration in router.py als NEUER Schritt 3.6 (zwischen FAISS-Schritt 3.5 und
Embedding-Vorfilter-Schritt 4) — bestehende FAISS-Logik UNANGETASTET (additiv).
Feature-Flag CLEF_FLASH_ENABLED default AUS (kein Verhaltenswechsel). Inline-
Wartezeit 5s (Auflage 1), Trigger-Band [0.55, 0.85) + Catch-All-Fallback
(Auflage 2). Sub-Pfade A/B/C nach Confidence.
config.py: eigener F-592-Konfig-Block (P-218-Schutz, getrennt von Red-Flag,
P-011-Laufzeit-ENV). room_map.py NICHT modifiziert (Architektur §4.1 — die
FAISS-Suche liegt in router.py, nicht room_map.py).
33 neue Tests (test_f592_clef_flash_router.py 20 Unit, test_f592_integration.py
13 Integration). Regression: 115 bestehende Tests grün.
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
# @implements: [F-592] — Clef Flash Phase-2 (Unit-Tests für ClefFlashRouter)
|
||||
"""
|
||||
Unit-Tests für den ClefFlashRouter (Phase 2 des 2-stufigen Klassifikators).
|
||||
|
||||
Abgedeckt:
|
||||
1. Payload-Aufbau (questions/criteria sind Dicts, NICHT Listen — P-187).
|
||||
2. route() bei Feature-Flag AUS → None (kein HTTP-Call).
|
||||
3. route() bei leerem state/criteria → None.
|
||||
4. Response-Parsing (choice/probabilities/confidence).
|
||||
5. Fehler-Pfade: HTTP-Fehler, Parse-Fehler, Timeout → None.
|
||||
6. ENV-Override (CLEF_FLASH_ENABLED etc., P-011-Klasse).
|
||||
|
||||
Der HTTP-Call wird via ``_post_systemone`` gemockt — kein echter Ollama-Zugriff.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
||||
|
||||
from plugin.archivar.clef_flash_router import ClefFlashRouter, ClefFlashResult
|
||||
|
||||
|
||||
# ── Helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _make_router(enabled: bool = True, **kwargs) -> ClefFlashRouter:
|
||||
"""Baut einen Router mit explizitem enabled-Override (Testisolation)."""
|
||||
return ClefFlashRouter(enabled=enabled, **kwargs)
|
||||
|
||||
|
||||
def _sample_response(choice="#BAT-Team", confidence=0.829) -> dict:
|
||||
"""Baut eine gültige SystemOne-Antwort (Spike §1.3)."""
|
||||
return {
|
||||
"model": "clef-flash:latest",
|
||||
"answers": {
|
||||
"room_routing": {
|
||||
"type": "choice",
|
||||
"choice": choice,
|
||||
"probabilities": {
|
||||
"#BAT-Team": 0.9745714302929901,
|
||||
"#PMDB": 0.025428569707009914,
|
||||
},
|
||||
"confidence": confidence,
|
||||
}
|
||||
},
|
||||
"usage": {"input_tokens": 154, "output_tokens": 0},
|
||||
}
|
||||
|
||||
|
||||
CRITERIA = {
|
||||
"#BAT-Team": "Trading, Krypto, Wyckoff, Bitcoin",
|
||||
"#PMDB": "PMDB, PostgreSQL, MCP-Broker, Features",
|
||||
}
|
||||
|
||||
|
||||
# ── Test 1: Payload-Aufbau ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestBuildPayload:
|
||||
def test_questions_and_criteria_are_dicts(self):
|
||||
"""questions und criteria müssen Dicts sein, keine Listen (P-187)."""
|
||||
cf = _make_router()
|
||||
payload = cf._build_payload("BTC Analyse", CRITERIA)
|
||||
assert isinstance(payload["questions"], dict)
|
||||
q = payload["questions"]["room_routing"]
|
||||
assert q["type"] == "choice"
|
||||
assert q["question"] == "Which room?"
|
||||
assert isinstance(q["criteria"], dict)
|
||||
|
||||
def test_criteria_content_preserved(self):
|
||||
"""Die criteria-Werte werden 1:1 übernommen."""
|
||||
cf = _make_router()
|
||||
payload = cf._build_payload("text", CRITERIA)
|
||||
assert payload["questions"]["room_routing"]["criteria"] == CRITERIA
|
||||
|
||||
def test_model_field(self):
|
||||
cf = _make_router(model="clef-flash:latest")
|
||||
payload = cf._build_payload("text", CRITERIA)
|
||||
assert payload["model"] == "clef-flash:latest"
|
||||
|
||||
|
||||
# ── Test 2: Feature-Flag AUS ─────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestDisabledFlag:
|
||||
def test_disabled_returns_none_without_call(self):
|
||||
"""CLEF_FLASH_ENABLED=false → route() gibt None zurück, kein HTTP-Call."""
|
||||
cf = _make_router(enabled=False)
|
||||
# _post_systemone darf NICHT aufgerufen werden.
|
||||
with patch.object(cf, "_post_systemone", AsyncMock()) as mock_post:
|
||||
result = asyncio.run(cf.route("text", CRITERIA))
|
||||
assert result is None
|
||||
mock_post.assert_not_called()
|
||||
|
||||
|
||||
# ── Test 3: Leere Inputs ────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestEmptyInputs:
|
||||
def test_empty_state_returns_none(self):
|
||||
cf = _make_router(enabled=True)
|
||||
result = asyncio.run(cf.route(" ", CRITERIA))
|
||||
assert result is None
|
||||
|
||||
def test_empty_criteria_returns_none(self):
|
||||
cf = _make_router(enabled=True)
|
||||
result = asyncio.run(cf.route("BTC Analyse", {}))
|
||||
assert result is None
|
||||
|
||||
|
||||
# ── Test 4: Erfolgreiche Klassifikation ─────────────────────────────────
|
||||
|
||||
|
||||
class TestSuccessfulRoute:
|
||||
def test_route_returns_parsed_result(self):
|
||||
cf = _make_router(enabled=True)
|
||||
with patch.object(cf, "_post_systemone", AsyncMock(return_value=_sample_response())):
|
||||
result = asyncio.run(cf.route("BTC Wyckoff Analyse", CRITERIA))
|
||||
assert result is not None
|
||||
assert result.choice == "#BAT-Team"
|
||||
assert result.confidence == pytest.approx(0.829)
|
||||
assert "#BAT-Team" in result.probabilities
|
||||
assert result.probabilities["#BAT-Team"] == pytest.approx(0.9745714302929901)
|
||||
|
||||
def test_route_passes_state_and_criteria(self):
|
||||
"""Der SystemOne-Call erhält den korrekt gebauten Payload."""
|
||||
cf = _make_router(enabled=True)
|
||||
captured = {}
|
||||
|
||||
async def _fake_post(payload):
|
||||
captured["payload"] = payload
|
||||
return _sample_response()
|
||||
|
||||
with patch.object(cf, "_post_systemone", new=_fake_post):
|
||||
asyncio.run(cf.route("BTC Analyse", CRITERIA))
|
||||
assert captured["payload"]["state"] == "BTC Analyse"
|
||||
assert captured["payload"]["questions"]["room_routing"]["criteria"] == CRITERIA
|
||||
|
||||
|
||||
# ── Test 5: Fehler-Pfade → None ─────────────────────────────────────────
|
||||
|
||||
|
||||
class TestErrorPaths:
|
||||
def test_http_error_returns_none(self):
|
||||
cf = _make_router(enabled=True)
|
||||
with patch.object(cf, "_post_systemone", AsyncMock(return_value=None)):
|
||||
result = asyncio.run(cf.route("text", CRITERIA))
|
||||
assert result is None
|
||||
|
||||
def test_exception_returns_none(self):
|
||||
cf = _make_router(enabled=True)
|
||||
|
||||
async def _boom(payload):
|
||||
raise RuntimeError("boom")
|
||||
|
||||
with patch.object(cf, "_post_systemone", new=_boom):
|
||||
result = asyncio.run(cf.route("text", CRITERIA))
|
||||
assert result is None
|
||||
|
||||
def test_malformed_response_returns_none(self):
|
||||
"""Fehlende answers.room_routing → None."""
|
||||
cf = _make_router(enabled=True)
|
||||
with patch.object(cf, "_post_systemone", AsyncMock(return_value={"foo": "bar"})):
|
||||
result = asyncio.run(cf.route("text", CRITERIA))
|
||||
assert result is None
|
||||
|
||||
def test_missing_choice_returns_none(self):
|
||||
"""answers.room_routing ohne choice → None."""
|
||||
bad = {"answers": {"room_routing": {"type": "choice"}}}
|
||||
cf = _make_router(enabled=True)
|
||||
with patch.object(cf, "_post_systemone", AsyncMock(return_value=bad)):
|
||||
result = asyncio.run(cf.route("text", CRITERIA))
|
||||
assert result is None
|
||||
|
||||
|
||||
# ── Test 6: Response-Parsing ────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestParseResponse:
|
||||
def test_parse_valid_response(self):
|
||||
cf = _make_router()
|
||||
result = cf._parse_response(_sample_response())
|
||||
assert isinstance(result, ClefFlashResult)
|
||||
assert result.choice == "#BAT-Team"
|
||||
assert result.confidence == pytest.approx(0.829)
|
||||
|
||||
def test_parse_missing_answers(self):
|
||||
cf = _make_router()
|
||||
assert cf._parse_response({}) is None
|
||||
assert cf._parse_response({"answers": None}) is None
|
||||
|
||||
def test_parse_non_dict_response(self):
|
||||
cf = _make_router()
|
||||
assert cf._parse_response("not-a-dict") is None
|
||||
|
||||
def test_parse_confidence_non_numeric(self):
|
||||
"""confidence als String wird zu 0.0 statt zu crashen."""
|
||||
cf = _make_router()
|
||||
raw = _sample_response()
|
||||
raw["answers"]["room_routing"]["confidence"] = "high"
|
||||
result = cf._parse_response(raw)
|
||||
assert result is not None
|
||||
assert result.confidence == 0.0
|
||||
|
||||
|
||||
# ── Test 7: ENV-Override (P-011-Klasse) ────────────────────────────────
|
||||
|
||||
|
||||
class TestEnvOverride:
|
||||
def test_enabled_reads_env_true(self, monkeypatch):
|
||||
monkeypatch.setenv("CLEF_FLASH_ENABLED", "true")
|
||||
cf = ClefFlashRouter() # kein expliziter enabled-Parameter
|
||||
assert cf.enabled is True
|
||||
|
||||
def test_enabled_reads_env_false(self, monkeypatch):
|
||||
monkeypatch.setenv("CLEF_FLASH_ENABLED", "0")
|
||||
cf = ClefFlashRouter()
|
||||
assert cf.enabled is False
|
||||
|
||||
def test_timeout_reads_env(self, monkeypatch):
|
||||
monkeypatch.setenv("CLEF_FLASH_TIMEOUT_S", "45")
|
||||
cf = ClefFlashRouter()
|
||||
assert cf.timeout == pytest.approx(45.0)
|
||||
|
||||
def test_base_url_reads_env(self, monkeypatch):
|
||||
monkeypatch.setenv("CLEF_FLASH_OLLAMA_URL", "http://example:1234")
|
||||
cf = ClefFlashRouter()
|
||||
assert cf.base_url == "http://example:1234"
|
||||
|
||||
def test_invalid_float_env_falls_back(self, monkeypatch):
|
||||
monkeypatch.setenv("CLEF_FLASH_TIMEOUT_S", "nicht-eine-zahl")
|
||||
cf = ClefFlashRouter()
|
||||
assert cf.timeout == pytest.approx(30.0)
|
||||
|
||||
def test_explicit_enabled_overrides_env(self, monkeypatch):
|
||||
"""Expliziter Parameter schlägt ENV (Testbarkeit)."""
|
||||
monkeypatch.setenv("CLEF_FLASH_ENABLED", "false")
|
||||
cf = ClefFlashRouter(enabled=True)
|
||||
assert cf.enabled is True
|
||||
@@ -0,0 +1,287 @@
|
||||
# @implements: [F-592] — Clef Flash Phase-2 Integration in router.py (Schritt 3.6)
|
||||
"""
|
||||
Integration-Tests für die Clef-Flash-Phase-2-Integration in BidirectionalRouter.
|
||||
|
||||
Abgedeckt:
|
||||
1. FAISS-Logik bleibt unangetastet (Feature-Flag AUS = kein Verhaltenswechsel).
|
||||
2. Clef Flash triggert bei FAISS-Score im Band [0.55, 0.85).
|
||||
3. Clef Flash triggert bei keinem FAISS-Treffer (Catch-All-Fallback).
|
||||
4. Clef Flash routet NICHT bei FAISS-Score >= 0.85 (Auto-Route).
|
||||
5. Sub-Pfad C (niedrige Confidence) → Fall-through, kein Routing.
|
||||
6. Origin-Raum wird aus den Kriterien ausgeschlossen.
|
||||
7. Catch-All ist nie ein Kriterium.
|
||||
|
||||
Der ClefFlashRouter wird als Mock injiziert — kein echter Ollama-Zugriff.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
||||
|
||||
from plugin.archivar.router import BidirectionalRouter, RoutingDecision
|
||||
from plugin.archivar.room_map import RoomMap, RoomEntry
|
||||
from plugin.archivar.classifier import IntentClassifier, EmbeddingClient
|
||||
from plugin.archivar.archivar_state import ArchivarState
|
||||
from plugin.archivar.clef_flash_router import ClefFlashResult
|
||||
|
||||
|
||||
# ── Helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class MockEmbeddingClient(EmbeddingClient):
|
||||
def get_embedding(self, text: str) -> Optional[list]:
|
||||
return [0.1] * 768
|
||||
|
||||
|
||||
def _make_room_map() -> RoomMap:
|
||||
"""4 Räume + 1 Catch-All."""
|
||||
rooms = {
|
||||
"room_rc_plugin": RoomEntry(
|
||||
room_id="room_rc_plugin", name="#RC-Plugin",
|
||||
theme="Rocket.Chat Plugin Entwicklung",
|
||||
keywords_100=["plugin", "rocketchat"], keywords_context=["adapter", "gateway"],
|
||||
),
|
||||
"room_lan_doku": RoomEntry(
|
||||
room_id="room_lan_doku", name="#LAN-Doku",
|
||||
theme="LAN Dokumentation und Netzwerk",
|
||||
keywords_100=["dokumentation", "doku"], keywords_context=["netzwerk", "lan"],
|
||||
),
|
||||
"room_bat_team": RoomEntry(
|
||||
room_id="room_bat_team", name="#BAT-Team",
|
||||
theme="Trading, Krypto, Wyckoff",
|
||||
keywords_100=["trading", "krypto"], keywords_context=["bitcoin"],
|
||||
),
|
||||
"room_devops": RoomEntry(
|
||||
room_id="room_devops", name="#DevOps",
|
||||
theme="DevOps und Deployment",
|
||||
keywords_100=["devops", "deployment"], keywords_context=["ci", "cd"],
|
||||
),
|
||||
"room_catchall": RoomEntry(
|
||||
room_id="room_catchall", name="#CatchAll",
|
||||
theme="Catch-all", catch_all=True,
|
||||
),
|
||||
}
|
||||
return RoomMap(
|
||||
rooms=rooms,
|
||||
excluded_room_ids=set(),
|
||||
fact_store_path=Path("/tmp/fact_store"),
|
||||
version=5,
|
||||
butler_mode="cognitive",
|
||||
)
|
||||
|
||||
|
||||
def _make_router(room_map: RoomMap, clef_router) -> BidirectionalRouter:
|
||||
classifier = IntentClassifier(embedding_client=MockEmbeddingClient(), llm_client=None)
|
||||
state = ArchivarState(":memory:")
|
||||
state.load()
|
||||
router = BidirectionalRouter(room_map, classifier, state, clef_flash_router=clef_router)
|
||||
router.set_subscribed_room_ids(list(room_map.rooms.keys()))
|
||||
return router
|
||||
|
||||
|
||||
def _mock_clef_router(enabled=True, choice="#BAT-Team", confidence=0.9):
|
||||
"""Mock-ClefFlashRouter mit den nötigen Properties."""
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
mock = MagicMock()
|
||||
mock.enabled = enabled
|
||||
mock.inline_wait_s = 5.0
|
||||
mock.faiss_trigger = 0.85
|
||||
mock.faiss_min_score = 0.55
|
||||
mock.auto_confidence = 0.85
|
||||
mock.recheck_min = 0.50
|
||||
mock.recheck_before_llm = False
|
||||
|
||||
result = ClefFlashResult(choice=choice, confidence=confidence,
|
||||
probabilities={choice: confidence})
|
||||
mock.route = AsyncMock(return_value=result)
|
||||
return mock
|
||||
|
||||
|
||||
def _mock_faiss(top_score=None, top_room_id="room_bat_team"):
|
||||
"""Mock-RoomIndexManager, der einen FAISS-Treffer (oder keinen) liefert."""
|
||||
index = MagicMock()
|
||||
index.is_built = True
|
||||
if top_score is None:
|
||||
index.search_text = MagicMock(return_value=[])
|
||||
else:
|
||||
index.search_text = MagicMock(return_value=[(top_room_id, top_score)])
|
||||
return index
|
||||
|
||||
|
||||
# ── Test 1: FAISS-Logik unangetastet (Flag AUS) ─────────────────────────
|
||||
|
||||
|
||||
class TestFaissUntouched:
|
||||
def test_flag_off_no_clef_flash_call(self):
|
||||
"""CLEF_FLASH_ENABLED=false → kein Clef-Flash-Call, FAISS-Butler bleibt."""
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=False)
|
||||
router = _make_router(room_map, clef)
|
||||
router._room_index = _mock_faiss(top_score=0.70)
|
||||
router._booster = None
|
||||
|
||||
decision = asyncio.run(router.route("BTC Analyse", "room_lan_doku"))
|
||||
|
||||
# Clef Flash darf NICHT aufgerufen worden sein.
|
||||
assert not clef.route.called
|
||||
# FAISS-Butler-Pfad: score 0.70 < 0.85 → Fall-through (kein Auto-Route),
|
||||
# aber kein Clef-Flash-Routing. Decision sollte NICHT von clef_flash stammen.
|
||||
assert decision is not None
|
||||
# is_faiss_routed muss False sein (0.70 < 0.85).
|
||||
assert decision.is_faiss_routed is False
|
||||
|
||||
|
||||
# ── Test 2: Trigger im Score-Band [0.55, 0.85) ───────────────────────────
|
||||
|
||||
|
||||
class TestScoreBandTrigger:
|
||||
def test_score_in_band_triggers_clef_flash(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True, choice="#BAT-Team", confidence=0.9)
|
||||
router = _make_router(room_map, clef)
|
||||
router._room_index = _mock_faiss(top_score=0.70, top_room_id="room_bat_team")
|
||||
router._booster = None
|
||||
|
||||
decision = asyncio.run(router.route("BTC Wyckoff Analyse", "room_lan_doku"))
|
||||
|
||||
assert clef.route.called
|
||||
# Clef Flash routet (Sub-Pfad A) → Butler-Move-Request.
|
||||
assert decision.move_request_sent is True
|
||||
assert decision.target_room == "room_bat_team"
|
||||
assert decision.confidence == pytest.approx(0.9)
|
||||
|
||||
def test_score_below_min_triggers_but_low_confidence_falls_through(self):
|
||||
"""Score im Band, aber Clef-Flash-Confidence unter recheck_min → Fall-through."""
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True, choice="#BAT-Team", confidence=0.3)
|
||||
router = _make_router(room_map, clef)
|
||||
router._room_index = _mock_faiss(top_score=0.60, top_room_id="room_bat_team")
|
||||
router._booster = None
|
||||
|
||||
# Embedding-Vorfilter überspringen + LLM deterministisch auf STAY setzen,
|
||||
# damit der Fall-through-Pfad sauber beobachtbar ist.
|
||||
router._classifier._initialized = False
|
||||
|
||||
async def _mock_llm(text, origin_room_id=""):
|
||||
return None, False, False, "stay", ""
|
||||
|
||||
router._llm_room_lookup = _mock_llm
|
||||
|
||||
decision = asyncio.run(router.route("BTC Analyse", "room_lan_doku"))
|
||||
|
||||
assert clef.route.called
|
||||
# Sub-Pfad C → kein Clef-Flash-Routing.
|
||||
assert decision.move_request_sent is False
|
||||
|
||||
|
||||
# ── Test 3: Kein FAISS-Treffer → Catch-All-Fallback (Trigger 3) ─────────
|
||||
|
||||
|
||||
class TestNoFaissTrigger:
|
||||
def test_no_faiss_hit_triggers_clef_flash(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True, choice="#DevOps", confidence=0.92)
|
||||
router = _make_router(room_map, clef)
|
||||
router._room_index = _mock_faiss(top_score=None) # kein Treffer
|
||||
router._booster = None
|
||||
# classifier nicht initialisiert → Schritt 4 übersprungen, Schritt 5
|
||||
# deterministisch auf STAY, damit Clef Flash der einzige Routing-Pfad ist.
|
||||
router._classifier._initialized = False
|
||||
|
||||
async def _mock_llm(text, origin_room_id=""):
|
||||
return None, False, False, "stay", ""
|
||||
|
||||
router._llm_room_lookup = _mock_llm
|
||||
|
||||
# Text ohne jegliche Keywords, damit Schritt 3/4.5 nicht greifen.
|
||||
decision = asyncio.run(router.route("Der neue Dienst wird produktiv geschaltet", "room_lan_doku"))
|
||||
|
||||
assert clef.route.called
|
||||
assert decision.move_request_sent is True
|
||||
assert decision.target_room == "room_devops"
|
||||
|
||||
|
||||
# ── Test 4: FAISS-Score >= 0.85 → Auto-Route, KEIN Clef Flash ───────────
|
||||
|
||||
|
||||
class TestAutoRouteNoClef:
|
||||
def test_high_faiss_score_auto_routes_without_clef(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
router._room_index = _mock_faiss(top_score=0.90, top_room_id="room_bat_team")
|
||||
router._booster = None
|
||||
|
||||
decision = asyncio.run(router.route("Kursbewegungen und Charts auswerten", "room_lan_doku"))
|
||||
|
||||
# Auto-Route bei >= 0.85 → is_faiss_routed=True, kein Clef-Flash-Call.
|
||||
assert decision.is_faiss_routed is True
|
||||
assert not clef.route.called
|
||||
|
||||
|
||||
# ── Test 5: Kriterien-Aufbau (Origin + Catch-All ausgeschlossen) ─────────
|
||||
|
||||
|
||||
class TestCriteriaBuild:
|
||||
def test_criteria_excludes_origin_and_catch_all(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
|
||||
criteria = router._build_clef_flash_criteria(origin_room_id="room_lan_doku")
|
||||
|
||||
# Catch-All ist nie ein Kriterium.
|
||||
assert "#CatchAll" not in criteria
|
||||
# Origin-Raum ist ausgeschlossen.
|
||||
assert "#LAN-Doku" not in criteria
|
||||
# Übrige Nicht-Catch-All-Räume sind enthalten.
|
||||
assert "#RC-Plugin" in criteria
|
||||
assert "#BAT-Team" in criteria
|
||||
assert "#DevOps" in criteria
|
||||
|
||||
def test_criteria_uses_theme_as_description(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
criteria = router._build_clef_flash_criteria(origin_room_id="room_catchall")
|
||||
assert criteria["#BAT-Team"] == "Trading, Krypto, Wyckoff"
|
||||
|
||||
|
||||
# ── Test 6: Trigger-Helper ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestTriggerHelper:
|
||||
def test_should_trigger_band(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
assert router._should_trigger_clef_flash(0.70) is True
|
||||
assert router._should_trigger_clef_flash(0.55) is True
|
||||
|
||||
def test_should_not_trigger_high(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
assert router._should_trigger_clef_flash(0.85) is False
|
||||
assert router._should_trigger_clef_flash(0.95) is False
|
||||
|
||||
def test_should_trigger_no_faiss(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
assert router._should_trigger_clef_flash(None) is True
|
||||
|
||||
def test_should_not_trigger_below_min(self):
|
||||
room_map = _make_room_map()
|
||||
clef = _mock_clef_router(enabled=True)
|
||||
router = _make_router(room_map, clef)
|
||||
assert router._should_trigger_clef_flash(0.30) is False
|
||||
Reference in New Issue
Block a user