Skip to content

Commit 94fa9c4

Browse files
branchseerclaude
andauthored
fix(test): fix flaky write_interactive_prompt on Windows ConPTY (#318)
## Summary - Replace `read_until(b' ')` with `read_until(b'\n')` in the `write_interactive_prompt` PTY test - On Windows ConPTY, `read_until(b' ')` can hang indefinitely, causing flaky CI failures (e.g. [run #23833764481](https://github.com/voidzero-dev/vite-task/actions/runs/23833764481/job/69473019642)) ## Test plan - [x] `cargo test -p pty_terminal --test terminal` passes locally - [ ] Windows CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eb746ad commit 94fa9c4

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

crates/pty_terminal/tests/terminal.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ fn write_interactive_prompt() {
140140
let cmd = CommandBuilder::from(command_for_fn!((), |(): ()| {
141141
use std::io::{Write, stdin, stdout};
142142
let mut stdout = stdout();
143-
print!("Name: ");
143+
// Use "Name:\n" instead of "Name: " so the test can synchronize with
144+
// `read_until(b'\n')`. On Windows ConPTY, `read_until(b' ')` on the
145+
// raw PTY stream can hang.
146+
println!("Name:");
144147
stdout.flush().unwrap();
145148

146149
let mut input = std::string::String::new();
@@ -152,12 +155,12 @@ fn write_interactive_prompt() {
152155
let Terminal { mut pty_reader, mut pty_writer, child_handle, .. } =
153156
Terminal::spawn(ScreenSize { rows: 80, cols: 80 }, cmd).unwrap();
154157

155-
// Wait for prompt "Name: " (read until the space after colon)
158+
// Wait for the "Name:" prompt line.
156159
{
157160
let mut buf_reader = BufReader::new(&mut pty_reader);
158-
let mut buf = Vec::new();
159-
buf_reader.read_until(b' ', &mut buf).unwrap();
160-
assert!(String::from_utf8_lossy(&buf).contains("Name:"));
161+
let mut line = Vec::new();
162+
buf_reader.read_until(b'\n', &mut line).unwrap();
163+
assert!(String::from_utf8_lossy(&line).contains("Name:"));
161164
}
162165

163166
// Send response
@@ -168,7 +171,7 @@ fn write_interactive_prompt() {
168171
let _ = child_handle.wait().unwrap();
169172

170173
let output = pty_reader.screen_contents();
171-
assert_eq!(output.trim(), "Name: Alice\nHello, Alice");
174+
assert_eq!(output.trim(), "Name:\nAlice\nHello, Alice");
172175
}
173176

174177
#[test]

0 commit comments

Comments
 (0)