agentic-resources/tests/test_detect_quality.py

62 lines
1.8 KiB
Python
Raw Normal View History

"""Session-quality filter tests (T01)."""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from session_memory.detect.quality import ( # noqa: E402
QualityConfig,
filter_real,
is_real_coding_session,
quality_config,
)
def _digest(repo="agentic-resources", events=60, prompt="Implement the curate entrypoint",
tools=None):
return {
"session_uid": "claude:x", "flavor": "claude", "repo": repo,
"event_count": events, "first_prompt": prompt,
"tool_histogram": tools if tools is not None else {"Bash": 20, "Edit": 15, "Read": 8},
}
def test_real_session_passes():
assert is_real_coding_session(_digest()) is True
def test_healthcheck_prompt_dropped():
assert is_real_coding_session(_digest(events=3, prompt="Say hello in one word.",
tools={})) is False
def test_interrupted_dropped():
assert is_real_coding_session(_digest(events=1, prompt="[Request interrupted by user]",
tools={})) is False
def test_too_short_dropped():
assert is_real_coding_session(_digest(events=5)) is False
def test_no_repo_dropped():
assert is_real_coding_session(_digest(repo=None)) is False
def test_no_substantive_tools_dropped():
# plenty of events but only plumbing calls -> not real coding
assert is_real_coding_session(
_digest(tools={"mcp__state-hub__update_task_status": 40})) is False
def test_filter_real_keeps_only_real():
digs = [_digest(), _digest(events=3, prompt="hello", tools={}), _digest(repo=None)]
assert len(filter_real(digs)) == 1
def test_quality_config_from_toml():
cfg = quality_config({"detect": {"quality": {"min_events": 50}}})
assert cfg.min_events == 50
assert cfg.min_substantive == 3 # default preserved