Fix tests

This commit is contained in:
jif-oai
2025-10-15 12:55:22 +01:00
parent 9865a0cfe1
commit b7e834a02b
4 changed files with 41 additions and 21 deletions

View File

@@ -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 {

View File

@@ -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<PathBuf>,
// Path to the codex binary itself (used by apply_patch backend to self-invoke when needed).
pub(crate) codex_exe: Option<PathBuf>,
}
@@ -41,16 +44,33 @@ impl ExecutorConfig {
pub(crate) fn new(
sandbox_policy: SandboxPolicy,
sandbox_cwd: PathBuf,
codex_linux_sandbox_exe: Option<PathBuf>,
codex_exe: Option<PathBuf>,
) -> 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<PathBuf>) -> Option<PathBuf> {
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(),
)
}

View File

@@ -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

View File

@@ -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<Session>, Arc<TurnContext>) {
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<Session>,
turn: &Arc<TurnContext>,
@@ -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(()));