#![cfg(feature = "agent-daemon")]
use pmat::agent::mcp_server::{
AgentConfig, ClaudeCodeAgentMcpServer, MonitoredProject, ProjectAnalysisResult,
};
use std::path::PathBuf;
#[test]
fn test_agent_config_default() {
let config = AgentConfig::default();
assert_eq!(config.name, "pmat-agent");
assert_eq!(config.version, "1.0.0");
assert_eq!(config.complexity_threshold, 20); assert_eq!(config.update_interval, 5); assert_eq!(config.max_projects, 10);
assert!(!config.watch_patterns.is_empty());
}
#[test]
fn test_agent_config_default_watch_patterns() {
let config = AgentConfig::default();
assert!(config.watch_patterns.contains(&"**/*.rs".to_string()));
assert!(config.watch_patterns.contains(&"**/*.py".to_string()));
assert!(config.watch_patterns.contains(&"**/*.js".to_string()));
assert!(config.watch_patterns.contains(&"**/*.ts".to_string()));
assert!(config.watch_patterns.contains(&"**/*.java".to_string()));
assert!(config.watch_patterns.contains(&"**/*.go".to_string()));
assert!(config.watch_patterns.contains(&"**/*.cpp".to_string()));
assert!(config.watch_patterns.contains(&"**/*.c".to_string()));
}
#[test]
fn test_agent_config_custom() {
let config = AgentConfig {
name: "custom-agent".to_string(),
version: "2.0.0".to_string(),
complexity_threshold: 15,
watch_patterns: vec!["**/*.rs".to_string()],
update_interval: 10,
max_projects: 5,
};
assert_eq!(config.name, "custom-agent");
assert_eq!(config.version, "2.0.0");
assert_eq!(config.complexity_threshold, 15);
assert_eq!(config.watch_patterns.len(), 1);
assert_eq!(config.update_interval, 10);
assert_eq!(config.max_projects, 5);
}
#[test]
fn test_agent_config_clone() {
let config1 = AgentConfig::default();
let config2 = config1.clone();
assert_eq!(config1.name, config2.name);
assert_eq!(config1.version, config2.version);
assert_eq!(config1.complexity_threshold, config2.complexity_threshold);
}
#[test]
fn test_agent_config_serialization() {
let config = AgentConfig::default();
let json = serde_json::to_string(&config).unwrap();
let deserialized: AgentConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config.name, deserialized.name);
assert_eq!(config.version, deserialized.version);
}
#[test]
fn test_server_creation_default_config() {
let config = AgentConfig::default();
let server = ClaudeCodeAgentMcpServer::new(config.clone());
drop(server);
}
#[test]
fn test_server_creation_custom_config() {
let config = AgentConfig {
name: "test-agent".to_string(),
version: "0.1.0".to_string(),
complexity_threshold: 30,
watch_patterns: vec!["**/*.test.rs".to_string()],
update_interval: 15,
max_projects: 3,
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_server_creation_zero_threshold() {
let config = AgentConfig {
complexity_threshold: 0,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_server_creation_very_high_threshold() {
let config = AgentConfig {
complexity_threshold: u32::MAX,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_server_creation_empty_watch_patterns() {
let config = AgentConfig {
watch_patterns: vec![],
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_server_creation_zero_max_projects() {
let config = AgentConfig {
max_projects: 0,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_server_creation_zero_update_interval() {
let config = AgentConfig {
update_interval: 0,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_monitored_project_creation() {
let project = MonitoredProject {
path: PathBuf::from("/tmp/test"),
name: "test-project".to_string(),
watch_patterns: vec!["**/*.rs".to_string()],
complexity_threshold: 20,
last_analysis: None,
started_at: std::time::SystemTime::now(),
};
assert_eq!(project.name, "test-project");
assert_eq!(project.complexity_threshold, 20);
assert!(project.last_analysis.is_none());
}
#[test]
fn test_monitored_project_clone() {
let project1 = MonitoredProject {
path: PathBuf::from("/tmp/test"),
name: "test".to_string(),
watch_patterns: vec!["**/*.rs".to_string()],
complexity_threshold: 15,
last_analysis: None,
started_at: std::time::SystemTime::now(),
};
let project2 = project1.clone();
assert_eq!(project1.name, project2.name);
assert_eq!(project1.complexity_threshold, project2.complexity_threshold);
}
#[test]
fn test_monitored_project_with_analysis() {
let analysis = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.85,
files_analyzed: 100,
functions_analyzed: 500,
avg_complexity: 5.2,
hotspot_functions: 10,
satd_issues: 5,
quality_gate_status: "PASS".to_string(),
recommendations: vec!["Refactor X".to_string()],
};
let project = MonitoredProject {
path: PathBuf::from("/tmp/test"),
name: "test".to_string(),
watch_patterns: vec![],
complexity_threshold: 20,
last_analysis: Some(analysis),
started_at: std::time::SystemTime::now(),
};
assert!(project.last_analysis.is_some());
assert_eq!(project.last_analysis.unwrap().quality_score, 0.85);
}
#[test]
fn test_project_analysis_result_creation() {
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T12:00:00Z".to_string(),
quality_score: 0.75,
files_analyzed: 50,
functions_analyzed: 250,
avg_complexity: 8.5,
hotspot_functions: 15,
satd_issues: 3,
quality_gate_status: "PASS".to_string(),
recommendations: vec![
"Reduce complexity in module X".to_string(),
"Address TODO comments".to_string(),
],
};
assert_eq!(result.quality_score, 0.75);
assert_eq!(result.files_analyzed, 50);
assert_eq!(result.functions_analyzed, 250);
assert_eq!(result.recommendations.len(), 2);
}
#[test]
fn test_project_analysis_result_serialization() {
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.9,
files_analyzed: 10,
functions_analyzed: 50,
avg_complexity: 3.0,
hotspot_functions: 0,
satd_issues: 0,
quality_gate_status: "PASS".to_string(),
recommendations: vec![],
};
let json = serde_json::to_string(&result).unwrap();
let deserialized: ProjectAnalysisResult = serde_json::from_str(&json).unwrap();
assert_eq!(result.quality_score, deserialized.quality_score);
assert_eq!(result.files_analyzed, deserialized.files_analyzed);
}
#[test]
fn test_project_analysis_result_clone() {
let result1 = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.5,
files_analyzed: 20,
functions_analyzed: 100,
avg_complexity: 10.0,
hotspot_functions: 25,
satd_issues: 10,
quality_gate_status: "FAIL".to_string(),
recommendations: vec!["Fix issues".to_string()],
};
let result2 = result1.clone();
assert_eq!(result1.quality_score, result2.quality_score);
assert_eq!(result1.files_analyzed, result2.files_analyzed);
}
#[test]
fn test_analysis_result_zero_files() {
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.0,
files_analyzed: 0,
functions_analyzed: 0,
avg_complexity: 0.0,
hotspot_functions: 0,
satd_issues: 0,
quality_gate_status: "UNKNOWN".to_string(),
recommendations: vec![],
};
assert_eq!(result.files_analyzed, 0);
assert_eq!(result.functions_analyzed, 0);
}
#[test]
fn test_analysis_result_perfect_score() {
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 1.0,
files_analyzed: 100,
functions_analyzed: 500,
avg_complexity: 1.0,
hotspot_functions: 0,
satd_issues: 0,
quality_gate_status: "PASS".to_string(),
recommendations: vec![],
};
assert_eq!(result.quality_score, 1.0);
assert_eq!(result.hotspot_functions, 0);
}
#[test]
fn test_analysis_result_very_poor_score() {
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.1,
files_analyzed: 50,
functions_analyzed: 200,
avg_complexity: 50.0,
hotspot_functions: 150,
satd_issues: 100,
quality_gate_status: "FAIL".to_string(),
recommendations: vec!["Critical refactoring needed".to_string()],
};
assert_eq!(result.quality_score, 0.1);
assert_eq!(result.hotspot_functions, 150);
}
#[test]
fn test_analysis_result_many_recommendations() {
let recommendations: Vec<String> = (0..100).map(|i| format!("Recommendation {}", i)).collect();
let result = ProjectAnalysisResult {
timestamp: "2025-01-01T00:00:00Z".to_string(),
quality_score: 0.5,
files_analyzed: 50,
functions_analyzed: 250,
avg_complexity: 10.0,
hotspot_functions: 50,
satd_issues: 25,
quality_gate_status: "WARNING".to_string(),
recommendations: recommendations.clone(),
};
assert_eq!(result.recommendations.len(), 100);
}
#[test]
fn test_agent_config_empty_name() {
let config = AgentConfig {
name: "".to_string(),
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_agent_config_empty_version() {
let config = AgentConfig {
version: "".to_string(),
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_agent_config_very_long_name() {
let long_name = "a".repeat(1000);
let config = AgentConfig {
name: long_name.clone(),
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_agent_config_special_characters_in_name() {
let config = AgentConfig {
name: "test-agent!@#$%^&*()".to_string(),
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_agent_config_very_large_max_projects() {
let config = AgentConfig {
max_projects: usize::MAX,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}
#[test]
fn test_agent_config_very_long_update_interval() {
let config = AgentConfig {
update_interval: u64::MAX,
..AgentConfig::default()
};
let server = ClaudeCodeAgentMcpServer::new(config);
drop(server);
}