rustqual 0.5.2

Comprehensive Rust code quality analyzer — six dimensions: Complexity, Coupling, DRY, IOSP, SRP, Test Quality
Documentation
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
mod analyzer;
mod cli;
mod config;
mod coupling;
mod dry;
mod findings;
mod normalize;
mod pipeline;
mod report;
mod scope;
mod srp;
mod structural;
mod tq;
mod watch;

use std::path::Path;

use clap::{CommandFactory, Parser};

use cli::{Cli, OutputFormat};
use config::Config;

/// Determine output format from CLI flags.
/// Operation: conditional logic.
fn determine_output_format(cli: &Cli) -> OutputFormat {
    if let Some(ref fmt) = cli.format {
        fmt.clone()
    } else if cli.json {
        OutputFormat::Json
    } else {
        OutputFormat::Text
    }
}

/// Handle the --init command: write a rustqual.toml config file.
/// Operation: logic to check file existence and write.
fn handle_init(content: &str) -> Result<(), i32> {
    let path = Path::new("rustqual.toml");
    if path.exists() {
        eprintln!("Error: rustqual.toml already exists in the current directory.");
        return Err(1);
    }
    match std::fs::write(path, content) {
        Ok(()) => {
            eprintln!("Created rustqual.toml with tailored configuration.");
            Ok(())
        }
        Err(e) => {
            eprintln!("Error writing rustqual.toml: {e}");
            Err(1)
        }
    }
}

/// Handle the --completions command: generate shell completions.
/// Integration: orchestrates clap_complete::generate with Cli::command.
fn handle_completions(shell: clap_complete::Shell) {
    clap_complete::generate(
        shell,
        &mut Cli::command(),
        "rustqual",
        &mut std::io::stdout(),
    );
}

/// Load config from an explicit config file path.
/// Operation: error handling logic.
fn load_explicit_config(config_path: &Path) -> Result<Config, i32> {
    match std::fs::read_to_string(config_path) {
        Ok(content) => match toml::from_str(&content) {
            Ok(c) => Ok(c),
            Err(e) => {
                eprintln!("Error parsing config: {e}");
                Err(2)
            }
        },
        Err(e) => {
            eprintln!("Error reading config: {e}");
            Err(2)
        }
    }
}

/// Load config via auto-discovery from the project path.
/// Operation: error mapping logic.
fn load_auto_config(path: &Path) -> Result<Config, i32> {
    Config::load(path).map_err(|e| {
        eprintln!("Error: {e}");
        2
    })
}

/// Load configuration from CLI args or auto-discovery.
/// Integration: delegates to load_explicit_config or load_auto_config.
fn load_config(cli: &Cli) -> Result<Config, i32> {
    cli.config
        .as_ref()
        .map(|p| load_explicit_config(p))
        .unwrap_or_else(|| load_auto_config(&cli.path))
}

/// Load, compile, and apply CLI overrides to config.
/// Integration: orchestrates load_config, compile, apply_cli_overrides, validate_weights.
fn setup_config(cli: &Cli) -> Result<Config, i32> {
    let mut config = load_config(cli)?;
    config.compile();
    apply_cli_overrides(&mut config, cli);
    validate_config_weights(&config)?;
    Ok(config)
}

/// Validate config settings that require cross-field checks.
/// Operation: error mapping logic.
fn validate_config_weights(config: &Config) -> Result<(), i32> {
    config::validate_weights(config).map_err(|e| {
        eprintln!("Error: {e}");
        2
    })
}

/// Apply CLI flag overrides to config.
/// Operation: conditional logic on CLI flags.
fn apply_cli_overrides(config: &mut Config, cli: &Cli) {
    if cli.strict_closures {
        config.strict_closures = true;
    }
    if cli.strict_iterators {
        config.strict_iterator_chains = true;
    }
    if cli.allow_recursion {
        config.allow_recursion = true;
    }
    if cli.strict_error_propagation {
        config.strict_error_propagation = true;
    }
    if cli.fail_on_warnings {
        config.fail_on_warnings = true;
    }
    if let Some(ref coverage) = cli.coverage {
        config.test.coverage_file = Some(coverage.display().to_string());
    }
}

