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
This commit is contained in:
Dmitriy Kovalenko
2026-11-23 20:25:06 +00:00
committed by copyberry
parent 06d76ee77b
commit 91f5c31ddb
9 changed files with 26 additions and 15 deletions
@@ -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(())
+6 -4
View File
@@ -161,18 +161,20 @@ async fn run_cloud_sandbox(args: &[&str], bundle: Value) -> Result<Option<TempDi
.map(|request| request.url.path().to_string())
.collect();
let stderr = String::from_utf8_lossy(&output.stderr);
let nested_macos_sandbox_unavailable = cfg!(target_os = "macos")
let nested_sandbox_unavailable = (cfg!(target_os = "macos")
&& output.status.code() == Some(71)
&& stderr.contains("sandbox-exec: sandbox_apply: Operation not permitted");
&& stderr.contains("sandbox-exec: sandbox_apply: Operation not permitted"))
|| (cfg!(target_os = "linux")
&& stderr.contains("bwrap: Failed to make / slave: Permission denied"));
assert!(
output.status.success() || nested_macos_sandbox_unavailable,
output.status.success() || nested_sandbox_unavailable,
"cloud-managed sandbox profile was not enforced: status={:?}; stdout={}; stderr={}; cloud bundle requests={cloud_bundle_request_paths:?}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
stderr,
);
if !nested_macos_sandbox_unavailable {
if !nested_sandbox_unavailable {
assert!(
String::from_utf8(output.stdout)?.starts_with("codex"),
"expected the sandboxed Codex version command to run",
+4 -2
View File
@@ -17,8 +17,10 @@ const LOOPBACK: &str = "127.0.0.2";
fn sandbox_unavailable(stderr: &str) -> Result<bool> {
#[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")]
@@ -53,13 +53,12 @@ fn sandbox_available() -> Result<bool> {
.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!(
+2 -2
View File
@@ -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}`);
@@ -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))
@@ -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",
];
@@ -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
@@ -1895,7 +1895,8 @@ async fn worktrees_overview_groups_by_project_or_directory() {
.collect::<Vec<_>>()
.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"}, {