Skip to main content

omni_dev/cli/
coverage.rs

1//! Coverage analysis CLI commands.
2
3pub(crate) mod diff;
4
5use anyhow::Result;
6use clap::{Parser, Subcommand};
7
8/// Coverage analysis: diff/patch coverage for PR comments.
9#[derive(Parser)]
10pub struct CoverageCommand {
11    /// The coverage subcommand to execute.
12    #[command(subcommand)]
13    pub command: CoverageSubcommands,
14}
15
16/// Coverage subcommands.
17#[derive(Subcommand)]
18pub enum CoverageSubcommands {
19    /// Analyses diff/patch coverage from a per-line report and a git diff.
20    Diff(diff::DiffCommand),
21}
22
23impl CoverageCommand {
24    /// Executes the coverage command.
25    ///
26    /// `repo` is the repository location resolved at the CLI boundary
27    /// (`None` = current working directory).
28    pub async fn execute(self, repo: Option<&std::path::Path>) -> Result<()> {
29        match self.command {
30            CoverageSubcommands::Diff(cmd) => cmd.execute(repo).await,
31        }
32    }
33}
34
35#[cfg(test)]
36#[allow(clippy::unwrap_used, clippy::expect_used)]
37mod tests {
38    use super::*;
39
40    /// The `coverage` command dispatches to `diff`; a missing report makes the
41    /// leaf command error, which exercises the dispatch path end-to-end.
42    #[tokio::test]
43    async fn dispatches_to_diff() {
44        let cmd = CoverageCommand {
45            command: CoverageSubcommands::Diff(diff::DiffCommand {
46                report: std::path::PathBuf::from("/nonexistent/report.lcov"),
47                report_format: diff::ReportFormat::Auto,
48                base_ref: Some("HEAD".to_string()),
49                head_ref: None,
50                baseline_report: None,
51                baseline_report_format: diff::ReportFormat::Auto,
52                format: diff::OutputFormatArg::Markdown,
53                fail_under_patch: None,
54                strip_prefix: None,
55                collapse_ranges: false,
56                all_files: false,
57                artifact_url: None,
58                run_url: None,
59                base_sha: None,
60                head_sha: None,
61                commit_url: None,
62            }),
63        };
64        // Reaches the leaf command and fails on the missing report file.
65        assert!(cmd.execute(None).await.is_err());
66    }
67}