feat: V8.5 — P1-Points: 90-Tage-Demotion + ::curate run Routine
This commit is contained in:
+157
-23
@@ -107,10 +107,10 @@ class TestBoostUniqueKeyword:
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# Assert
|
||||
# room_a: 0.80 + 0.05 = 0.85
|
||||
# room_a: 0.80 + 0.10 = 0.90
|
||||
# room_b: 0.75 (unverändert)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.75)
|
||||
|
||||
@@ -128,10 +128,10 @@ class TestBoostUniqueKeyword:
|
||||
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# room_b: 0.75 + 3×0.05 = 0.90
|
||||
# room_b: 0.75 + 3×0.10 + 2×0.05 = 1.15
|
||||
# room_a: 0.80 (kein Keyword-Match)
|
||||
assert result[0][0] == "room_b"
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
assert result[0][1] == pytest.approx(1.15)
|
||||
assert result[1][0] == "room_a"
|
||||
assert result[1][1] == pytest.approx(0.80)
|
||||
|
||||
@@ -146,10 +146,10 @@ class TestBoostUniqueKeyword:
|
||||
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# room_a: 0.70 + 3×0.05 = 0.85
|
||||
# room_a: 0.70 + 3×0.10 + 2×0.05 = 1.10
|
||||
# room_b: 0.80 (gateway ist shared → kein Boost)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(1.10)
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.80)
|
||||
|
||||
@@ -164,10 +164,10 @@ class TestBoostUniqueKeyword:
|
||||
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# room_a: 0.70 + 0.05 = 0.75
|
||||
assert result[0][0] == "room_b" # 0.80 > 0.75
|
||||
assert result[1][0] == "room_a"
|
||||
assert result[1][1] == pytest.approx(0.75)
|
||||
# room_a: 0.70 + 0.10 = 0.80
|
||||
assert result[0][0] == "room_a" # 0.80 == 0.80, room_a hat unique keyword
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.80)
|
||||
|
||||
|
||||
class TestBoostSharedKeyword:
|
||||
@@ -203,10 +203,10 @@ class TestBoostSharedKeyword:
|
||||
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# room_a: 0.80 + 0.05 = 0.85
|
||||
# room_a: 0.80 + 0.10 = 0.90
|
||||
# room_b: 0.75 (gateway shared → kein Boost)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.75)
|
||||
|
||||
@@ -249,7 +249,7 @@ class TestBoostEdgeCases:
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
|
||||
def test_keyword_as_substring(self, booster: KeywordBooster) -> None:
|
||||
"""Keyword-Matching ist substring-basiert (nicht word-boundary)."""
|
||||
@@ -263,7 +263,7 @@ class TestBoostEdgeCases:
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
|
||||
def test_catch_all_keywords_ignored(self, booster: KeywordBooster) -> None:
|
||||
"""Catch-All-Raum hat keine Keywords → nimmt nicht an Boosts teil."""
|
||||
@@ -277,7 +277,7 @@ class TestBoostEdgeCases:
|
||||
|
||||
# room_a bekommt Boost, room_catchall nicht
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
# room_catchall bleibt bei 0.60
|
||||
catchall_score = next(s for rid, s in result if rid == "room_catchall")
|
||||
assert catchall_score == pytest.approx(0.60)
|
||||
@@ -293,7 +293,7 @@ class TestBoostEdgeCases:
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85)
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -378,10 +378,10 @@ class TestConflictResolution:
|
||||
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
# room_a: 0.82 + 0.05 (unique boost) + 0.02 (conflict) = 0.89
|
||||
# room_a: 0.82 + 0.10 (unique boost) + 0.05 (conflict) = 0.97
|
||||
# room_b: 0.87 (gateway shared → kein Boost, 0 unique → kein conflict boost)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.89)
|
||||
assert result[0][1] == pytest.approx(0.97)
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.87)
|
||||
|
||||
@@ -399,7 +399,7 @@ class TestConflictResolution:
|
||||
result = booster.boost(text, scores)
|
||||
|
||||
assert result[0][0] == "room_b"
|
||||
assert result[0][1] == pytest.approx(0.89)
|
||||
assert result[0][1] == pytest.approx(0.97)
|
||||
assert result[1][0] == "room_a"
|
||||
assert result[1][1] == pytest.approx(0.87)
|
||||
|
||||
@@ -472,9 +472,9 @@ class TestConflictResolution:
|
||||
result = booster.boost(text, scores3)
|
||||
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.94)
|
||||
assert result[0][1] == pytest.approx(1.07)
|
||||
assert result[1][0] == "room_b"
|
||||
assert result[1][1] == pytest.approx(0.92)
|
||||
assert result[1][1] == pytest.approx(0.97)
|
||||
|
||||
|
||||
class TestConflictEdgeCases:
|
||||
@@ -495,7 +495,7 @@ class TestConflictEdgeCases:
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.85) # nur unique Boost
|
||||
assert result[0][1] == pytest.approx(0.90) # nur unique Boost
|
||||
|
||||
def test_three_scores_conflict_only_top2(self, booster: KeywordBooster) -> None:
|
||||
"""Bei 3 Scores: Konfliktlösung betrachtet NUR Top-1 und Top-2."""
|
||||
@@ -524,7 +524,7 @@ class TestConflictEdgeCases:
|
||||
("room_b", 0.75),
|
||||
]
|
||||
result_before = booster.boost("plugin bug", scores)
|
||||
assert result_before[0][1] == pytest.approx(0.85)
|
||||
assert result_before[0][1] == pytest.approx(0.90)
|
||||
|
||||
# Ändere RoomMap: füge "plugin" auch zu room_b hinzu
|
||||
room_map = booster._room_map
|
||||
@@ -602,3 +602,137 @@ class TestBoosterCleanup:
|
||||
# "plugin" ist unique für room_a → +0.10 (tatsächlicher Boost-Wert)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# V8.2 A3: 90-Tage-Keyword-Booster-Demotion
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
class TestV82A3RecordMatches:
|
||||
"""V8.2 A3: _record_matches() setzt last_matched-Timestamps."""
|
||||
|
||||
@pytest.fixture
|
||||
def booster(self) -> KeywordBooster:
|
||||
return KeywordBooster(_make_booster_room_map())
|
||||
|
||||
def test_record_matches_sets_timestamp_for_100_keywords(self, booster: KeywordBooster) -> None:
|
||||
"""_record_matches setzt _keyword_last_matched für keywords_100."""
|
||||
# "rocketchat" ist keywords_100 für room_a
|
||||
booster._record_matches("rocketchat websocket", ["rocketchat"])
|
||||
|
||||
entry = booster._room_map.get_room_by_id("room_a")
|
||||
assert entry is not None
|
||||
assert "rocketchat" in entry._keyword_last_matched
|
||||
# Timestamp sollte ISO-Format sein
|
||||
from datetime import datetime
|
||||
ts = entry._keyword_last_matched["rocketchat"]
|
||||
datetime.fromisoformat(ts) # wirft ValueError wenn nicht ISO
|
||||
|
||||
def test_record_matches_skips_context_keywords(self, booster: KeywordBooster) -> None:
|
||||
"""_record_matches tracked NUR keywords_100, nicht keywords_context."""
|
||||
# "plugin" ist keywords_context für room_a (nicht keywords_100)
|
||||
booster._record_matches("plugin bug", ["plugin"])
|
||||
|
||||
entry = booster._room_map.get_room_by_id("room_a")
|
||||
assert entry is not None
|
||||
# "plugin" ist context, nicht 100 → kein Timestamp
|
||||
assert "plugin" not in entry._keyword_last_matched
|
||||
|
||||
def test_record_matches_handles_shared_keyword(self, booster: KeywordBooster) -> None:
|
||||
"""_record_matches tracked shared keywords in allen betroffenen Räumen."""
|
||||
# "gateway" ist keywords_context in room_a UND room_b
|
||||
# → kein keywords_100 → keine Timestamps
|
||||
booster._record_matches("gateway issue", ["gateway"])
|
||||
|
||||
entry_a = booster._room_map.get_room_by_id("room_a")
|
||||
entry_b = booster._room_map.get_room_by_id("room_b")
|
||||
assert "gateway" not in entry_a._keyword_last_matched
|
||||
assert "gateway" not in entry_b._keyword_last_matched
|
||||
|
||||
def test_record_matches_handles_unknown_keyword(self, booster: KeywordBooster) -> None:
|
||||
"""_record_matches mit unbekanntem Keyword → kein Fehler."""
|
||||
# Sollte nicht crashen
|
||||
booster._record_matches("xyz unknown", ["xyz"])
|
||||
# Kein Assert nötig — kein Crash = bestanden
|
||||
|
||||
def test_boost_calls_record_matches(self, booster: KeywordBooster) -> None:
|
||||
"""boost() ruft _record_matches() auf → Timestamps werden gesetzt."""
|
||||
scores: list[tuple[str, float]] = [
|
||||
("room_a", 0.80),
|
||||
("room_b", 0.75),
|
||||
]
|
||||
# "rocketchat" ist keywords_100 für room_a
|
||||
booster.boost("rocketchat plugin", scores)
|
||||
|
||||
entry = booster._room_map.get_room_by_id("room_a")
|
||||
assert "rocketchat" in entry._keyword_last_matched
|
||||
|
||||
|
||||
class TestV82A3BoosterDemotion:
|
||||
"""V8.2 A3: KeywordBooster.demote_stale_keywords() delegiert an RoomMap."""
|
||||
|
||||
@pytest.fixture
|
||||
def booster(self) -> KeywordBooster:
|
||||
return KeywordBooster(_make_booster_room_map())
|
||||
|
||||
def test_demote_stale_delegates_to_room_map(self, booster: KeywordBooster) -> None:
|
||||
"""demote_stale_keywords() delegiert an RoomMap und baut Mapping neu."""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# Setze "rocketchat" (keywords_100 für room_a) auf 91 Tage alt
|
||||
old_date = (datetime.now() - timedelta(days=91)).isoformat()
|
||||
booster._room_map.set_keyword_last_matched("room_a", "rocketchat", old_date)
|
||||
|
||||
# Vorher: "rocketchat" ist im Mapping
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
|
||||
demoted = booster.demote_stale_keywords(max_age_days=90)
|
||||
assert demoted >= 1
|
||||
|
||||
# Nach Demotion: "rocketchat" ist nicht mehr keywords_100
|
||||
entry = booster._room_map.get_room_by_id("room_a")
|
||||
assert "rocketchat" not in entry.keywords_100
|
||||
assert "rocketchat" in entry.keywords_context
|
||||
|
||||
# Mapping wurde neu gebaut → "rocketchat" ist jetzt als context-Keyword im Mapping
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
|
||||
def test_demote_no_stale_returns_zero(self, booster: KeywordBooster) -> None:
|
||||
"""Keine stale Keywords → demote_stale_keywords() gibt 0 zurück."""
|
||||
# Keine last_matched gesetzt → initial, nicht demoten
|
||||
demoted = booster.demote_stale_keywords(max_age_days=90)
|
||||
assert demoted == 0
|
||||
|
||||
def test_demote_rebuilds_mapping(self, booster: KeywordBooster) -> None:
|
||||
"""Nach Demotion: Mapping enthält demoted Keywords als context-Keywords."""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
old_date = (datetime.now() - timedelta(days=100)).isoformat()
|
||||
booster._room_map.set_keyword_last_matched("room_a", "rocketchat", old_date)
|
||||
booster._room_map.set_keyword_last_matched("room_a", "ddp", old_date)
|
||||
|
||||
demoted = booster.demote_stale_keywords(max_age_days=90)
|
||||
assert demoted == 2
|
||||
|
||||
# Beide Keywords sind jetzt im Mapping (als context)
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
assert "ddp" in booster._keyword_to_rooms
|
||||
|
||||
def test_demote_then_boost_still_works(self, booster: KeywordBooster) -> None:
|
||||
"""Nach Demotion: boost() funktioniert korrekt mit neuem Mapping."""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
old_date = (datetime.now() - timedelta(days=100)).isoformat()
|
||||
booster._room_map.set_keyword_last_matched("room_a", "rocketchat", old_date)
|
||||
|
||||
booster.demote_stale_keywords(max_age_days=90)
|
||||
|
||||
# "rocketchat" ist jetzt context-Keyword → unique Boost funktioniert noch
|
||||
scores: list[tuple[str, float]] = [
|
||||
("room_a", 0.80),
|
||||
("room_b", 0.75),
|
||||
]
|
||||
result = booster.boost("rocketchat issue", scores)
|
||||
# room_a bekommt +0.10 (unique keyword, jetzt context)
|
||||
assert result[0][0] == "room_a"
|
||||
assert result[0][1] == pytest.approx(0.90)
|
||||
|
||||
Reference in New Issue
Block a user