/// Handle --save-baseline: write results to a JSON file.
/// Operation: serialization + file write logic.
fn handle_save_baseline(
    path: &Path,
    all_results: &[analyzer::FunctionAnalysis],
    summary: &report::Summary,
) -> Result<(), i32> {
    let baseline = report::create_baseline(all_results, summary);
    match std::fs::write(path, baseline) {
        Ok(()) => {
            eprintln!("Baseline saved to {}", path.display());
            Ok(())
        }
        Err(e) => {
            eprintln!("Error saving baseline: {e}");
            Err(1)
        }
    }
}

/// Handle --compare: compare current results against baseline.
/// Operation: file read + comparison logic.
fn handle_compare(
    path: &Path,
    all_results: &[analyzer::FunctionAnalysis],
    summary: &report::Summary,
) -> Result<bool, i32> {
    let baseline_content = std::fs::read_to_string(path).map_err(|e| {
        eprintln!("Error reading baseline: {e}");
        1
    })?;
    Ok(report::print_comparison(
        &baseline_content,
        all_results,
        summary,
    ))
}

/// Check --min-quality-score gate.
/// Operation: conditional check.
fn check_min_quality_score(min_score: f64, summary: &report::Summary) -> Result<(), i32> {
    let actual = summary.quality_score * analyzer::PERCENTAGE_MULTIPLIER;
    if actual < min_score {
        eprintln!(
            "Quality score {:.1}% is below minimum {:.1}%",
            actual, min_score,
        );
        return Err(1);
    }
    Ok(())
}

/// Print a stderr warning if the suppression ratio exceeds the configured maximum.
/// Operation: conditional formatting logic.
fn warn_suppression_ratio(summary: &report::Summary, max_ratio: f64) {
    if !summary.suppression_ratio_exceeded || summary.total == 0 {
        return;
    }
    eprintln!(
        "Warning: {} suppression(s) found ({:.1}% of functions, max: {:.1}%)",
        summary.all_suppressions,
        summary.all_suppressions as f64 / summary.total as f64 * analyzer::PERCENTAGE_MULTIPLIER,
        max_ratio * analyzer::PERCENTAGE_MULTIPLIER,
    );
}

/// Check --fail-on-warnings gate.
/// Operation: conditional check.
fn check_fail_on_warnings(config: &Config, summary: &report::Summary) -> Result<(), i32> {
    if config.fail_on_warnings && summary.suppression_ratio_exceeded {
        eprintln!("Error: warnings present and --fail-on-warnings is set");
        return Err(1);
    }
    Ok(())
}

/// Apply quality gate checks from CLI flags.
/// Integration: dispatches to check_min_quality_score.
fn check_quality_gates(cli: &Cli, summary: &report::Summary) -> Result<(), i32> {
    cli.min_quality_score
        .iter()
        .try_for_each(|&s| check_min_quality_score(s, summary))
}

/// Check default-fail gate: exit 1 on findings unless --no-fail.
/// Operation: conditional check.
fn check_default_fail(no_fail: bool, total_findings: usize) -> Result<(), i32> {
    if !no_fail && total_findings > 0 {
        return Err(1);
    }
    Ok(())
}

/// Apply all exit gates: warnings, fail-on-warnings, quality gates, default-fail.
/// Integration: dispatches to warning + gate check functions.
fn apply_exit_gates(cli: &Cli, config: &Config, summary: &report::Summary) -> Result<(), i32> {
    warn_suppression_ratio(summary, config.max_suppression_ratio);
    check_fail_on_warnings(config, summary)?;
    check_quality_gates(cli, summary)?;
    check_default_fail(cli.no_fail, summary.total_findings())
}

/// Sort results so violations come first, ordered by effort score (highest first).
/// Operation: sorting logic.
fn sort_by_effort(results: &mut [analyzer::FunctionAnalysis]) {
    results.sort_by(|a, b| {
        b.effort_score
            .unwrap_or(0.0)
            .partial_cmp(&a.effort_score.unwrap_or(0.0))
            .unwrap_or(std::cmp::Ordering::Equal)
    });
}

