omni-dev 0.40.0

AI-powered git commit rewriter, PR generator, and MCP server for Jira, Confluence, and Datadog.
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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
//! Lint command — deterministic, no-AI validation of commit messages against
//! guidelines. The AI sibling is [`super::check`]; the two share
//! [`crate::data::check::CheckReport`] so they're interchangeable in
//! scripts. Core rule logic lives in [`crate::git::lint`].

use std::io::Read;
use std::path::Path;

use anyhow::{Context, Result};
use clap::Parser;

use crate::data::check::{CheckReport, CommitCheckResult, OutputFormat};

/// Lint command options - deterministically validates commit messages
/// against guidelines (no AI, no network).
#[derive(Parser)]
pub struct LintCommand {
    /// Commit range to lint (e.g., HEAD~3..HEAD, abc123..def456).
    /// Defaults to commits ahead of the default base branch
    /// (origin/main, origin/master, main, or master).
    #[arg(value_name = "COMMIT_RANGE")]
    pub commit_range: Option<String>,

    /// Path to custom context directory (defaults to .omni-dev/).
    #[arg(long)]
    pub context_dir: Option<std::path::PathBuf>,

    /// Accepted for CLI parity with `check`; unused by `lint` (there is no
    /// AI prose guidelines file to load — deterministic rules come from
    /// `.omni-dev/commit-rules.yaml` and `.omni-dev/scopes.yaml` instead).
    #[arg(long)]
    pub guidelines: Option<std::path::PathBuf>,

    /// Output format.
    #[arg(short = 'o', long, value_enum, default_value_t = OutputFormat::Text)]
    pub output: OutputFormat,

    /// Exits with error code if any issues found (including warnings).
    #[arg(long)]
    pub strict: bool,

    /// Only shows errors/warnings, suppresses info-level output.
    #[arg(long)]
    pub quiet: bool,

    /// Shows the resolved rules/scopes configuration sources.
    #[arg(long)]
    pub verbose: bool,

    /// Includes passing commits in output (hidden by default).
    #[arg(long)]
    pub show_passing: bool,

    /// Reads a single commit message from standard input instead of a
    /// commit range (for a `commit-msg` git hook call site).
    #[arg(long)]
    pub stdin: bool,
}

impl LintCommand {
    /// Executes the lint command, validating commit messages against
    /// deterministic rules.
    pub async fn execute(self, repo: Option<&Path>) -> Result<()> {
        let repo_root = match repo {
            Some(p) => p.to_path_buf(),
            None => std::env::current_dir().context("Failed to determine current directory")?,
        };
        let repo_root = repo_root.as_path();
        let output_format = self.output;

        let context_dir =
            crate::claude::context::resolve_context_dir_at(self.context_dir.as_deref(), repo_root);
        let valid_scopes = crate::claude::context::load_project_scopes(&context_dir, repo_root);
        let rules = crate::claude::context::load_commit_rules(&context_dir);

        if self.verbose && output_format == OutputFormat::Text {
            self.show_config_status(repo_root, &context_dir, &valid_scopes, &rules);
        }

        let report = if self.stdin {
            let mut message = String::new();
            std::io::stdin()
                .read_to_string(&mut message)
                .context("Failed to read commit message from stdin")?;
            lint_report_for_message(&message, &rules, &valid_scopes)
        } else {
            let range = self.resolve_range(repo_root)?;
            lint_report_for_range(repo_root, &range, &rules, &valid_scopes)?
        };

        self.output_report(&report, output_format)?;

        // Unlike `check`, an empty range is a clean exit (0), not an error —
        // a deterministic gate with nothing to lint isn't a failure.
        let exit_code = report.exit_code(self.strict);
        if exit_code != 0 {
            std::process::exit(exit_code);
        }

        Ok(())
    }

    fn resolve_range(&self, repo_root: &Path) -> Result<String> {
        if let Some(range) = &self.commit_range {
            return Ok(range.clone());
        }
        let repo = crate::git::GitRepository::open_at(repo_root)
            .context("Failed to open git repository at the given path")?;
        super::default_commit_range(&repo)
    }

