From 9eb7d1bcb2541002f952755db42d8363ca48b978 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Wed, 11 Mar 2026 23:24:06 +0000 Subject: [PATCH] Add find command to select mutations by factors --- crates/bough-cli/src/config.rs | 75 ++++++++++++++++++++++++++++++++-- crates/bough-cli/src/main.rs | 4 ++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/crates/bough-cli/src/config.rs b/crates/bough-cli/src/config.rs index fba865a6..c74d5606 100644 --- a/crates/bough-cli/src/config.rs +++ b/crates/bough-cli/src/config.rs @@ -1,10 +1,10 @@ -use std::env; -use std::io::IsTerminal; -use std::{collections::HashMap, path::PathBuf}; - +use bough_core::Factor; use facet::Facet; use figue::{self as args, ConfigFormat, ConfigFormatError, Driver, builder}; use miette::Diagnostic; +use std::env; +use std::io::IsTerminal; +use std::{collections::HashMap, path::PathBuf}; use thiserror::Error; use tracing::{debug, warn}; @@ -69,6 +69,22 @@ pub enum Command { step: Step, }, + Find { + #[facet(args::positional, default)] + lang: Option, + #[facet(args::positional, default)] + file: Option, + + #[facet(args::named, args::short = 'n', default = 1)] + number: u8, + + #[facet(args::named, default = 1)] + number_per_file: u8, + + #[facet(args::named, default = vec![Factor::OuterMissedMutations, Factor::TSNodeDepth])] + factors: Vec, + }, + Run, Noop, } @@ -619,6 +635,57 @@ cmd = "npm test" assert!(matches!(cli.command, Command::Run)); } + #[test] + fn find_defaults() { + let cli = parse_ok(&["find"], MINIMAL_TOML); + match cli.command { + Command::Find { + lang, + file, + number, + number_per_file, + factors, + } => { + assert_eq!(lang, None); + assert_eq!(file, None); + assert_eq!(number, 1); + assert_eq!(number_per_file, 1); + assert_eq!( + factors, + vec![Factor::OuterMissedMutations, Factor::TSNodeDepth] + ); + } + other => panic!("expected Find, got {other:?}"), + } + } + + #[test] + fn find_with_args() { + let cli = parse_ok( + &["find", "js", "src/foo.js", "-n", "5", "--number-per-file", "3", "--factors", "VcsFileChurn", "--factors", "MutationSeverity"], + MINIMAL_TOML, + ); + match cli.command { + Command::Find { + lang, + file, + number, + number_per_file, + factors, + } => { + assert_eq!(lang, Some(bough_core::LanguageId::Javascript)); + assert_eq!(file, Some(PathBuf::from("src/foo.js"))); + assert_eq!(number, 5); + assert_eq!(number_per_file, 3); + assert_eq!( + factors, + vec![Factor::VcsFileChurn, Factor::MutationSeverity] + ); + } + other => panic!("expected Find, got {other:?}"), + } + } + // bough[verify config.include.at-least-one] #[test] fn empty_include_fails_validation() { diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 36b3ab1d..b1d9679b 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -505,6 +505,10 @@ fn main() { Box::new(Noop) } + Command::Find { .. } => { + todo!("find command") + } + Command::Noop => { info!("starting run"); Box::new(Noop) -- knotmirror 0.0.1