From 7e97da7c13db7118b8a377ad52739008303b336c Mon Sep 17 00:00:00 2001 From: jif-oai Date: Wed, 13 May 2026 10:39:07 +0200 Subject: [PATCH] chore: Keep view_image sandbox test in temp dir (#22355) ## Summary - move the `view_image` sandbox filesystem-read unit test onto a temporary cwd - keep the turn cwd and selected turn environment cwd aligned inside the test - avoid leaving `core/image.png` behind in the repo checkout after the test runs ## Root cause The test wrote `image.png` beneath `turn.cwd`, and the shared session test helper defaults that cwd to the current repo directory when no override is provided. ## Validation - `just fmt` - `cargo test -p codex-core tools::handlers::view_image::tests::handle_passes_sandbox_context_for_local_filesystem_reads` --- codex-rs/core/src/tools/handlers/view_image.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rs index 652e8c0eb6..f7f5cfd4d4 100644 --- a/codex-rs/core/src/tools/handlers/view_image.rs +++ b/codex-rs/core/src/tools/handlers/view_image.rs @@ -248,6 +248,7 @@ mod tests { use crate::tools::context::ToolInvocation; use crate::turn_diff_tracker::TurnDiffTracker; use codex_protocol::models::PermissionProfile; + use core_test_support::TempDirExt; use pretty_assertions::assert_eq; use serde_json::json; use std::sync::Arc; @@ -276,7 +277,15 @@ mod tests { #[tokio::test] async fn handle_passes_sandbox_context_for_local_filesystem_reads() { let (session, mut turn) = make_session_and_context().await; - let image_path = turn.cwd.join("image.png"); + let image_dir = tempfile::tempdir().expect("create image temp dir"); + let image_cwd = image_dir.abs(); + turn.cwd = image_cwd.clone(); + turn.environments + .turn_environments + .first_mut() + .expect("default local turn environment") + .cwd = image_cwd.clone(); + let image_path = image_cwd.join("image.png"); std::fs::write(image_path.as_path(), b"not a real image").expect("write test image"); turn.permission_profile = PermissionProfile::read_only();