    fn show_config_status(
        &self,
        _repo_root: &Path,
        context_dir: &Path,
        valid_scopes: &[crate::data::context::ScopeDefinition],
        rules: &crate::data::context::CommitRules,
    ) {
        use crate::claude::context::{config_source_label, ConfigSourceLabel};

        println!("📋 Lint configuration:");
        println!("   📂 Config dir: {}", context_dir.display());

        let scopes_source = if valid_scopes.is_empty() {
            "⚪ None found (any scope accepted)".to_string()
        } else {
            match config_source_label(context_dir, "scopes.yaml") {
                ConfigSourceLabel::NotFound => {
                    format!(
                        "✅ (ecosystem defaults only) ({} scopes)",
                        valid_scopes.len()
                    )
                }
                label => format!("{label} ({} scopes)", valid_scopes.len()),
            }
        };
        println!("   🎯 Valid scopes: {scopes_source}");

        let rules_source = match config_source_label(context_dir, "commit-rules.yaml") {
            ConfigSourceLabel::NotFound => "⚪ Using built-in defaults".to_string(),
            label => format!("{label}"),
        };
        println!("   📏 Commit rules: {rules_source}");
        println!(
            "      subject_max_len={}, require_scope={}, types={}",
            rules.subject_max_len,
            rules.require_scope,
            rules.types.len()
        );
        println!();
    }

    /// Outputs the lint report in the specified format.
    fn output_report(&self, report: &CheckReport, format: OutputFormat) -> Result<()> {
        match format {
            OutputFormat::Text => self.output_text_report(report),
            OutputFormat::Json => {
                let json = serde_json::to_string_pretty(report)
                    .context("Failed to serialize report to JSON")?;
                println!("{json}");
                Ok(())
            }
            OutputFormat::Yaml => {
                let yaml =
                    crate::data::to_yaml(report).context("Failed to serialize report to YAML")?;
                println!("{yaml}");
                Ok(())
            }
        }
    }

    /// Outputs the text format report.
    fn output_text_report(&self, report: &CheckReport) -> Result<()> {
        use crate::data::check::IssueSeverity;

        println!();

        for result in &report.commits {
            if result.passes && !self.show_passing {
                continue;
            }

            if self.quiet && !has_errors_or_warnings(&result.issues) {
                continue;
            }

            let icon = super::formatting::determine_commit_icon(result.passes, &result.issues);
            let short_hash = super::formatting::truncate_hash(&result.hash);
            println!("{icon} {short_hash} - \"{}\"", result.message);

            for issue in &result.issues {
                if self.quiet && issue.severity == IssueSeverity::Info {
                    continue;
                }
                let severity_str = super::formatting::format_severity_label(issue.severity);
                println!(
                    "   {} [{}] {}",
                    severity_str, issue.section, issue.explanation
                );
            }

            println!();
        }

        println!(
            "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\
             Summary: {} commits linted\n\
             \x20 {} errors, {} warnings\n\
             \x20 {} passed, {} with issues",
            report.summary.total_commits,
            report.summary.error_count,
            report.summary.warning_count,
            report.summary.passing_commits,
            report.summary.failing_commits,
        );

        Ok(())
    }
}

/// Returns whether any issues have Error or Warning severity.
fn has_errors_or_warnings(issues: &[crate::data::check::CommitIssue]) -> bool {
    use crate::data::check::IssueSeverity;
    issues
        .iter()
        .any(|i| matches!(i.severity, IssueSeverity::Error | IssueSeverity::Warning))
}

/// Builds a single-commit [`CheckReport`] by linting `message` directly —
/// no git, no repository. Used by `--stdin` and the MCP `message` input.
fn lint_report_for_message(
    message: &str,
    rules: &crate::data::context::CommitRules,
    valid_scopes: &[crate::data::context::ScopeDefinition],
) -> CheckReport {
    let issues = crate::git::lint_message(message, rules, valid_scopes);
    let passes = crate::git::lint_passes(&issues);
    let result = CommitCheckResult {
        hash: "-".to_string(),
        message: message.lines().next().unwrap_or("").to_string(),
        issues,
        suggestion: None,
        passes,
        summary: None,
    };
    CheckReport::new(vec![result])
}

