From b7e834a02b7164dd363bb71e677a080ad46b72e9 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Wed, 15 Oct 2025 12:55:22 +0100 Subject: [PATCH] Fix tests --- codex-rs/core/src/codex.rs | 3 +++ codex-rs/core/src/executor/runner.rs | 22 +++++++++++++++++++++- codex-rs/core/src/executor/sandbox.rs | 20 +++++++++++++++----- codex-rs/core/src/unified_exec/mod.rs | 17 ++--------------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 4e6d065366..39a2711f22 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -472,6 +472,7 @@ impl Session { turn_context.sandbox_policy.clone(), turn_context.cwd.clone(), config.codex_linux_sandbox_exe.clone(), + None, )), }; @@ -2761,6 +2762,7 @@ mod tests { turn_context.sandbox_policy.clone(), turn_context.cwd.clone(), None, + None, )), }; let session = Session { @@ -2829,6 +2831,7 @@ mod tests { config.sandbox_policy.clone(), config.cwd.clone(), None, + None, )), }; let session = Arc::new(Session { diff --git a/codex-rs/core/src/executor/runner.rs b/codex-rs/core/src/executor/runner.rs index f3ade5b34f..74536605ef 100644 --- a/codex-rs/core/src/executor/runner.rs +++ b/codex-rs/core/src/executor/runner.rs @@ -34,6 +34,9 @@ use crate::tools::context::ExecCommandContext; pub(crate) struct ExecutorConfig { pub(crate) sandbox_policy: SandboxPolicy, pub(crate) sandbox_cwd: PathBuf, + // Path to codex-linux-sandbox executable (Linux-only). Used by initial_launch when selecting Linux sandbox. + pub(crate) codex_linux_sandbox_exe: Option, + // Path to the codex binary itself (used by apply_patch backend to self-invoke when needed). pub(crate) codex_exe: Option, } @@ -41,16 +44,33 @@ impl ExecutorConfig { pub(crate) fn new( sandbox_policy: SandboxPolicy, sandbox_cwd: PathBuf, + codex_linux_sandbox_exe: Option, codex_exe: Option, ) -> Self { + let codex_exe = codex_exe.or_else(|| derive_codex_exe(&codex_linux_sandbox_exe)); Self { sandbox_policy, sandbox_cwd, + codex_linux_sandbox_exe, codex_exe, } } } +fn derive_codex_exe(sandbox_exe: &Option) -> Option { + sandbox_exe.as_ref().and_then(|path| { + let stem_matches_sandbox = path + .file_stem() + .and_then(|stem| stem.to_str()) + .is_some_and(|stem| stem == "codex-linux-sandbox"); + if stem_matches_sandbox { + None + } else { + Some(path.clone()) + } + }) +} + pub(crate) struct ExecutionPlan { request: ExecutionRequest, config: ExecutorConfig, @@ -86,7 +106,7 @@ impl ExecutionPlan { &self.request.params.command, &self.config.sandbox_policy, &self.config.sandbox_cwd, - self.config.codex_exe.as_ref(), + self.config.codex_linux_sandbox_exe.as_ref(), ) } diff --git a/codex-rs/core/src/executor/sandbox.rs b/codex-rs/core/src/executor/sandbox.rs index 349c72c15b..313222dd24 100644 --- a/codex-rs/core/src/executor/sandbox.rs +++ b/codex-rs/core/src/executor/sandbox.rs @@ -339,7 +339,7 @@ mod tests { action, user_explicitly_approved_this_action: true, }; - let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None); + let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None, None); let request = ExecutionRequest { params: ExecParams { command: vec!["apply_patch".into()], @@ -382,7 +382,12 @@ mod tests { action, user_explicitly_approved_this_action: false, }; - let cfg = ExecutorConfig::new(SandboxPolicy::DangerFullAccess, std::env::temp_dir(), None); + let cfg = ExecutorConfig::new( + SandboxPolicy::DangerFullAccess, + std::env::temp_dir(), + None, + None, + ); let request = ExecutionRequest { params: ExecParams { command: vec!["apply_patch".into()], @@ -426,7 +431,7 @@ mod tests { action, user_explicitly_approved_this_action: false, }; - let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None); + let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None, None); let request = ExecutionRequest { params: ExecParams { command: vec!["apply_patch".into()], @@ -465,7 +470,12 @@ mod tests { #[tokio::test] async fn select_shell_autoapprove_in_danger_mode() { let (session, ctx) = make_session_and_context(); - let cfg = ExecutorConfig::new(SandboxPolicy::DangerFullAccess, std::env::temp_dir(), None); + let cfg = ExecutorConfig::new( + SandboxPolicy::DangerFullAccess, + std::env::temp_dir(), + None, + None, + ); let request = ExecutionRequest { params: ExecParams { command: vec!["some-unknown".into()], @@ -501,7 +511,7 @@ mod tests { #[tokio::test] async fn select_shell_escalates_on_failure_with_platform_sandbox() { let (session, ctx) = make_session_and_context(); - let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None); + let cfg = ExecutorConfig::new(SandboxPolicy::ReadOnly, std::env::temp_dir(), None, None); let request = ExecutionRequest { params: ExecParams { // Unknown command => untrusted but not flagged dangerous diff --git a/codex-rs/core/src/unified_exec/mod.rs b/codex-rs/core/src/unified_exec/mod.rs index ebb977424f..06f76f96bf 100644 --- a/codex-rs/core/src/unified_exec/mod.rs +++ b/codex-rs/core/src/unified_exec/mod.rs @@ -495,24 +495,18 @@ async fn create_unified_exec_session( } #[cfg(test)] +#[cfg(unix)] mod tests { use super::*; - #[cfg(unix)] + use crate::codex::Session; - #[cfg(unix)] use crate::codex::TurnContext; - #[cfg(unix)] use crate::codex::make_session_and_context; - #[cfg(unix)] use crate::protocol::AskForApproval; - #[cfg(unix)] use crate::protocol::SandboxPolicy; - #[cfg(unix)] use core_test_support::skip_if_sandbox; - #[cfg(unix)] use std::sync::Arc; - #[cfg(unix)] fn test_session_and_turn() -> (Arc, Arc) { let (session, mut turn) = make_session_and_context(); turn.approval_policy = AskForApproval::Never; @@ -520,7 +514,6 @@ mod tests { (Arc::new(session), Arc::new(turn)) } - #[cfg(unix)] async fn run_unified_exec_request( session: &Arc, turn: &Arc, @@ -568,7 +561,6 @@ mod tests { assert_eq!(buffer.chunks.pop_back().unwrap(), vec![b'b']); } - #[cfg(unix)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn unified_exec_persists_across_requests_jif() -> Result<(), UnifiedExecError> { skip_if_sandbox!(Ok(())); @@ -610,7 +602,6 @@ mod tests { Ok(()) } - #[cfg(unix)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn multi_unified_exec_sessions() -> Result<(), UnifiedExecError> { skip_if_sandbox!(Ok(())); @@ -662,7 +653,6 @@ mod tests { Ok(()) } - #[cfg(unix)] #[tokio::test] async fn unified_exec_timeouts() -> Result<(), UnifiedExecError> { skip_if_sandbox!(Ok(())); @@ -712,7 +702,6 @@ mod tests { Ok(()) } - #[cfg(unix)] #[tokio::test] #[ignore] // Ignored while we have a better way to test this. async fn requests_with_large_timeout_are_capped() -> Result<(), UnifiedExecError> { @@ -735,7 +724,6 @@ mod tests { Ok(()) } - #[cfg(unix)] #[tokio::test] #[ignore] // Ignored while we have a better way to test this. async fn completed_commands_do_not_persist_sessions() -> Result<(), UnifiedExecError> { @@ -765,7 +753,6 @@ mod tests { Ok(()) } - #[cfg(unix)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn reusing_completed_session_returns_unknown_session() -> Result<(), UnifiedExecError> { skip_if_sandbox!(Ok(()));