Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Stabilize pipe process stdin round-trip test (#14013)

Ahmed Ibrahim9b5078d3e848
diff --git a/codex-rs/utils/pty/src/tests.rs b/codex-rs/utils/pty/src/tests.rs
index c2856a95c6..cc4c002a5e 100644
--- a/codex-rs/utils/pty/src/tests.rs
+++ b/codex-rs/utils/pty/src/tests.rs
@@ -288,21 +288,42 @@ async fn pty_python_repl_emits_output_and_exits() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn pipe_process_round_trips_stdin() -> anyhow::Result<()> {
- let Some(python) = find_python() else {
- eprintln!("python not found; skipping pipe_process_round_trips_stdin");
- return Ok(());
+ let (program, args) = if cfg!(windows) {
+ let cmd = std::env::var("COMSPEC").unwrap_or_else(|_| "cmd.exe".to_string());
+ (
+ cmd,
+ vec![
+ "/Q".to_string(),
+ "/V:ON".to_string(),
+ "/D".to_string(),
+ "/C".to_string(),
+ "set /p line= & echo(!line!".to_string(),
+ ],
+ )
+ } else {
+ let Some(python) = find_python() else {
+ eprintln!("python not found; skipping pipe_process_round_trips_stdin");
+ return Ok(());
+ };
+ (
+ python,
+ vec![
+ "-u".to_string(),
+ "-c".to_string(),
+ "import sys; print(sys.stdin.readline().strip());".to_string(),
+ ],
+ )
};
-
- let args = vec![
- "-u".to_string(),
- "-c".to_string(),
- "import sys; print(sys.stdin.readline().strip());".to_string(),
- ];
let env_map: HashMap<String, String> = std::env::vars().collect();
- let spawned = spawn_pipe_process(&python, &args, Path::new("."), &env_map, &None).await?;
+ let spawned = spawn_pipe_process(&program, &args, Path::new("."), &env_map, &None).await?;
let (session, output_rx, exit_rx) = combine_spawned_output(spawned);
let writer = session.writer_sender();
- writer.send(b"roundtrip\n".to_vec()).await?;
+ let newline = if cfg!(windows) { "\r\n" } else { "\n" };
+ writer
+ .send(format!("roundtrip{newline}").into_bytes())
+ .await?;
+ drop(writer);
+ session.close_stdin();
let (output, code) = collect_output_until_exit(output_rx, exit_rx, 5_000).await;
let text = String::from_utf8_lossy(&output);