#[test]
fn test_parser_health_new() {
let health = ParserHealth::new();
assert_eq!(health.total_events, 0);
assert_eq!(health.parsed_events, 0);
assert_eq!(health.ignored_events, 0);
}
#[test]
fn test_parser_health_record_parsed() {
let mut health = ParserHealth::new();
health.record_parsed();
assert_eq!(health.total_events, 1);
assert_eq!(health.parsed_events, 1);
assert_eq!(health.ignored_events, 0);
}
#[test]
fn test_parser_health_record_ignored() {
let mut health = ParserHealth::new();
health.record_ignored();
assert_eq!(health.total_events, 1);
assert_eq!(health.parsed_events, 0);
assert_eq!(health.ignored_events, 1);
}
#[test]
fn test_parser_health_is_concerning() {
let mut health = ParserHealth::new();
for _ in 0..3 {
health.record_ignored();
}
assert!(!health.is_concerning());
for _ in 0..20 {
health.record_unknown_event();
}
assert!(!health.is_concerning());
let mut health2 = ParserHealth::new();
for _ in 0..10 {
health2.record_parsed();
}
for _ in 0..15 {
health2.record_parse_error();
}
assert!(health2.is_concerning());
let mut health3 = ParserHealth::new();
for _ in 0..15 {
health3.record_parsed();
}
for _ in 0..10 {
health3.record_unknown_event();
}
for _ in 0..2 {
health3.record_parse_error();
}
assert!(!health3.is_concerning()); }
#[test]
fn test_parser_health_unknown_events() {
let mut health = ParserHealth::new();
assert_eq!(health.unknown_events, 0);
health.record_unknown_event();
health.record_unknown_event();
assert_eq!(health.unknown_events, 2);
assert_eq!(health.ignored_events, 2); assert_eq!(health.parse_errors, 0);
assert!(!health.is_concerning());
}
#[test]
fn test_health_monitor() {
let monitor = HealthMonitor::new("claude");
monitor.record_parsed();
monitor.record_parsed();
monitor.record_ignored();
let colors = Colors { enabled: false };
assert!(monitor.check_and_warn(colors).is_none());
let fresh_monitor = HealthMonitor::new("claude");
assert!(fresh_monitor.check_and_warn(colors).is_none());
}
#[test]
fn test_health_monitor_warns_once() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..15 {
monitor.record_parse_error();
}
let warning1 = monitor.check_and_warn(colors);
assert!(warning1.is_some());
let warning2 = monitor.check_and_warn(colors);
assert!(warning2.is_none()); }
#[test]
fn test_health_monitor_many_unknown_no_warning() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..2049 {
monitor.record_unknown_event();
}
for _ in 0..53 {
monitor.record_parsed();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none()); }
#[test]
fn test_health_monitor_mixed_unknown_and_parse_errors() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..100 {
monitor.record_unknown_event();
}
for _ in 0..20 {
monitor.record_parse_error();
}
for _ in 0..20 {
monitor.record_parsed();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none());
for _ in 0..30 {
monitor.record_parse_error();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none());
for _ in 0..60 {
monitor.record_parse_error();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none());
for _ in 0..30 {
monitor.record_parse_error();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_some());
}
#[test]
fn test_parser_health_parse_error_percentage() {
let mut health = ParserHealth::new();
assert!((health.parse_error_percentage() - 0.0).abs() < f64::EPSILON);
for _ in 0..5 {
health.record_parse_error();
}
assert!((health.parse_error_percentage() - 100.0).abs() < f64::EPSILON);
let mut health2 = ParserHealth::new();
for _ in 0..5 {
health2.record_parse_error();
}
for _ in 0..5 {
health2.record_parsed();
}
assert!((health2.parse_error_percentage() - 50.0).abs() < f64::EPSILON);
let mut health3 = ParserHealth::new();
for _ in 0..5 {
health3.record_parse_error();
}
for _ in 0..10 {
health3.record_unknown_event();
}
for _ in 0..5 {
health3.record_parsed();
}
assert!((health3.parse_error_percentage() - 25.0).abs() < f64::EPSILON);
}
#[test]
fn test_parser_health_control_events() {
let mut health = ParserHealth::new();
assert_eq!(health.control_events, 0);
health.record_control_event();
health.record_control_event();
health.record_control_event();
assert_eq!(health.control_events, 3);
assert_eq!(health.total_events, 3);
assert_eq!(health.ignored_events, 0);
assert_eq!(health.unknown_events, 0);
assert!(!health.is_concerning());
}
#[test]
fn test_parser_health_control_events_with_other_types() {
let mut health = ParserHealth::new();
for _ in 0..100 {
health.record_control_event();
}
for _ in 0..50 {
health.record_parsed();
}
for _ in 0..30 {
health.record_unknown_event();
}
assert_eq!(health.total_events, 180);
assert_eq!(health.control_events, 100);
assert_eq!(health.parsed_events, 50);
assert_eq!(health.unknown_events, 30);
assert_eq!(health.ignored_events, 30);
assert!(!health.is_concerning());
assert!((health.parse_error_percentage() - 0.0).abs() < f64::EPSILON);
}
#[test]
fn test_health_monitor_control_events() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..2000 {
monitor.record_control_event();
}
for _ in 0..50 {
monitor.record_parsed();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none());
}
#[test]
fn test_health_monitor_warning_includes_control_events() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..15 {
monitor.record_parse_error();
}
for _ in 0..10 {
monitor.record_control_event();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_some());
let warning_text = warning.unwrap();
assert!(warning_text.contains("10 control events"));
}
#[test]
fn test_parser_health_partial_events() {
let mut health = ParserHealth::new();
assert_eq!(health.partial_events, 0);
health.record_partial_event();
health.record_partial_event();
health.record_partial_event();
assert_eq!(health.partial_events, 3);
assert_eq!(health.total_events, 3);
assert_eq!(health.ignored_events, 0);
assert_eq!(health.unknown_events, 0);
assert!(!health.is_concerning());
}
#[test]
fn test_parser_health_partial_events_with_other_types() {
let mut health = ParserHealth::new();
for _ in 0..100 {
health.record_partial_event();
}
for _ in 0..50 {
health.record_control_event();
}
for _ in 0..30 {
health.record_parsed();
}
for _ in 0..20 {
health.record_unknown_event();
}
assert_eq!(health.total_events, 200);
assert_eq!(health.partial_events, 100);
assert_eq!(health.control_events, 50);
assert_eq!(health.parsed_events, 30);
assert_eq!(health.unknown_events, 20);
assert_eq!(health.ignored_events, 20);
assert!(!health.is_concerning());
assert!((health.parse_error_percentage() - 0.0).abs() < f64::EPSILON);
}
#[test]
fn test_health_monitor_partial_events() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..2049 {
monitor.record_partial_event();
}
for _ in 0..53 {
monitor.record_parsed();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_none());
}
#[test]
fn test_health_monitor_warning_includes_partial_events() {
let monitor = HealthMonitor::new("test");
let colors = Colors { enabled: false };
for _ in 0..15 {
monitor.record_parse_error();
}
for _ in 0..10 {
monitor.record_partial_event();
}
for _ in 0..2 {
monitor.record_control_event();
}
let warning = monitor.check_and_warn(colors);
assert!(warning.is_some());
let warning_text = warning.unwrap();
assert!(warning_text.contains("2 control events"));
assert!(warning_text.contains("10 partial events"));
}