From 91f5c31ddbea55f63457cbee36a1f218dd0a99ae Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Mon, 23 Nov 2026 18:46:42 +0000 Subject: [PATCH] Make Codex tests more portable across environments (#63427) ## Why Read-only Bazel runfiles can leave copied patch fixtures unwritable, and restricted Linux environments can deny the mount setup Bubblewrap needs. Test environments can also lack Python or use paths long enough to produce identical truncated worktree headings. ## What changed - Write fresh, writable copies of patch scenario inputs. - Treat Bubblewrap's mount permission error as sandbox unavailability in the CLI and Linux sandbox tests. - Use `printf` and `tr` to generate output for code mode truncation tests. - Normalize one worktree heading at a time in the overview snapshot. GitOrigin-RevId: 88590c9c08a739ecdd4ed49bd41734b02ece3f66 --- codex-rs/apply-patch/tests/suite/scenarios.rs | 3 ++- codex-rs/cli/tests/sandbox_cloud_config.rs | 10 ++++++---- codex-rs/cli/tests/sandbox_network_proxy.rs | 6 ++++-- codex-rs/cli/tests/shared_sandbox_launcher.rs | 9 ++++----- codex-rs/core/tests/suite/code_mode.rs | 4 ++-- codex-rs/linux-sandbox/tests/suite/bwrap_path.rs | 1 + codex-rs/linux-sandbox/tests/suite/managed_proxy.rs | 1 + codex-rs/linux-sandbox/tests/suite/sandbox.rs | 4 ++++ codex-rs/tui/src/app/agents_overview_tests.rs | 3 ++- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/codex-rs/apply-patch/tests/suite/scenarios.rs b/codex-rs/apply-patch/tests/suite/scenarios.rs index 4c0aa11cd4..a13c6b976a 100644 --- a/codex-rs/apply-patch/tests/suite/scenarios.rs +++ b/codex-rs/apply-patch/tests/suite/scenarios.rs @@ -124,7 +124,8 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> { if let Some(parent) = dest_path.parent() { fs::create_dir_all(parent)?; } - fs::copy(&path, &dest_path)?; + // Scenario inputs must be writable even when Bazel runfiles are read-only. + fs::write(&dest_path, fs::read(&path)?)?; } } Ok(()) diff --git a/codex-rs/cli/tests/sandbox_cloud_config.rs b/codex-rs/cli/tests/sandbox_cloud_config.rs index dfaded50cd..cd29c0dc52 100644 --- a/codex-rs/cli/tests/sandbox_cloud_config.rs +++ b/codex-rs/cli/tests/sandbox_cloud_config.rs @@ -161,18 +161,20 @@ async fn run_cloud_sandbox(args: &[&str], bundle: Value) -> Result Result { #[cfg(target_os = "linux")] - if stderr.contains("bubblewrap is unavailable") { - eprintln!("skipping network proxy sandbox test: bubblewrap is unavailable"); + if stderr.contains("bubblewrap is unavailable") + || stderr.contains("bwrap: Failed to make / slave: Permission denied") + { + eprintln!("skipping network proxy sandbox test: {stderr}"); return Ok(true); } #[cfg(target_os = "macos")] diff --git a/codex-rs/cli/tests/shared_sandbox_launcher.rs b/codex-rs/cli/tests/shared_sandbox_launcher.rs index a0e765e0a0..bacd92e9dc 100644 --- a/codex-rs/cli/tests/shared_sandbox_launcher.rs +++ b/codex-rs/cli/tests/shared_sandbox_launcher.rs @@ -53,13 +53,12 @@ fn sandbox_available() -> Result { .args(["sandbox", "--", "/usr/bin/true"]) .env("CODEX_HOME", home.path()) .output()?; + let stderr = String::from_utf8_lossy(&probe.stderr); if !probe.status.success() - && String::from_utf8_lossy(&probe.stderr).contains("Operation not permitted") + && (stderr.contains("Operation not permitted") + || stderr.contains("bwrap: Failed to make / slave: Permission denied")) { - eprintln!( - "skipping helper test: Linux sandbox is unavailable: {}", - String::from_utf8_lossy(&probe.stderr) - ); + eprintln!("skipping helper test: Linux sandbox is unavailable: {stderr}"); return Ok(false); } anyhow::ensure!( diff --git a/codex-rs/core/tests/suite/code_mode.rs b/codex-rs/core/tests/suite/code_mode.rs index a1936f85ef..fe7210190b 100644 --- a/codex-rs/core/tests/suite/code_mode.rs +++ b/codex-rs/core/tests/suite/code_mode.rs @@ -4867,7 +4867,7 @@ async fn code_mode_exec_nested_limit_truncates_result_variable_when_exceeded() - "use exec_command from code mode", r#"// @exec: {"max_output_tokens": 25000} const result = await tools.exec_command({ - cmd: "python3 -c \"import sys; sys.stdout.write('A' * 90000)\"", + cmd: "printf '%90000s' '' | tr ' ' A", max_output_tokens: 20000 }); const resultVariableWasTruncated = result.output.includes("…2500 tokens truncated…"); @@ -4998,7 +4998,7 @@ async fn code_mode_exec_without_nested_limit_preserves_result_variable_before_co "use exec_command from code mode", r#"// @exec: {"max_output_tokens": 20000} const result = await tools.exec_command({ - cmd: "python3 -c \"import sys; sys.stdout.write('x' * 50000)\"" + cmd: "printf '%50000s' '' | tr ' ' x" }); const resultVariableWasTruncated = result.output.length !== 50000; text(`Variable truncated: ${resultVariableWasTruncated ? "True" : "False"}. Variable: ${result.output}`); diff --git a/codex-rs/linux-sandbox/tests/suite/bwrap_path.rs b/codex-rs/linux-sandbox/tests/suite/bwrap_path.rs index 33a3788633..84a8024450 100644 --- a/codex-rs/linux-sandbox/tests/suite/bwrap_path.rs +++ b/codex-rs/linux-sandbox/tests/suite/bwrap_path.rs @@ -63,6 +63,7 @@ fn child_workdir_does_not_probe_or_launch_writable_parent_bwrap() { "bubblewrap is unavailable", "No permissions to create a new namespace", "setting up uid map: Permission denied", + "bwrap: Failed to make / slave: Permission denied", ] .iter() .any(|message| stderr.contains(message)) diff --git a/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs b/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs index 82124b7b6e..6acb5a110e 100644 --- a/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs +++ b/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs @@ -53,6 +53,7 @@ const MANAGED_PROXY_PERMISSION_ERR_SNIPPETS: &[&str] = &[ "loopback: Failed RTM_NEWLINK", "setting up uid map: Permission denied", "No permissions to create a new namespace", + "bwrap: Failed to make / slave: Permission denied", "error isolating Linux network namespace for proxy mode", ]; diff --git a/codex-rs/linux-sandbox/tests/suite/sandbox.rs b/codex-rs/linux-sandbox/tests/suite/sandbox.rs index e0167df88c..a57141e859 100644 --- a/codex-rs/linux-sandbox/tests/suite/sandbox.rs +++ b/codex-rs/linux-sandbox/tests/suite/sandbox.rs @@ -217,6 +217,10 @@ async fn run_cmd_result_with_permission_profile_for_cwd( fn is_bwrap_unavailable_output(output: &codex_protocol::exec_output::ExecToolCallOutput) -> bool { output.stderr.text.contains(BWRAP_UNAVAILABLE_ERR) + || output + .stderr + .text + .contains("bwrap: Failed to make / slave: Permission denied") || (output .stderr .text diff --git a/codex-rs/tui/src/app/agents_overview_tests.rs b/codex-rs/tui/src/app/agents_overview_tests.rs index 7f6dd422db..fa94a64087 100644 --- a/codex-rs/tui/src/app/agents_overview_tests.rs +++ b/codex-rs/tui/src/app/agents_overview_tests.rs @@ -1895,7 +1895,8 @@ async fn worktrees_overview_groups_by_project_or_directory() { .collect::>() .join("\n"); for (heading, stable) in directory_headings.iter().rev() { - directory_grouping = directory_grouping.replace(heading, stable); + // Long paths can truncate to the same heading for both worktrees. + directory_grouping = directory_grouping.replacen(heading, stable, 1); } let directory_grouping = directory_grouping.replace('\\', "/"); insta::with_settings!({snapshot_path => "../snapshots"}, {