1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//! CommandDispatcher tests - Part 1: Basic command tests
//! Extracted for file health compliance (CB-040)
use super::*;
#[cfg_attr(coverage_nightly, coverage(off))]
#[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().expect("internal error"))
}
/// Test execute_command with Generate command (tests command routing)
#[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,
};
// Should delegate to handler without panicking
// Note: This will likely fail in actual execution due to missing template
// but tests our routing logic
let result = CommandDispatcher::execute_command(command, server).await;
// We expect this to fail cleanly (not panic)
assert!(result.is_err());
}
/// Test execute_command with List command
#[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;
// List command should succeed with basic server
assert!(result.is_ok());
}
/// Test execute_command with Scaffold::ListTemplates command
#[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;
// ListTemplates should succeed
assert!(result.is_ok());
}
/// Test execute_quality_gate_command (extracted method test)
#[tokio::test]
async fn test_execute_quality_gate_command() {
// OutputFormat already imported
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;
// Quality gate should execute without panicking
// Note: May fail due to actual quality violations but routing works
assert!(result.is_ok() || result.is_err());
}
/// Test execute_report_command (extracted method test)
#[tokio::test]
async fn test_execute_report_command() {
// Toyota Way Root Cause Fix: Use temporary directory to avoid hanging on large codebase
use std::fs;
use tempfile::TempDir;
let temp_dir = TempDir::new().expect("internal error");
let test_file = temp_dir.path().join("test.rs");
fs::write(&test_file, "fn simple() -> i32 { 42 }").expect("internal error");
let analyses = vec![String::from("complexity")];
let result = CommandDispatcher::execute_report_command(
Some(temp_dir.path().to_path_buf()),
OutputFormat::Table,
false,
false,
false,
analyses,
None,
None,
false,
false,
false,
false,
)
.await;
// Report command should execute without panicking
assert!(result.is_ok() || result.is_err());
}
/// Test execute_config_command (extracted method test)
#[tokio::test]
async fn test_execute_config_command() {
let result = CommandDispatcher::execute_config_command(
true, // show
false, // edit
false, // validate
false, // reset
None, // section
None, // set
None, // config_path
)
.await;
// Config show command should succeed
assert!(result.is_ok());
}
/// Test create_test_config (Toyota Way Extract Method test)
#[test]
fn test_create_test_config() {
use crate::cli::commands::TestSuite;
let config = CommandDispatcher::create_test_config(
&TestSuite::All,
100, // iterations
true, // memory
true, // throughput
true, // regression
);
assert_eq!(config.test_iterations, 100);
assert!(config.enable_memory_tests);
assert!(config.enable_throughput_tests);
assert!(config.enable_regression_tests);
}
/// Test create_test_config with specific suite
#[test]
fn test_create_test_config_memory_suite() {
use crate::cli::commands::TestSuite;
let config = CommandDispatcher::create_test_config(
&TestSuite::Memory,
50, // iterations
false, // memory flag (should be enabled by suite)
false, // throughput
false, // regression
);
assert_eq!(config.test_iterations, 50);
assert!(config.enable_memory_tests); // Enabled by TestSuite::Memory
assert!(!config.enable_throughput_tests);
assert!(!config.enable_regression_tests);
}
/// Test print_performance_summary_if_requested (extracted method)
#[test]
fn test_print_performance_summary_if_requested() {
use crate::cli::commands::TestSuite;
use std::time::Duration;
// Test with perf enabled (should not panic)
CommandDispatcher::print_performance_summary_if_requested(
true,
Duration::from_secs(5),
&TestSuite::Memory,
100,
);
// Test with perf disabled (should not print)
CommandDispatcher::print_performance_summary_if_requested(
false,
Duration::from_secs(5),
&TestSuite::Memory,
100,
);
}
/// Test write_test_results_if_requested with no output
#[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, // no output file
&TestSuite::Memory,
Duration::from_secs(5),
100,
&result,
);
// Should succeed without writing anything
assert!(write_result.is_ok());
}
#[test]
fn test_command_dispatcher_basic() {
// Basic test
assert_eq!(1 + 1, 2);
}
}