/// Entry point: parse CLI, load config, run analysis, check gates.
pub fn run() -> Result<(), i32> {
    let mut args: Vec<String> = std::env::args().collect();
    // Support `cargo qual` invocation: cargo passes "qual" as first arg
    if args.len() > 1 && args[1] == "qual" {
        args.remove(1);
    }
    let mut cli = Cli::parse_from(args);
    // Normalize Windows backslash paths to forward slashes
    let normalized = cli.path.to_string_lossy().replace('\\', "/");
    cli.path = std::path::PathBuf::from(normalized);

    if cli.init {
        let files = pipeline::collect_rust_files(&cli.path);
        let content = if files.is_empty() {
            config::generate_default_config().to_string()
        } else {
            let parsed = pipeline::read_and_parse_files(&files, &cli.path);
            let default_config = Config::default();
            let scope_refs: Vec<(&str, &syn::File)> =
                parsed.iter().map(|(p, _, f)| (p.as_str(), f)).collect();
            let scope = scope::ProjectScope::from_files(&scope_refs);
            let analyzer_obj = analyzer::Analyzer::new(&default_config, &scope);
            let all_results: Vec<_> = parsed
                .iter()
                .flat_map(|(path, _, syntax)| analyzer_obj.analyze_file(syntax, path))
                .collect();
            let metrics = config::init::extract_init_metrics(files.len(), &all_results);
            config::generate_tailored_config(&metrics)
        };
        return handle_init(&content);
    }
    if let Some(shell) = cli.completions {
        handle_completions(shell);
        return Ok(());
    }

    let output_format = determine_output_format(&cli);
    let config = setup_config(&cli)?;

    if cli.watch {
        return watch::run_watch_mode(&cli, &config, &output_format);
    }

    let files = pipeline::collect_filtered_files(&cli.path, &config);
    let files = if let Some(ref git_ref) = cli.diff {
        match pipeline::get_git_changed_files(&cli.path, git_ref) {
            Ok(changed) => {
                let filtered = pipeline::filter_to_changed(files, &changed);
                eprintln!(
                    "[diff mode: {} changed file(s) vs {git_ref}]",
                    filtered.len()
                );
                filtered
            }
            Err(e) => {
                eprintln!("Warning: {e}. Analyzing all files.");
                files
            }
        }
    } else {
        files
    };
    if files.is_empty() {
        eprintln!("No Rust source files found in {}", cli.path.display());
        return Ok(());
    }

    let parsed = pipeline::read_and_parse_files(&files, &cli.path);
    let mut analysis = pipeline::run_analysis(&parsed, &config);
    if cli.sort_by_effort {
        sort_by_effort(&mut analysis.results);
    }
    if cli.findings {
        let entries = crate::report::findings_list::collect_all_findings(&analysis);
        if entries.is_empty() {
            println!("No findings.");
        } else {
            crate::report::findings_list::print_findings(&entries);
        }
    } else {
        pipeline::output_results(
            &analysis,
            &output_format,
            cli.verbose,
            cli.suggestions,
            &config.coupling,
        );
    }

    cli.save_baseline
        .as_ref()
        .map(|p| handle_save_baseline(p, &analysis.results, &analysis.summary))
        .transpose()?;
    if let Some(ref compare_path) = cli.compare {
        let regressed = handle_compare(compare_path, &analysis.results, &analysis.summary)?;
        if cli.fail_on_regression && regressed {
            return Err(1);
        }
    }

    apply_exit_gates(&cli, &config, &analysis.summary)
}

#[cfg(test)]
mod tests {
    use super::*;

    // ── OutputFormat tests ──────────────────────────────────────

    #[test]
    fn test_output_format_text() {
        assert_eq!("text".parse::<OutputFormat>().unwrap(), OutputFormat::Text);
    }

    #[test]
    fn test_output_format_json() {
        assert_eq!("json".parse::<OutputFormat>().unwrap(), OutputFormat::Json);
    }

    #[test]
    fn test_output_format_github() {
        assert_eq!(
            "github".parse::<OutputFormat>().unwrap(),
            OutputFormat::Github
        );
    }

    #[test]
    fn test_output_format_dot() {
        assert_eq!("dot".parse::<OutputFormat>().unwrap(), OutputFormat::Dot);
    }

    #[test]
    fn test_output_format_sarif() {
        assert_eq!(
            "sarif".parse::<OutputFormat>().unwrap(),
            OutputFormat::Sarif
        );
    }

    #[test]
    fn test_output_format_html() {
        assert_eq!("html".parse::<OutputFormat>().unwrap(), OutputFormat::Html);
    }

    #[test]
    fn test_output_format_case_insensitive() {
        assert_eq!("JSON".parse::<OutputFormat>().unwrap(), OutputFormat::Json);
        assert_eq!("Text".parse::<OutputFormat>().unwrap(), OutputFormat::Text);
        assert_eq!(
            "GITHUB".parse::<OutputFormat>().unwrap(),
            OutputFormat::Github
        );
    }