/// Builds a [`CheckReport`] by linting every non-merge commit in `range`.
/// Merge commits are already excluded by
/// [`crate::git::GitRepository::get_commits_in_range`] — no additional
/// filtering needed here. An empty range yields an empty (clean) report.
fn lint_report_for_range(
    repo_root: &Path,
    range: &str,
    rules: &crate::data::context::CommitRules,
    valid_scopes: &[crate::data::context::ScopeDefinition],
) -> Result<CheckReport> {
    let repo = crate::git::GitRepository::open_at(repo_root)
        .context("Failed to open git repository at the given path")?;
    let commits = repo.get_commits_in_range(range)?;

    let results = commits
        .iter()
        .map(|commit| {
            let issues = crate::git::lint_message(&commit.original_message, rules, valid_scopes);
            let passes = crate::git::lint_passes(&issues);
            CommitCheckResult {
                hash: commit.hash.clone(),
                message: commit
                    .original_message
                    .lines()
                    .next()
                    .unwrap_or("")
                    .to_string(),
                issues,
                suggestion: None,
                passes,
                summary: None,
            }
        })
        .collect();

    Ok(CheckReport::new(results))
}

/// Structured output from [`run_lint`] for programmatic consumers (MCP).
#[derive(Debug, Clone)]
pub struct LintOutcome {
    /// YAML serialisation of the full [`CheckReport`].
    pub report_yaml: String,
    /// `true` when any commit has an error-severity issue.
    pub has_errors: bool,
    /// `true` when any commit has a warning-severity issue.
    pub has_warnings: bool,
    /// Total commits linted.
    pub total_commits: usize,
    /// Strict mode setting that produced `exit_code`.
    pub strict: bool,
    /// Exit code the CLI would use, honouring `strict`.
    pub exit_code: i32,
}

/// What to lint.
///
/// Either a commit range (resolved the same way as the CLI's positional
/// argument, defaulting to commits ahead of the base branch when `None`) or
/// a single literal message (the `--stdin` equivalent).
pub enum LintInput {
    /// Lint every non-merge commit in this range.
    Range(Option<String>),
    /// Lint this message directly, bypassing git entirely.
    Message(String),
}

