[test] add tests for --no-interaction and its alias to ensure non-interactive mode skips prompts and uses defaults

This commit is contained in:
2025-08-12 04:58:39 +02:00
parent 98491a8701
commit b7f0ddda37
5 changed files with 114 additions and 7 deletions

View File

@@ -67,7 +67,8 @@ struct Args {
quiet: bool,
/// Non-interactive mode: never prompt; use defaults instead.
#[arg(long = "no-interaction", global = true)]
/// Deprecated alias supported: --no-interation (typo)
#[arg(long = "no-interaction", alias = "no-interation", global = true)]
no_interaction: bool,
/// Disable progress bars (also respects NO_PROGRESS=1). Progress bars render on stderr only when attached to a TTY.
@@ -503,14 +504,17 @@ fn run() -> Result<()> {
if let Some(out) = &args.output {
// Merge target: either only merged, or merged plus separate
let outp = PathBuf::from(out);
if let Some(parent) = outp.parent() { create_dir_all(parent).ok(); }
// Name: <date>_out or <date>_merged depending on flag
// Ensure target directory exists appropriately for the chosen mode
if args.merge_and_separate {
// When writing inside an output directory, create it directly
create_dir_all(&outp).ok();
// In merge+separate mode, always write merged output inside the provided directory
let base = PathBuf::from(out).join(format!("{}_merged", polyscribe::date_prefix()));
let base = outp.join(format!("{}_merged", polyscribe::date_prefix()));
let root = OutputRoot { items: merged_items.clone() };
write_outputs(&base, &root, &out_formats)?;
} else {
// For single merged file, ensure the parent dir exists
if let Some(parent) = outp.parent() { create_dir_all(parent).ok(); }
let base = outp.with_file_name(format!("{}_{}", polyscribe::date_prefix(), outp.file_name().and_then(|s| s.to_str()).unwrap_or("out")));
let root = OutputRoot { items: merged_items.clone() };
write_outputs(&base, &root, &out_formats)?;
@@ -915,4 +919,26 @@ mod tests {
std_env::remove_var("POLYSCRIBE_TEST_FORCE_VULKAN");
}
}
#[test]
fn test_no_interaction_disables_speaker_prompt() {
use polyscribe::ui;
// Ensure non-interactive via env and global flag
unsafe {
std_env::set_var("NO_INTERACTION", "1");
}
polyscribe::set_no_interaction(true);
ui::testing_reset_prompt_call_counters();
// Build a minimal progress manager
let pf = polyscribe::progress::ProgressFactory::from_config(&polyscribe::Config::default());
let pm = pf.make_manager(polyscribe::progress::ProgressMode::Single);
let dummy = std::path::PathBuf::from("example.wav");
let got = super::prompt_speaker_name_for_path(&dummy, "DefaultSpeaker", /*enabled:*/ true, &pm);
assert_eq!(got, "DefaultSpeaker");
assert_eq!(ui::testing_prompt_call_count(), 0, "no prompt functions should be called when NO_INTERACTION=1");
// Cleanup
unsafe {
std_env::remove_var("NO_INTERACTION");
}
}
}