[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

@@ -36,7 +36,17 @@ pub fn set_no_interaction(b: bool) {
}
/// Return current non-interactive state.
pub fn is_no_interaction() -> bool {
NO_INTERACTION.load(Ordering::Relaxed)
if NO_INTERACTION.load(Ordering::Relaxed) {
return true;
}
// Also honor NO_INTERACTION=1/true environment variable for convenience/testing
match std::env::var("NO_INTERACTION") {
Ok(v) => {
let v = v.trim();
v == "1" || v.eq_ignore_ascii_case("true")
}
Err(_) => false,
}
}
/// Set verbose level (0 = normal, 1 = verbose, 2 = super-verbose)
@@ -638,8 +648,13 @@ where
}
// Print a blank line before the selection prompt to keep output synchronized.
printer("");
let idx = crate::ui::prompt_select_index("Select a Whisper model", &display_names)
.context("Failed to read selection")?;
let idx = if crate::is_no_interaction() || !crate::stdin_is_tty() {
// Non-interactive: auto-select the first candidate deterministically (as listed)
0
} else {
crate::ui::prompt_select_index("Select a Whisper model", &display_names)
.context("Failed to read selection")?
};
let chosen = candidates.swap_remove(idx);
let _ = std::fs::write(models_dir.join(".last_model"), chosen.display().to_string());
// Print an empty line after selection input