use super::commands::{QddCommands, RoadmapCommands, ScaffoldCommands};
use super::{AnalyzeCommands, Commands, DemoProtocol, OutputFormat, RefactorCommands};
use crate::cli::handlers;
use crate::cli::handlers::cache::CacheCommand;
use crate::cli::handlers::memory::MemoryCommand;
use crate::stateless_server::StatelessTemplateServer;
use std::path::PathBuf;
use std::sync::Arc;
#[allow(dead_code)]
#[allow(async_fn_in_trait)]
pub trait CommandHandler: Send + Sync {
async fn execute(&self, server: Arc<StatelessTemplateServer>) -> anyhow::Result<()>;
}
#[allow(dead_code)]
#[allow(async_fn_in_trait)]
pub trait AnalyzeCommandHandler: Send + Sync {
async fn execute(&self) -> anyhow::Result<()>;
}
pub struct CommandDispatcher;
impl CommandDispatcher {
pub async fn execute_command(
command: Commands,
server: Arc<StatelessTemplateServer>,
) -> anyhow::Result<()> {
Self::route_command(command, server).await
}
async fn route_command(
command: Commands,
server: Arc<StatelessTemplateServer>,
) -> anyhow::Result<()> {
match command {
Commands::Generate {
category,
template,
params,
output,
create_dirs,
} => {
handlers::handle_generate(server, category, template, params, output, create_dirs)
.await
}
Commands::Scaffold { command } => Self::execute_scaffold_command(command, server).await,
Commands::List {
toolchain,
category,
format,
} => handlers::handle_list(server, toolchain, category, format).await,
Commands::Search {
query,
toolchain,
limit,
} => handlers::handle_search(server, query, toolchain, limit).await,
Commands::Validate { uri, params } => {
handlers::handle_validate(server, uri, params).await
}
Commands::Context {
toolchain,
project_path,
output,
format,
include_large_files,
skip_expensive_metrics,
} => {
handlers::handle_context(
toolchain,
project_path,
output,
format,
include_large_files,
skip_expensive_metrics,
)
.await
}
Commands::Analyze(analyze_cmd) => Self::execute_analyze_command(analyze_cmd).await,
Commands::Qdd(qdd_cmd) => Self::execute_qdd_command(qdd_cmd).await,
Commands::Demo {
path,
url,
repo,
format,
protocol,
show_api,
no_browser,
port,
cli,
target_nodes,
centrality_threshold,
merge_threshold,
debug,
debug_output,
skip_vendor,
no_skip_vendor,
max_line_length,
} => {
Self::execute_demo_command(
path,
url,
repo,
Some(format),
protocol,
show_api,
no_browser,
port.unwrap_or(8080),
cli,
Some(target_nodes),
Some(centrality_threshold),
Some(merge_threshold as f64),
debug,
debug_output,
skip_vendor,
no_skip_vendor,
max_line_length,
server,
)
.await
}
Commands::QualityGate {
project_path,
file,
format,
fail_on_violation,
checks,
max_dead_code,
min_entropy,
max_complexity_p99,
include_provability,
output,
perf,
} => {
let output_format = match format {
crate::cli::enums::QualityGateOutputFormat::Json => OutputFormat::Json,
_ => OutputFormat::Table,
};
let check_strings: Vec<String> = checks
.iter()
.map(|c| format!("{c:?}").to_lowercase())
.collect();
Self::execute_quality_gate_command(
Some(project_path),
file,
output_format,
fail_on_violation,
check_strings,
Some(max_dead_code),
Some(min_entropy),
Some(max_complexity_p99 as usize),
include_provability,
output,
perf,
)
.await
}
Commands::Report {
project_path,
output_format,
include_visualizations,
include_executive_summary,
include_recommendations,
analyses,
confidence_threshold,
output,
perf,
text,
markdown,
csv,
} => {
let internal_format = match output_format {
crate::cli::enums::ReportOutputFormat::Json => OutputFormat::Json,
_ => OutputFormat::Table,
};
let analysis_strings: Vec<String> = analyses
.iter()
.map(|a| format!("{a:?}").to_lowercase())
.collect();
Self::execute_report_command(
Some(project_path),
internal_format,
include_visualizations,
include_executive_summary,
include_recommendations,
analysis_strings,
Some(f64::from(confidence_threshold) / 100.0),
output,
perf,
text,
markdown,
csv,
)
.await
}
Commands::Serve {
port,
host,
cors,
transport,
} => handlers::handle_serve(host, port, cors, transport).await,
Commands::Diagnose(args) => super::diagnose::handle_diagnose(args).await,
Commands::Enforce(enforce_cmd) => handlers::route_enforce_command(enforce_cmd).await,
Commands::Refactor(refactor_cmd) => Self::execute_refactor_command(refactor_cmd).await,
Commands::Roadmap(roadmap_cmd) => Self::execute_roadmap_command(roadmap_cmd).await,
Commands::Test {
suite,
iterations,
memory,
throughput,
regression,
timeout,
output,
perf,
} => {
Self::execute_test_command(
suite, iterations, memory, throughput, regression, timeout, output, perf,
)
.await
}
Commands::Memory { command } => Self::execute_memory_command(command).await,
Commands::Cache { command } => Self::execute_cache_command(command).await,
Commands::Telemetry {
system,
service,
reset,
test_event,
} => {
handlers::telemetry_handlers::handle_telemetry(system, service, reset, test_event)
.await
}
Commands::Config {
show,
edit,
validate,
reset,
section,
set,
config_path,
} => {
Self::execute_config_command(
show,
edit,
validate,
reset,
section,
if set.is_empty() { None } else { Some(set) },
config_path,
)
.await
}
Commands::Agent { command } => handlers::handle_agent_command(command).await,
Commands::Tdg {
path,
command,
format,
config,
quiet,
include_components,
min_grade,
output,
} => {
let tdg_config = handlers::tdg_handlers::TdgCommandConfig {
path,
command,
format,
config,
quiet,
include_components,
min_grade,
output,
};
handlers::handle_tdg_command(tdg_config).await
}
}
}
#[allow(clippy::too_many_arguments)]
async fn execute_demo_command(
path: Option<PathBuf>,
url: Option<String>,
repo: Option<String>,
format: Option<OutputFormat>,
protocol: DemoProtocol,
show_api: bool,
no_browser: bool,
port: u16,
cli: bool,
target_nodes: Option<usize>,
centrality_threshold: Option<f64>,
merge_threshold: Option<f64>,
debug: bool,
debug_output: Option<PathBuf>,
skip_vendor: bool,
no_skip_vendor: bool,
max_line_length: Option<usize>,
server: Arc<StatelessTemplateServer>,
) -> anyhow::Result<()> {
let demo_protocol = Self::convert_demo_protocol(protocol, cli);
let demo_args = Self::create_demo_args(
path,
url,
repo,
format,
demo_protocol,
show_api,
no_browser,
port,
cli,
target_nodes,
centrality_threshold,
merge_threshold,
debug,
debug_output,
skip_vendor,
no_skip_vendor,
max_line_length,
);
crate::demo::run_demo(demo_args, server).await
}
fn convert_demo_protocol(protocol: DemoProtocol, cli: bool) -> crate::demo::Protocol {
if cli {
crate::demo::Protocol::Cli
} else {
match protocol {
DemoProtocol::Cli => crate::demo::Protocol::Cli,
DemoProtocol::Http => crate::demo::Protocol::Http,
DemoProtocol::Mcp => crate::demo::Protocol::Mcp,
#[cfg(feature = "tui")]
DemoProtocol::Tui => crate::demo::Protocol::Tui,
DemoProtocol::All => crate::demo::Protocol::All,
}
}
}
#[allow(clippy::too_many_arguments)]
fn create_demo_args(
path: Option<PathBuf>,
url: Option<String>,
repo: Option<String>,
format: Option<OutputFormat>,
protocol: crate::demo::Protocol,
show_api: bool,
no_browser: bool,
port: u16,
cli: bool,
target_nodes: Option<usize>,
centrality_threshold: Option<f64>,
merge_threshold: Option<f64>,
debug: bool,
debug_output: Option<PathBuf>,
skip_vendor: bool,
no_skip_vendor: bool,
max_line_length: Option<usize>,
) -> crate::demo::DemoArgs {
crate::demo::DemoArgs {
path,
url,
repo,
format: format.unwrap_or(OutputFormat::Table),
protocol,
show_api,
no_browser,
port: Some(port),
web: !cli,
target_nodes: target_nodes.unwrap_or(1000),
centrality_threshold: centrality_threshold.unwrap_or(0.5),
merge_threshold: merge_threshold.map_or(100, |t| t as usize),
debug,
debug_output,
skip_vendor: skip_vendor && !no_skip_vendor,
max_line_length,
}
}
async fn execute_scaffold_command(
command: ScaffoldCommands,
server: Arc<StatelessTemplateServer>,
) -> anyhow::Result<()> {
match command {
ScaffoldCommands::Project {
toolchain,
templates,
params,
parallel,
} => handlers::handle_scaffold(server, toolchain, templates, params, parallel).await,
ScaffoldCommands::Agent {
name,
template,
features,
quality,
output,
force,
dry_run,
interactive,
deterministic_core,
probabilistic_wrapper,
} => {
Self::execute_scaffold_agent_command(
name,
template,
features,
quality,
output,
force,
dry_run,
interactive,
deterministic_core.is_some(),
probabilistic_wrapper.is_some(),
)
.await
}
ScaffoldCommands::ListTemplates => handlers::handle_list_agent_templates().await,
ScaffoldCommands::ValidateTemplate { path } => {
handlers::handle_validate_agent_template(path).await
}
}
}
#[allow(clippy::too_many_arguments)]
async fn execute_scaffold_agent_command(
name: String,
template: String,
features: Vec<String>,
quality: String,
output: Option<PathBuf>,
force: bool,
dry_run: bool,
interactive: bool,
deterministic_core: bool,
probabilistic_wrapper: bool,
) -> anyhow::Result<()> {
let params = handlers::generation_handlers::ScaffoldAgentParams {
name,
template,
features,
quality,
output,
force,
dry_run,
interactive,
deterministic_core: if deterministic_core {
Some("true".to_string())
} else {
None
},
probabilistic_wrapper: if probabilistic_wrapper {
Some("true".to_string())
} else {
None
},
};
handlers::handle_scaffold_agent(params).await
}
pub async fn execute_analyze_command(analyze_cmd: AnalyzeCommands) -> anyhow::Result<()> {
super::handlers::route_analyze_command(analyze_cmd).await
}
pub async fn execute_qdd_command(qdd_cmd: QddCommands) -> anyhow::Result<()> {
super::handlers::qdd_handlers::handle_qdd_command(qdd_cmd).await
}
pub async fn execute_refactor_command(refactor_cmd: RefactorCommands) -> anyhow::Result<()> {
super::handlers::route_refactor_command(refactor_cmd).await
}
pub async fn execute_roadmap_command(roadmap_cmd: RoadmapCommands) -> anyhow::Result<()> {
use crate::roadmap::{self, RoadmapConfig};
use std::path::PathBuf;
let config = RoadmapConfig {
path: PathBuf::from("docs/execution/roadmap.md"),
quality_gates: roadmap::QualityGateConfig {
complexity_max: 20,
coverage_min: 80,
satd_tolerance: 0,
documentation_required: true,
lint_compliance: true,
},
enforce_quality_gates: true,
git: roadmap::GitConfig {
create_branches: true,
branch_pattern: "feature/{task_id}".to_string(),
commit_pattern: "{task_id}: {message}".to_string(),
require_quality_check: true,
},
enabled: true,
auto_generate_todos: true,
require_task_ids: true,
task_id_pattern: "PMAT-[0-9]{4}".to_string(),
tracking: roadmap::TrackingConfig {
velocity_tracking: true,
burndown_charts: true,
quality_metrics: true,
export_format: "json".to_string(),
},
};
let cmd = roadmap::commands::RoadmapCommand {
command: match roadmap_cmd {
RoadmapCommands::Init {
version,
title,
duration_days,
priority,
} => roadmap::commands::RoadmapSubcommand::Init {
version,
title,
duration_days,
priority,
},
RoadmapCommands::Todos {
sprint,
output,
include_quality_gates,
} => roadmap::commands::RoadmapSubcommand::Todos {
sprint,
output,
include_quality_gates,
},
RoadmapCommands::Start {
task_id,
create_branch,
} => roadmap::commands::RoadmapSubcommand::Start {
task_id,
create_branch,
},
RoadmapCommands::Complete {
task_id,
skip_quality_check,
} => roadmap::commands::RoadmapSubcommand::Complete {
task_id,
skip_quality_check,
},
RoadmapCommands::Status {
sprint,
task,
format,
} => {
let output_format = match format {
super::OutputFormat::Json => crate::cli::OutputFormat::Json,
_ => crate::cli::OutputFormat::Table,
};
roadmap::commands::RoadmapSubcommand::Status {
sprint,
task,
format: output_format,
}
}
RoadmapCommands::Validate { sprint, strict } => {
roadmap::commands::RoadmapSubcommand::Validate { sprint, strict }
}
RoadmapCommands::QualityCheck { task_id } => {
roadmap::commands::RoadmapSubcommand::QualityCheck { task_id }
}
},
};
roadmap::commands::execute(cmd, config).await
}
#[allow(clippy::too_many_arguments)]
pub async fn execute_test_command(
suite: super::commands::TestSuite,
iterations: usize,
memory: bool,
throughput: bool,
regression: bool,
timeout: u64,
output: Option<PathBuf>,
perf: bool,
) -> anyhow::Result<()> {
let config = Self::create_test_config(&suite, iterations, memory, throughput, regression);
Self::print_test_startup_info(&suite, iterations, timeout);
let start = std::time::Instant::now();
let test_future = Self::execute_test_suite(&suite, config);
Self::execute_with_timeout_and_reporting(
test_future,
timeout,
start,
&suite,
iterations,
output,
perf,
)
.await
}
pub async fn execute_memory_command(memory_cmd: MemoryCommand) -> anyhow::Result<()> {
super::handlers::handle_memory_command(&memory_cmd).await
}
pub async fn execute_cache_command(cache_cmd: CacheCommand) -> anyhow::Result<()> {
super::handlers::handle_cache_command(&cache_cmd).await
}
#[allow(clippy::too_many_arguments)]
async fn execute_quality_gate_command(
project_path: Option<PathBuf>,
file: Option<PathBuf>,
format: OutputFormat,
fail_on_violation: bool,
checks: Vec<String>,
max_dead_code: Option<f64>,
min_entropy: Option<f64>,
max_complexity_p99: Option<usize>,
include_provability: bool,
output: Option<PathBuf>,
perf: bool,
) -> anyhow::Result<()> {
use crate::cli::enums::{QualityCheckType, QualityGateOutputFormat};
let qg_format = match format {
OutputFormat::Json => QualityGateOutputFormat::Json,
OutputFormat::Table => QualityGateOutputFormat::Summary,
OutputFormat::Yaml => QualityGateOutputFormat::Summary,
};
let quality_checks: Vec<QualityCheckType> = checks
.iter()
.filter_map(|s| match s.as_str() {
"dead_code" | "dead-code" => Some(QualityCheckType::DeadCode),
"complexity" => Some(QualityCheckType::Complexity),
"coverage" => Some(QualityCheckType::Coverage),
"sections" => Some(QualityCheckType::Sections),
"provability" => Some(QualityCheckType::Provability),
"satd" => Some(QualityCheckType::Satd),
"entropy" => Some(QualityCheckType::Entropy),
"security" => Some(QualityCheckType::Security),
"duplicates" => Some(QualityCheckType::Duplicates),
"all" => Some(QualityCheckType::All),
_ => None,
})
.collect();
let max_dead = max_dead_code.unwrap_or(0.1); let min_ent = min_entropy.unwrap_or(0.7); let max_comp = max_complexity_p99.unwrap_or(20) as u32;
handlers::demo_handlers::handle_quality_gate(
project_path.unwrap_or_else(|| PathBuf::from(".")),
file,
qg_format,
fail_on_violation,
quality_checks,
max_dead,
min_ent,
max_comp,
include_provability,
output,
perf,
)
.await
}
#[allow(clippy::too_many_arguments)]
async fn execute_report_command(
project_path: Option<PathBuf>,
output_format: OutputFormat,
include_visualizations: bool,
include_executive_summary: bool,
include_recommendations: bool,
analyses: Vec<String>,
confidence_threshold: Option<f64>,
output: Option<PathBuf>,
perf: bool,
text: bool,
markdown: bool,
csv: bool,
) -> anyhow::Result<()> {
use crate::cli::enums::{AnalysisType, ReportOutputFormat};
let report_format = match output_format {
OutputFormat::Json => ReportOutputFormat::Json,
OutputFormat::Table => ReportOutputFormat::Text,
OutputFormat::Yaml => ReportOutputFormat::Text,
};
let analysis_types: Vec<AnalysisType> = analyses
.iter()
.filter_map(|s| match s.as_str() {
"complexity" => Some(AnalysisType::Complexity),
"dead_code" | "dead-code" => Some(AnalysisType::DeadCode),
"duplication" => Some(AnalysisType::Duplication),
"technical_debt" | "technical-debt" => Some(AnalysisType::TechnicalDebt),
"big_o" | "big-o" => Some(AnalysisType::BigO),
"all" => Some(AnalysisType::All),
_ => None,
})
.collect();
let confidence = (confidence_threshold.unwrap_or(0.8) * 100.0) as u8;
handlers::enhanced_reporting_handlers::handle_generate_report(
project_path.unwrap_or_else(|| PathBuf::from(".")),
report_format,
text,
markdown,
csv,
include_visualizations,
include_executive_summary,
include_recommendations,
analysis_types,
confidence,
output,
perf,
)
.await
}
#[allow(clippy::too_many_arguments)]
async fn execute_config_command(
show: bool,
edit: bool,
validate: bool,
reset: bool,
section: Option<String>,
set: Option<Vec<String>>,
config_path: Option<PathBuf>,
) -> anyhow::Result<()> {
handlers::handle_configuration(
show,
edit,
validate,
reset,
section,
set.unwrap_or_default(),
config_path,
)
.await
}
fn create_test_config(
suite: &super::commands::TestSuite,
iterations: usize,
memory: bool,
throughput: bool,
regression: bool,
) -> crate::test_performance::PerformanceTestConfig {
use crate::cli::commands::TestSuite;
crate::test_performance::PerformanceTestConfig {
enable_regression_tests: regression
|| matches!(suite, TestSuite::Regression | TestSuite::All),
enable_memory_tests: memory || matches!(suite, TestSuite::Memory | TestSuite::All),
enable_throughput_tests: throughput
|| matches!(suite, TestSuite::Throughput | TestSuite::All),
test_iterations: iterations,
}
}
fn print_test_startup_info(
suite: &super::commands::TestSuite,
iterations: usize,
timeout: u64,
) {
println!("Starting Performance Testing Suite (SPECIFICATION.md Section 30)");
println!(
"Suite: {suite:?}, Iterations: {iterations}, Timeout: {timeout}s"
);
}
async fn execute_test_suite(
suite: &super::commands::TestSuite,
config: crate::test_performance::PerformanceTestConfig,
) -> anyhow::Result<()> {
use crate::cli::commands::TestSuite;
use crate::test_performance::run_performance_test_suite;
match suite {
TestSuite::Performance | TestSuite::All => run_performance_test_suite(config).await,
TestSuite::Regression => Self::execute_regression_tests(config).await,
TestSuite::Memory => Self::execute_memory_tests(config).await,
TestSuite::Throughput => Self::execute_throughput_tests(config).await,
TestSuite::Property => Self::execute_property_tests().await,
TestSuite::Integration => Self::execute_integration_tests().await,
}
}
async fn execute_regression_tests(
config: crate::test_performance::PerformanceTestConfig,
) -> anyhow::Result<()> {
if config.enable_regression_tests {
println!("Running regression tests...");
crate::test_performance::test_performance_regression_detection().await?;
println!("Regression tests passed!");
}
Ok(())
}
async fn execute_memory_tests(
config: crate::test_performance::PerformanceTestConfig,
) -> anyhow::Result<()> {
if config.enable_memory_tests {
println!("Running memory tests...");
crate::test_performance::test_memory_usage_patterns().await?;
println!("Memory tests passed!");
}
Ok(())
}
async fn execute_throughput_tests(
config: crate::test_performance::PerformanceTestConfig,
) -> anyhow::Result<()> {
if config.enable_throughput_tests {
println!("Running throughput tests...");
crate::test_performance::test_single_threaded_throughput().await?;
crate::test_performance::test_realistic_project_analysis().await?;
crate::test_performance::test_large_file_performance().await?;
println!("Throughput tests passed!");
}
Ok(())
}
async fn execute_property_tests() -> anyhow::Result<()> {
println!("🧪 Running property-based test suite...");
println!("This validates code properties with generated test cases");
use std::process::Command;
let output = Command::new("cargo")
.arg("test")
.arg("--package")
.arg("pmat")
.arg("--lib")
.arg("--")
.arg("property")
.output()?;
if output.status.success() {
println!("✅ Property tests completed successfully");
Ok(())
} else {
anyhow::bail!("Property tests failed")
}
}
async fn execute_integration_tests() -> anyhow::Result<()> {
println!("🔗 Running integration test suite...");
println!("This validates component interactions and system behavior");
use std::path::Path;
if !Path::new("tests/integration.rs").exists() {
println!("ℹ️ No separate integration test file found");
println!("✅ Integration tests are embedded in unit tests");
return Ok(());
}
use std::process::Command;
let output = Command::new("cargo")
.arg("test")
.arg("--package")
.arg("pmat")
.arg("--test")
.arg("integration")
.output()?;
if output.status.success() {
println!("✅ Integration tests completed successfully");
Ok(())
} else {
anyhow::bail!("Integration tests failed")
}
}
#[allow(clippy::too_many_arguments)]
async fn execute_with_timeout_and_reporting(
test_future: impl std::future::Future<Output = anyhow::Result<()>>,
timeout: u64,
start: std::time::Instant,
suite: &super::commands::TestSuite,
iterations: usize,
output: Option<PathBuf>,
perf: bool,
) -> anyhow::Result<()> {
let timeout_duration = std::time::Duration::from_secs(timeout);
if let Ok(result) = tokio::time::timeout(timeout_duration, test_future).await {
let elapsed = start.elapsed();
Self::print_performance_summary_if_requested(perf, elapsed, suite, iterations);
Self::write_test_results_if_requested(output, suite, elapsed, iterations, &result)?;
result
} else {
eprintln!("Test execution timed out after {timeout}s");
anyhow::bail!("Performance tests timed out");
}
}
fn print_performance_summary_if_requested(
perf: bool,
elapsed: std::time::Duration,
suite: &super::commands::TestSuite,
iterations: usize,
) {
if perf {
println!("\nPerformance Summary:");
println!(" Total execution time: {elapsed:?}");
println!(" Suite: {suite:?}");
println!(" Iterations: {iterations}");
}
}
fn write_test_results_if_requested(
output: Option<PathBuf>,
suite: &super::commands::TestSuite,
elapsed: std::time::Duration,
iterations: usize,
result: &anyhow::Result<()>,
) -> anyhow::Result<()> {
if let Some(output_path) = output {
let results = format!(
"Performance Test Results\n\
======================\n\
Suite: {:?}\n\
Execution time: {:?}\n\
Iterations: {}\n\
Status: {}\n",
suite,
elapsed,
iterations,
if result.is_ok() { "PASSED" } else { "FAILED" }
);
std::fs::write(&output_path, results)?;
println!("Results written to: {}", output_path.display());
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::commands::{Commands, ScaffoldCommands};
use crate::stateless_server::StatelessTemplateServer;
use std::sync::Arc;
fn create_test_server() -> Arc<StatelessTemplateServer> {
Arc::new(StatelessTemplateServer::new().unwrap())
}
#[tokio::test]
async fn test_execute_command_generate() {
let server = create_test_server();
let command = Commands::Generate {
category: String::new(),
template: "test_template".to_string(),
params: Vec::new(),
output: None,
create_dirs: false,
};
let result = CommandDispatcher::execute_command(command, server).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_execute_command_list() {
let server = create_test_server();
let command = Commands::List {
toolchain: None,
category: None,
format: OutputFormat::Table,
};
let result = CommandDispatcher::execute_command(command, server).await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_execute_command_scaffold_list() {
let server = create_test_server();
let command = Commands::Scaffold {
command: ScaffoldCommands::ListTemplates,
};
let result = CommandDispatcher::execute_command(command, server).await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_execute_quality_gate_command() {
use std::path::PathBuf;
let result = CommandDispatcher::execute_quality_gate_command(
Some(PathBuf::from(".")),
None,
OutputFormat::Table,
false,
vec!["complexity".to_string()],
None,
None,
None,
false,
None,
false,
)
.await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_execute_report_command() {
use std::path::PathBuf;
let analyses = vec![String::from("complexity")];
let result = CommandDispatcher::execute_report_command(
Some(PathBuf::from(".")),
OutputFormat::Table,
false,
false,
false,
analyses,
None,
None,
false,
false,
false,
false,
)
.await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_execute_config_command() {
let result = CommandDispatcher::execute_config_command(
true, false, false, false, None, None, None, )
.await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_execute_property_tests() {
let result = CommandDispatcher::execute_property_tests().await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_execute_integration_tests() {
let result = CommandDispatcher::execute_integration_tests().await;
assert!(result.is_ok());
}
#[test]
fn test_create_test_config() {
use crate::cli::commands::TestSuite;
let config = CommandDispatcher::create_test_config(
&TestSuite::All,
100, true, true, true, );
assert_eq!(config.test_iterations, 100);
assert!(config.enable_memory_tests);
assert!(config.enable_throughput_tests);
assert!(config.enable_regression_tests);
}
#[test]
fn test_create_test_config_memory_suite() {
use crate::cli::commands::TestSuite;
let config = CommandDispatcher::create_test_config(
&TestSuite::Memory,
50, false, false, false, );
assert_eq!(config.test_iterations, 50);
assert!(config.enable_memory_tests); assert!(!config.enable_throughput_tests);
assert!(!config.enable_regression_tests);
}
#[test]
fn test_print_performance_summary_if_requested() {
use crate::cli::commands::TestSuite;
use std::time::Duration;
CommandDispatcher::print_performance_summary_if_requested(
true,
Duration::from_secs(5),
&TestSuite::Memory,
100,
);
CommandDispatcher::print_performance_summary_if_requested(
false,
Duration::from_secs(5),
&TestSuite::Memory,
100,
);
}
#[test]
fn test_write_test_results_no_output() {
use crate::cli::commands::TestSuite;
use std::time::Duration;
let result: anyhow::Result<()> = Ok(());
let write_result = CommandDispatcher::write_test_results_if_requested(
None, &TestSuite::Memory,
Duration::from_secs(5),
100,
&result,
);
assert!(write_result.is_ok());
}
#[test]
fn test_command_dispatcher_basic() {
assert_eq!(1 + 1, 2);
}
}
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}