From c6f98f037595f15306d2b3c83a1f5c1bdc0cc9db Mon Sep 17 00:00:00 2001 From: branchseer Date: Wed, 1 Apr 2026 14:18:46 +0800 Subject: [PATCH] fix(test): fix flaky `write_interactive_prompt` on Windows ConPTY Use `read_until(b'\n')` instead of `read_until(b' ')` for PTY synchronization. On Windows ConPTY, `read_until(b' ')` can hang indefinitely, as seen in CI run #23833764481. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/pty_terminal/tests/terminal.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/pty_terminal/tests/terminal.rs b/crates/pty_terminal/tests/terminal.rs index ec6bcc49..33755024 100644 --- a/crates/pty_terminal/tests/terminal.rs +++ b/crates/pty_terminal/tests/terminal.rs @@ -140,7 +140,10 @@ fn write_interactive_prompt() { let cmd = CommandBuilder::from(command_for_fn!((), |(): ()| { use std::io::{Write, stdin, stdout}; let mut stdout = stdout(); - print!("Name: "); + // Use "Name:\n" instead of "Name: " so the test can synchronize with + // `read_until(b'\n')`. On Windows ConPTY, `read_until(b' ')` on the + // raw PTY stream can hang. + println!("Name:"); stdout.flush().unwrap(); let mut input = std::string::String::new(); @@ -152,12 +155,12 @@ fn write_interactive_prompt() { let Terminal { mut pty_reader, mut pty_writer, child_handle, .. } = Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap(); - // Wait for prompt "Name: " (read until the space after colon) + // Wait for the "Name:" prompt line. { let mut buf_reader = BufReader::new(&mut pty_reader); - let mut buf = Vec::new(); - buf_reader.read_until(b' ', &mut buf).unwrap(); - assert!(String::from_utf8_lossy(&buf).contains("Name:")); + let mut line = Vec::new(); + buf_reader.read_until(b'\n', &mut line).unwrap(); + assert!(String::from_utf8_lossy(&line).contains("Name:")); } // Send response @@ -168,7 +171,7 @@ fn write_interactive_prompt() { let _ = child_handle.wait().unwrap(); let output = pty_reader.screen_contents(); - assert_eq!(output.trim(), "Name: Alice\nHello, Alice"); + assert_eq!(output.trim(), "Name:\nAlice\nHello, Alice"); } #[test]