/// Non-interactive core for `omni-dev git commit message lint`.
///
/// Shared by the CLI and the MCP `git_lint_commits` tool. No AI client
/// involved — deterministic and synchronous under the hood, `async` only
/// for call-site parity with [`super::run_check`].
///
/// `repo_path` selects the repository (`None` defaults to the current
/// working directory); `context_dir` overrides the `.omni-dev/` resolution
/// chain for both `scopes.yaml` and `commit-rules.yaml`.
pub async fn run_lint(
    input: LintInput,
    repo_path: Option<&Path>,
    context_dir: Option<&Path>,
    strict: bool,
) -> Result<LintOutcome> {
    let repo_root = match repo_path {
        Some(p) => p.to_path_buf(),
        None => std::env::current_dir().context("Failed to determine current directory")?,
    };
    let repo_root = repo_root.as_path();

    let ctx_dir = crate::claude::context::resolve_context_dir_at(context_dir, repo_root);
    let valid_scopes = crate::claude::context::load_project_scopes(&ctx_dir, repo_root);
    let rules = crate::claude::context::load_commit_rules(&ctx_dir);

    let report = match input {
        LintInput::Message(message) => lint_report_for_message(&message, &rules, &valid_scopes),
        LintInput::Range(range) => {
            let range = if let Some(r) = range {
                r
            } else {
                let repo = crate::git::GitRepository::open_at(repo_root)
                    .context("Failed to open git repository at the given path")?;
                super::default_commit_range(&repo)?
            };
            lint_report_for_range(repo_root, &range, &rules, &valid_scopes)?
        }
    };

    let report_yaml = crate::data::to_yaml(&report).context("Failed to serialise CheckReport")?;
    let has_errors = report.has_errors();
    let has_warnings = report.has_warnings();
    let exit_code = report.exit_code(strict);
    let total_commits = report.commits.len();

    Ok(LintOutcome {
        report_yaml,
        has_errors,
        has_warnings,
        total_commits,
        strict,
        exit_code,
    })
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
    use super::*;

    fn init_test_repo() -> tempfile::TempDir {
        let tmp_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tmp");
        std::fs::create_dir_all(&tmp_root).unwrap();
        let temp_dir = tempfile::tempdir_in(&tmp_root).unwrap();
        for args in [
            vec!["init"],
            vec!["checkout", "-b", "main"],
            vec!["commit", "--allow-empty", "-m", "feat(cli): first commit"],
        ] {
            let output = std::process::Command::new("git")
                .current_dir(temp_dir.path())
                .args([
                    "-c",
                    "user.email=test@example.com",
                    "-c",
                    "user.name=Test",
                    "-c",
                    "commit.gpgsign=false",
                ])
                .args(&args)
                .output()
                .unwrap();
            assert!(output.status.success(), "git {args:?} failed");
        }
        temp_dir
    }

    fn commit(dir: &Path, message: &str) {
        let output = std::process::Command::new("git")
            .current_dir(dir)
            .args([
                "-c",
                "user.email=test@example.com",
                "-c",
                "user.name=Test",
                "-c",
                "commit.gpgsign=false",
                "commit",
                "--allow-empty",
                "-m",
                message,
            ])
            .output()
            .unwrap();
        assert!(output.status.success(), "commit failed: {message}");
    }

    fn merge_dummy_branch(dir: &Path) {
        let sh = |args: &[&str]| {
            let output = std::process::Command::new("git")
                .current_dir(dir)
                .args([
                    "-c",
                    "user.email=test@example.com",
                    "-c",
                    "user.name=Test",
                    "-c",
                    "commit.gpgsign=false",
                ])
                .args(args)
                .output()
                .unwrap();
            assert!(output.status.success(), "git {args:?} failed");
        };
        sh(&["checkout", "-b", "side"]);
        sh(&["commit", "--allow-empty", "-m", "feat(cli): side change"]);
        sh(&["checkout", "main"]);
        sh(&["commit", "--allow-empty", "-m", "feat(cli): main change"]);
        sh(&["merge", "side", "--no-ff", "-m", "Merge branch 'side'"]);
    }

    #[tokio::test]
    async fn run_lint_message_flags_known_issues() {
        let outcome = run_lint(
            LintInput::Message("feature(bogus): Bad Message.".to_string()),
            None,
            None,
            false,
        )
        .await
        .unwrap();
        assert!(outcome.has_errors);
        assert_eq!(outcome.exit_code, 1);
        assert_eq!(outcome.total_commits, 1);
        assert!(outcome.report_yaml.contains("commits:"));
    }

    #[tokio::test]
    async fn run_lint_message_clean_passes() {
        let outcome = run_lint(
            LintInput::Message("feat(cli): add thing".to_string()),
            None,
            None,
            false,
        )
        .await
        .unwrap();
        assert!(!outcome.has_errors);
        assert_eq!(outcome.exit_code, 0);
    }

    #[tokio::test]
    async fn run_lint_range_merge_commit_excluded() {
        let temp_dir = init_test_repo();
        merge_dummy_branch(temp_dir.path());

        let outcome = run_lint(
            LintInput::Range(Some("HEAD~2..HEAD".to_string())),
            Some(temp_dir.path()),
            None,
            false,
        )
        .await
        .unwrap();

        // HEAD~2..HEAD spans the merge commit plus "main change"; the merge
        // commit itself must not appear.
        assert!(!outcome.report_yaml.contains("Merge branch"));
    }

    #[tokio::test]
    async fn run_lint_range_empty_is_clean_not_an_error() {
        let temp_dir = init_test_repo();
        let outcome = run_lint(
            LintInput::Range(Some("HEAD..HEAD".to_string())),
            Some(temp_dir.path()),
            None,
            false,
        )
        .await
        .unwrap();
        assert_eq!(outcome.total_commits, 0);
        assert!(!outcome.has_errors);
        assert_eq!(outcome.exit_code, 0);
    }

    #[tokio::test]
    async fn run_lint_range_strict_promotes_warnings() {
        let temp_dir = init_test_repo();
        commit(
            temp_dir.path(),
            "feat(cli): add thing\n\nCo-Authored-By: Bot <bot@example.com>",
        );
        let outcome = run_lint(
            LintInput::Range(Some("HEAD~1..HEAD".to_string())),
            Some(temp_dir.path()),
            None,
            true,
        )
        .await
        .unwrap();
        assert!(!outcome.has_errors);
        assert!(outcome.has_warnings);
        assert_eq!(outcome.exit_code, 2);
    }

    #[tokio::test]
    async fn run_lint_range_and_message_agree_on_same_content() {
        let temp_dir = init_test_repo();
        commit(temp_dir.path(), "feature(bogus): Bad Message.");

        let range_outcome = run_lint(
            LintInput::Range(Some("HEAD~1..HEAD".to_string())),
            Some(temp_dir.path()),
            None,
            false,
        )
        .await
        .unwrap();
        let message_outcome = run_lint(
            LintInput::Message("feature(bogus): Bad Message.".to_string()),
            None,
            None,
            false,
        )
        .await
        .unwrap();

        assert_eq!(range_outcome.has_errors, message_outcome.has_errors);
        assert_eq!(range_outcome.exit_code, message_outcome.exit_code);
    }

    #[test]
    fn cli_execute_json_output_matches_check_report_shape() {
        let temp_dir = init_test_repo();
        commit(temp_dir.path(), "feat(cli): second commit");
        let cmd = LintCommand {
            commit_range: Some("HEAD~1..HEAD".to_string()),
            context_dir: None,
            guidelines: None,
            output: OutputFormat::Json,
            strict: false,
            quiet: true,
            verbose: false,
            show_passing: true,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok());
    }

    #[test]
    fn cli_execute_yaml_output_matches_check_report_shape() {
        let temp_dir = init_test_repo();
        commit(temp_dir.path(), "feat(cli): second commit");
        let cmd = LintCommand {
            commit_range: Some("HEAD~1..HEAD".to_string()),
            context_dir: None,
            guidelines: None,
            output: OutputFormat::Yaml,
            strict: false,
            quiet: true,
            verbose: false,
            show_passing: true,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok());
    }

    /// `commit_range: None` drives `resolve_range` through its
    /// `default_commit_range` fallback rather than the literal-range
    /// shortcut every other test in this module uses.
    #[test]
    fn cli_execute_range_none_uses_default_commit_range() {
        let temp_dir = init_test_repo();
        let cmd = LintCommand {
            commit_range: None,
            context_dir: None,
            guidelines: None,
            output: OutputFormat::Json,
            strict: false,
            quiet: true,
            verbose: false,
            show_passing: true,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok(), "expected clean exit, got: {result:?}");
    }

    /// `LintInput::Range(None)` is `run_lint`'s own default-range fallback —
    /// a separate code path from `LintCommand::resolve_range` above, since
    /// `run_lint` is also reachable from the MCP tool with no CLI in front
    /// of it.
    #[tokio::test]
    async fn run_lint_range_none_uses_default_commit_range() {
        let temp_dir = init_test_repo();
        let outcome = run_lint(LintInput::Range(None), Some(temp_dir.path()), None, false)
            .await
            .unwrap();
        assert_eq!(outcome.total_commits, 0);
    }

    #[test]
    fn cli_execute_verbose_config_status_empty_scopes_rules_not_found() {
        let temp_dir = init_test_repo();
        // An explicit (nonexistent) context_dir bypasses walk-up discovery —
        // without it, resolution would walk up from `temp_dir` (created
        // under this crate's own `tmp/`) and find *this repo's* real
        // `.omni-dev/scopes.yaml`, defeating the "nothing configured" case
        // this test means to exercise.
        let context_dir = temp_dir.path().join(".omni-dev");
        let cmd = LintCommand {
            commit_range: Some("HEAD..HEAD".to_string()),
            context_dir: Some(context_dir),
            guidelines: None,
            output: OutputFormat::Text,
            strict: false,
            quiet: false,
            verbose: true,
            show_passing: false,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok());
    }

    #[test]
    fn cli_execute_verbose_config_status_scopes_and_rules_found() {
        let temp_dir = init_test_repo();
        let context_dir = temp_dir.path().join(".omni-dev");
        std::fs::create_dir_all(&context_dir).unwrap();
        std::fs::write(
            context_dir.join("scopes.yaml"),
            "scopes:\n  - name: custom\n    description: Custom scope\n    examples: []\n    file_patterns: []\n",
        )
        .unwrap();
        std::fs::write(
            context_dir.join("commit-rules.yaml"),
            "subject_max_len: 72\ntypes:\n  - feat\nrequire_scope: false\nforbidden_footers: []\n",
        )
        .unwrap();

        let cmd = LintCommand {
            commit_range: Some("HEAD..HEAD".to_string()),
            context_dir: Some(context_dir),
            guidelines: None,
            output: OutputFormat::Text,
            strict: false,
            quiet: false,
            verbose: true,
            show_passing: false,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok());
    }

    #[test]
    fn cli_execute_verbose_config_status_ecosystem_scopes_no_file() {
        let temp_dir = init_test_repo();
        std::fs::write(temp_dir.path().join("Cargo.toml"), "[package]\n").unwrap();
        // See the comment in the "empty scopes" test above: an explicit
        // (nonexistent) context_dir bypasses walk-up discovery, so the only
        // non-empty scopes are the `Cargo.toml`-derived ecosystem defaults
        // this test targets.
        let context_dir = temp_dir.path().join(".omni-dev");

        let cmd = LintCommand {
            commit_range: Some("HEAD..HEAD".to_string()),
            context_dir: Some(context_dir),
            guidelines: None,
            output: OutputFormat::Text,
            strict: false,
            quiet: false,
            verbose: true,
            show_passing: false,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok());
    }

    /// `passes` (and so the `show_passing: false` default's skip-continue at
    /// the top of the per-commit loop) reflects only `Error`-severity
    /// issues, matching `exit_code`'s own error-only gate — a
    /// `Warning`-only commit still counts as passing and is hidden here
    /// just like a clean one. `output_text_report`'s per-issue print lines
    /// are covered separately below (`quiet_mode_filters_...`), since a
    /// commit that fails the `show_passing` check can't reach them without
    /// an `Error`-severity issue, which would drive `execute()`'s
    /// `std::process::exit` and abort this whole test binary.
    #[test]
    fn output_text_report_show_passing_false_hides_warning_only_commits() {
        let temp_dir = init_test_repo();
        commit(temp_dir.path(), "feat(cli): clean second commit");
        commit(
            temp_dir.path(),
            "feat(cli): add thing\n\nCo-Authored-By: Bot <bot@example.com>",
        );
        let cmd = LintCommand {
            commit_range: Some("HEAD~2..HEAD".to_string()),
            context_dir: None,
            guidelines: None,
            output: OutputFormat::Text,
            strict: false,
            quiet: false,
            verbose: false,
            show_passing: false,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok(), "expected clean exit, got: {result:?}");
    }

    /// `quiet` filters both a clean commit (`show_passing: true` keeps it
    /// past the first check, but it has no errors/warnings to show) and,
    /// within a surviving commit's own issue list, its `Info`-severity
    /// entries — two distinct skip branches in `output_text_report`.
    #[test]
    fn output_text_report_quiet_mode_filters_clean_and_info_issues() {
        let temp_dir = init_test_repo();
        commit(temp_dir.path(), "feat(cli): clean thing");
        commit(
            temp_dir.path(),
            "feat(cli): Add thing.\n\nCo-Authored-By: Bot <bot@example.com>",
        );
        let cmd = LintCommand {
            commit_range: Some("HEAD~2..HEAD".to_string()),
            context_dir: None,
            guidelines: None,
            output: OutputFormat::Text,
            strict: false,
            quiet: true,
            verbose: false,
            show_passing: true,
            stdin: false,
        };
        let rt = tokio::runtime::Runtime::new().unwrap();
        let result = rt.block_on(cmd.execute(Some(temp_dir.path())));
        assert!(result.is_ok(), "expected clean exit, got: {result:?}");
    }
}