From 369fedff5c28576d221f389cb790cffe804a9e4a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 18:09:39 +0000 Subject: [PATCH] fix: ignore stray empty input in interactive prompts When running interactive tests (like `INTERACTIVE=1 cargo test --nocapture`), stray newlines from previous commands or input streams can cause `read_line` to immediately return an empty string. This caused the first prompt (`prompt_microstructure_variable`) to be skipped, and the intended answer was instead consumed by the second prompt (`prompt_cutoff_value`). This commit updates `helpers::prompt_microstructure_variable` and `helpers::prompt_cutoff_value` to repeatedly read from `stdin` until a non-empty line is provided. It also correctly handles EOF (`bytes == 0`) to prevent infinite loops when stdin is exhausted. Co-authored-by: soniapi <396009+soniapi@users.noreply.github.com> --- src/helpers.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index b79fdb0..8ed697c 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -11,9 +11,20 @@ pub fn prompt_microstructure_variable(connection: &mut PgConnection) -> Option Option { let mut input = String::new(); // Read user input - io::stdin() - .read_line(&mut input) - .expect("Failed to read input"); + loop { + input.clear(); + let bytes = io::stdin() + .read_line(&mut input) + .expect("Failed to read input"); + + if bytes == 0 { + return None; // EOF + } + + if !input.trim().is_empty() { + break; + } + } // The user can only enter a number for now, anything else will exit the function. if let Ok(divide) = input.trim().parse::() {