darkplex-core/tests/test_knowledge_extractor.py
Claudia c5e5ce9dc0
Some checks failed
Tests / test (push) Failing after 5s
fix: all imports updated to cortex.xxx namespace — 405 tests green
- Fixed bare 'from governance.' imports in source + tests
- Fixed bare 'from intelligence.' imports in tests
- Fixed mock.patch targets to use full cortex.xxx paths
- All 405 tests passing
2026-02-12 08:47:45 +01:00

61 lines
1.9 KiB
Python

"""Tests for knowledge_extractor.py (darkplex-core root) — Smart Extractor."""
import sys
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0, str(Path.home() / "repos" / "darkplex-core"))
from cortex.knowledge_extractor import importance_heuristic, parse_since
class TestImportanceHeuristic:
def test_empty(self):
assert importance_heuristic("") == 0.0
assert importance_heuristic(None) == 0.0
def test_short_text(self):
score = importance_heuristic("Hello world")
assert 0 < score <= 1.0
def test_long_text_boosted(self):
short = importance_heuristic("Hello")
long = importance_heuristic("x " * 300)
assert long > short
def test_heartbeat_penalized(self):
score = importance_heuristic("HEARTBEAT_OK system running fine no issues detected at all")
assert score < 0.3
def test_business_boosted(self):
score = importance_heuristic("Meeting about the project deadline and contract with the client partnership")
assert score > 0.4
def test_capitalized_names_boost(self):
text = "Albert discussed with Thomas, Sarah, Michael, Peter, Franz, and Maria about the Company"
score = importance_heuristic(text)
assert score > 0.4
def test_clamped(self):
# Even extreme texts should be 0-1
score = importance_heuristic("cron: heartbeat HEARTBEAT_OK health check no critical")
assert 0 <= score <= 1.0
class TestParseSince:
def test_hours(self):
ts = parse_since("6h")
assert ts is not None
assert ts > 0
def test_days(self):
ts = parse_since("1d")
assert ts is not None
def test_minutes(self):
ts = parse_since("30m")
assert ts is not None
def test_invalid(self):
assert parse_since("abc") is None
assert parse_since("") is None