    #[test]
    fn test_output_format_invalid() {
        assert!("xml".parse::<OutputFormat>().is_err());
        assert!("csv".parse::<OutputFormat>().is_err());
    }

    #[test]
    fn test_output_format_default() {
        assert_eq!(OutputFormat::default(), OutputFormat::Text);
    }

    // ── CLI override tests ──────────────────────────────────────

    #[test]
    fn test_apply_cli_overrides_strict_closures() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test", "--strict-closures"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(config.strict_closures);
    }

    #[test]
    fn test_apply_cli_overrides_allow_recursion() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test", "--allow-recursion"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(config.allow_recursion);
    }

    #[test]
    fn test_apply_cli_overrides_strict_error_propagation() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test", "--strict-error-propagation"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(config.strict_error_propagation);
    }

    #[test]
    fn test_apply_cli_overrides_strict_iterators() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test", "--strict-iterators"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(config.strict_iterator_chains);
    }

    #[test]
    fn test_apply_cli_overrides_no_flags() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(!config.strict_closures);
        assert!(!config.strict_iterator_chains);
        assert!(!config.allow_recursion);
        assert!(!config.strict_error_propagation);
    }

    #[test]
    fn test_fail_on_warnings_cli_parse() {
        let cli = Cli::parse_from(["test", "--fail-on-warnings"]);
        assert!(cli.fail_on_warnings);
    }

    #[test]
    fn test_fail_on_warnings_default_false() {
        let cli = Cli::parse_from(["test"]);
        assert!(!cli.fail_on_warnings);
    }

    #[test]
    fn test_apply_cli_overrides_fail_on_warnings() {
        let mut config = Config::default();
        let cli = Cli::parse_from(["test", "--fail-on-warnings"]);
        apply_cli_overrides(&mut config, &cli);
        assert!(config.fail_on_warnings);
    }

    #[test]
    fn test_fail_on_warnings_config_default() {
        let config = Config::default();
        assert!(!config.fail_on_warnings);
    }

    // ── Gate function tests (Result-based) ─────────────────────

    #[test]
    fn test_check_fail_on_warnings_passes_when_no_warnings() {
        let mut config = Config::default();
        config.fail_on_warnings = true;
        let summary = crate::report::Summary {
            total: 10,
            ..Default::default()
        };
        assert!(check_fail_on_warnings(&config, &summary).is_ok());
    }

    #[test]
    fn test_check_fail_on_warnings_passes_when_disabled() {
        let config = Config::default(); // fail_on_warnings = false
        let summary = crate::report::Summary {
            total: 10,
            suppression_ratio_exceeded: true,
            ..Default::default()
        };
        assert!(check_fail_on_warnings(&config, &summary).is_ok());
    }

    #[test]
    fn test_check_fail_on_warnings_exits_when_triggered() {
        let mut config = Config::default();
        config.fail_on_warnings = true;
        let summary = crate::report::Summary {
            total: 10,
            suppression_ratio_exceeded: true,
            ..Default::default()
        };
        assert_eq!(check_fail_on_warnings(&config, &summary), Err(1));
    }

    #[test]
    fn test_min_quality_score_cli_parse() {
        let cli = Cli::parse_from(["test", "--min-quality-score", "80.0"]);
        assert!((cli.min_quality_score.unwrap() - 80.0).abs() < f64::EPSILON);
    }

    #[test]
    fn test_check_quality_gates_passes() {
        let cli = Cli::parse_from(["test", "--min-quality-score", "50.0"]);
        let mut summary = crate::report::Summary {
            total: 10,
            iosp_score: 1.0,
            ..Default::default()
        };
        summary.compute_quality_score(&crate::config::sections::DEFAULT_QUALITY_WEIGHTS);
        assert!(check_quality_gates(&cli, &summary).is_ok());
    }

    #[test]
    fn test_check_min_quality_score_below_threshold() {
        let mut summary = crate::report::Summary {
            total: 10,
            ..Default::default()
        };
        summary.quality_score = 0.5;
        assert_eq!(check_min_quality_score(90.0, &summary), Err(1));
    }

    #[test]
    fn test_check_min_quality_score_above_threshold() {
        let mut summary = crate::report::Summary {
            total: 10,
            ..Default::default()
        };
        summary.quality_score = 0.95;
        assert!(check_min_quality_score(90.0, &summary).is_ok());
    }

    #[test]
    fn test_check_quality_gates_below_threshold() {
        let cli = Cli::parse_from(["test", "--min-quality-score", "90.0"]);
        let summary = crate::report::Summary {
            total: 10,
            quality_score: 0.5,
            ..Default::default()
        };
        assert_eq!(check_quality_gates(&cli, &summary), Err(1));
    }

    #[test]
    fn test_check_quality_gates_no_gate_set() {
        let cli = Cli::parse_from(["test"]);
        let summary = crate::report::Summary {
            total: 10,
            ..Default::default()
        };
        assert!(check_quality_gates(&cli, &summary).is_ok());
    }

    #[test]
    fn test_check_default_fail_with_findings() {
        assert_eq!(check_default_fail(false, 5), Err(1));
    }

    #[test]
    fn test_check_default_fail_no_fail_mode() {
        assert!(check_default_fail(true, 5).is_ok());
    }

    #[test]
    fn test_check_default_fail_no_findings() {
        assert!(check_default_fail(false, 0).is_ok());
    }

    #[test]
    fn test_determine_output_format_explicit() {
        let cli = Cli::parse_from(["test", "--format", "json"]);
        assert_eq!(determine_output_format(&cli), OutputFormat::Json);
    }

    #[test]
    fn test_determine_output_format_json_flag() {
        let cli = Cli::parse_from(["test", "--json"]);
        assert_eq!(determine_output_format(&cli), OutputFormat::Json);
    }

    #[test]
    fn test_determine_output_format_default_text() {
        let cli = Cli::parse_from(["test"]);
        assert_eq!(determine_output_format(&cli), OutputFormat::Text);
    }

    #[test]
    fn test_determine_output_format_explicit_overrides_json_flag() {
        let cli = Cli::parse_from(["test", "--json", "--format", "html"]);
        assert_eq!(determine_output_format(&cli), OutputFormat::Html);
    }

    // ── Init metrics tests ────────────────────────────────────────

    #[test]
    fn test_extract_init_metrics_empty() {
        let m = config::init::extract_init_metrics(0, &[]);
        assert_eq!(m.file_count, 0);
        assert_eq!(m.function_count, 0);
        assert_eq!(m.max_cognitive, 0);
    }

    #[test]
    fn test_extract_init_metrics_with_complexity() {
        let fa = crate::analyzer::FunctionAnalysis {
            name: "f".into(),
            file: "test.rs".into(),
            line: 1,
            classification: crate::analyzer::Classification::Operation,
            parent_type: None,
            suppressed: false,
            complexity: Some(crate::analyzer::ComplexityMetrics {
                cognitive_complexity: 12,
                cyclomatic_complexity: 8,
                max_nesting: 3,
                function_lines: 45,
                ..Default::default()
            }),
            qualified_name: "f".into(),
            severity: None,
            cognitive_warning: false,
            cyclomatic_warning: false,
            nesting_depth_warning: false,
            function_length_warning: false,
            unsafe_warning: false,
            error_handling_warning: false,
            complexity_suppressed: false,
            own_calls: vec![],
            parameter_count: 0,
            is_trait_impl: false,
            is_test: false,
            effort_score: None,
        };
        let results = vec![fa];
        let m = config::init::extract_init_metrics(5, &results);
        assert_eq!(m.file_count, 5);
        assert_eq!(m.function_count, 1);
        assert_eq!(m.max_cognitive, 12);
        assert_eq!(m.max_cyclomatic, 8);
        assert_eq!(m.max_nesting_depth, 3);
        assert_eq!(m.max_function_lines, 45);
    }

    // ── Diff CLI flag tests ──────────────────────────────────────

    #[test]
    fn test_diff_cli_default_ref() {
        let cli = Cli::parse_from(["test", "--diff"]);
        assert_eq!(cli.diff.as_deref(), Some("HEAD"));
    }

    #[test]
    fn test_diff_cli_custom_ref() {
        let cli = Cli::parse_from(["test", "--diff", "main"]);
        assert_eq!(cli.diff.as_deref(), Some("main"));
    }

    #[test]
    fn test_diff_cli_not_set() {
        let cli = Cli::parse_from(["test"]);
        assert!(cli.diff.is_none());
    }
}