darkplex-core/tests/test_knowledge_extractor.py
Claudia fd7d75c0ed
Some checks failed
Tests / test (push) Failing after 2s
Merge darkplex-core into cortex — unified intelligence layer v0.2.0
- Merged all unique darkplex-core modules into cortex:
  - intelligence/ subfolder (anticipator, collective, shared_memory, knowledge_cleanup, temporal, llm_extractor, loop)
  - governance/ subfolder (policy engine, risk scorer, evidence, enforcer, report generator)
  - entity_manager.py, knowledge_extractor.py
- Fixed bare 'from intelligence.' imports to 'from cortex.intelligence.'
- Added 'darkplex' CLI alias alongside 'cortex'
- Package renamed to darkplex-core v0.2.0
- 405 tests passing (was 234)
- 14 new test files covering all merged modules
2026-02-12 08:43:02 +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 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