Problem
collector/patterns/pattern_detector.py (441 lines) has zero test coverage.
PatternDetector implements cross-session pattern detection with pure logic (no I/O, no async):
detect_all_patterns() — groups by agent, calls per-agent detection
detect_error_rate_trends() — compares baseline vs recent error rates
detect_tool_failure_frequency() — compares tool failure rates
detect_new_failure_modes() — detects new error session patterns
detect_confidence_drops() — replay value drop detection
_calculate_average_error_rate() / _calculate_tool_failure_rate() — metric helpers
Pattern dataclass and to_dict() are also untested.
Scope
Add tests/test_pattern_detector.py covering:
Pattern dataclass
to_dict() roundtrip has all expected keys
Helper methods
- Empty session list returns 0.0
- Error rate: sessions with errors / total sessions
- Tool failure rate: total_errors / total_tool_calls
detect_error_rate_trends()
- No pattern when recent rate <= baseline
- Warning when increase exceeds threshold
- Critical when increase exceeds 2x threshold
- Handles zero baseline rate
detect_tool_failure_frequency()
- No pattern below threshold
- Pattern detected when rate spikes
- Severity escalation to critical
detect_new_failure_modes()
- No pattern when recent errors <= 2x baseline
- Warning when recent exceeds 2x baseline
- Critical when recent exceeds 3x baseline
detect_confidence_drops()
- No pattern when drop is below threshold
- Pattern when replay_value drops significantly
detect_all_patterns()
- Empty list returns empty
- Groups sessions by agent correctly
- Sorts critical before warning
- Returns no patterns when baseline too small (< 3 sessions)
Validation
python3 -m pytest -q tests/test_pattern_detector.py
Problem
collector/patterns/pattern_detector.py(441 lines) has zero test coverage.PatternDetectorimplements cross-session pattern detection with pure logic (no I/O, no async):detect_all_patterns()— groups by agent, calls per-agent detectiondetect_error_rate_trends()— compares baseline vs recent error ratesdetect_tool_failure_frequency()— compares tool failure ratesdetect_new_failure_modes()— detects new error session patternsdetect_confidence_drops()— replay value drop detection_calculate_average_error_rate()/_calculate_tool_failure_rate()— metric helpersPatterndataclass andto_dict()are also untested.Scope
Add
tests/test_pattern_detector.pycovering:Pattern dataclass
to_dict()roundtrip has all expected keysHelper methods
detect_error_rate_trends()
detect_tool_failure_frequency()
detect_new_failure_modes()
detect_confidence_drops()
detect_all_patterns()
Validation