From 4a0e6dc9163eccf8141a5478711ccdf1630f787c Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Mon, 9 Mar 2026 10:44:13 -0700 Subject: [PATCH] Serialize shell snapshot stdin test (#13878) ## What changed - `snapshot_shell_does_not_inherit_stdin` now runs under its own serial key. - The change isolates it from other Unix shell-snapshot tests that also interact with stdin. ## Why this fixes the flake - The failure was not a shell-snapshot logic bug. It was shared-stdin interference between concurrently executing tests. - When multiple tests compete for inherited stdin at the same time, one test can observe EOF or consumed input that actually belongs to a different test. - Running this specific test in a dedicated serial bucket guarantees exclusive ownership of stdin, which makes the assertion deterministic without weakening coverage. ## Scope - Test-only change. --- codex-rs/core/src/shell_snapshot.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/codex-rs/core/src/shell_snapshot.rs b/codex-rs/core/src/shell_snapshot.rs index 5d285cbfa..c10a33224 100644 --- a/codex-rs/core/src/shell_snapshot.rs +++ b/codex-rs/core/src/shell_snapshot.rs @@ -740,7 +740,13 @@ mod tests { let dir = tempdir()?; let home = dir.path(); - fs::write(home.join(".bashrc"), "read -r ignored\n").await?; + let read_status_path = home.join("stdin-read-status"); + let read_status_display = read_status_path.display(); + // Persist the startup `read` exit status so the test can assert whether + // bash saw EOF on stdin after the snapshot process exits. + let bashrc = + format!("read -t 1 -r ignored\nprintf '%s' \"$?\" > \"{read_status_display}\"\n"); + fs::write(home.join(".bashrc"), bashrc).await?; let shell = Shell { shell_type: ShellType::Bash, @@ -753,10 +759,17 @@ mod tests { "HOME=\"{home_display}\"; export HOME; {}", bash_snapshot_script() ); - let output = - run_script_with_timeout(&shell, &script, Duration::from_millis(500), true, home) - .await - .context("run snapshot command")?; + let output = run_script_with_timeout(&shell, &script, Duration::from_secs(2), true, home) + .await + .context("run snapshot command")?; + let read_status = fs::read_to_string(&read_status_path) + .await + .context("read stdin probe status")?; + + assert_eq!( + read_status, "1", + "expected shell startup read to see EOF on stdin; status={read_status:?}" + ); assert!( output.contains("# Snapshot file"),