From be5dbe493f0ee8d64b0cc054840693bf6798c835 Mon Sep 17 00:00:00 2001 From: saud-oai Date: Sun, 24 May 2026 00:12:52 -0400 Subject: [PATCH] Add regression coverage for timed-out zsh snapshots --- codex-rs/core/src/shell_snapshot_tests.rs | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/codex-rs/core/src/shell_snapshot_tests.rs b/codex-rs/core/src/shell_snapshot_tests.rs index 0199347b4e..526269448a 100644 --- a/codex-rs/core/src/shell_snapshot_tests.rs +++ b/codex-rs/core/src/shell_snapshot_tests.rs @@ -1,9 +1,12 @@ use super::*; +use anyhow::anyhow; use core_test_support::PathBufExt; use core_test_support::PathExt; use pretty_assertions::assert_eq; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; #[cfg(unix)] use std::process::Command; @@ -374,6 +377,41 @@ async fn timed_out_snapshot_shell_is_terminated() -> Result<()> { Ok(()) } +#[cfg(unix)] +#[tokio::test] +async fn timed_out_zsh_user_rc_uses_login_shell_fallback_snapshot() -> Result<()> { + let dir = tempdir()?; + let shell_path = dir.path().join("zsh-wrapper.sh"); + fs::write( + &shell_path, + r#"#!/bin/sh +marker="$0.first-call" +if [ ! -e "$marker" ]; then + : > "$marker" + while :; do :; done +fi +case "$*" in + *".zshrc"*) exit 2 ;; +esac +printf '# Snapshot file\nexport PATH=/fallback/bin\n' +"#, + ) + .await?; + std::fs::set_permissions(&shell_path, std::fs::Permissions::from_mode(0o755))?; + + let shell = Shell { + shell_type: ShellType::Zsh, + shell_path, + shell_snapshot: crate::shell::empty_shell_snapshot_receiver(), + }; + + let snapshot = capture_zsh_snapshot(&shell, &dir.path().abs(), Duration::from_secs(1)).await?; + + assert_eq!(snapshot, "# Snapshot file\nexport PATH=/fallback/bin\n"); + + Ok(()) +} + #[cfg(target_os = "macos")] #[tokio::test] async fn macos_zsh_snapshot_includes_sections() -> Result<()> {