diff options
| author | Stephen Hurd <shurd@FreeBSD.org> | 2026-10-02 17:50:37 +0000 |
|---|---|---|
| committer | Hiroki Tagato <tagattie@FreeBSD.org> | 2026-10-02 17:52:24 +0000 |
| commit | 98cb9236fbeac266df58282f630b20de653088b8 (patch) | |
| tree | 50ef08d68bcff42e1092d66656506b791cba7d1c | |
| parent | 7a6a7307f98bba662c074b28e4f4596e14e672f7 (diff) | |
misc/codex: Restore apply_patch's ability for deleting files
PR: 298698
Reported by: shurd
4 files changed, 52 insertions, 6 deletions
diff --git a/misc/codex/Makefile b/misc/codex/Makefile index ab73d945e7c9..69944a669735 100644 --- a/misc/codex/Makefile +++ b/misc/codex/Makefile @@ -1,6 +1,7 @@ PORTNAME= codex DISTVERSIONPREFIX= rust-v DISTVERSION= 0.155.1 +PORTREVISION= 1 CATEGORIES= misc devel MAINTAINER= tagattie@FreeBSD.org diff --git a/misc/codex/files/patch-codex-rs_core_src_tools_handlers_apply__patch.rs b/misc/codex/files/patch-codex-rs_core_src_tools_handlers_apply__patch.rs index 8d6e8a90ed36..78bb9592268b 100644 --- a/misc/codex/files/patch-codex-rs_core_src_tools_handlers_apply__patch.rs +++ b/misc/codex/files/patch-codex-rs_core_src_tools_handlers_apply__patch.rs @@ -1,4 +1,4 @@ ---- codex-rs/core/src/tools/handlers/apply_patch.rs.orig 2026-09-09 21:43:48 UTC +--- codex-rs/core/src/tools/handlers/apply_patch.rs.orig 2026-10-02 02:01:57 UTC +++ codex-rs/core/src/tools/handlers/apply_patch.rs @@ -43,6 +43,7 @@ use codex_exec_server::ExecutorFileSystem; use codex_apply_patch::Hunk; @@ -12,9 +12,9 @@ } } -+fn apply_patch_verification_sandbox<'a>( ++pub(crate) fn apply_patch_file_system_sandbox<'a>( + environment: &TurnEnvironment, -+ sandbox: &'a FileSystemSandboxContext, ++ sandbox: Option<&'a FileSystemSandboxContext>, +) -> Option<&'a FileSystemSandboxContext> { + if cfg!(any(target_os = "openbsd", target_os = "freebsd")) + && !environment.environment.is_remote() @@ -25,7 +25,7 @@ + { + None + } else { -+ Some(sandbox) ++ sandbox + } +} + @@ -37,7 +37,7 @@ let fs = turn_environment.environment.get_filesystem(); let sandbox = turn_environment.sandbox_context(/*additional_permissions*/ None); + let verification_sandbox = -+ apply_patch_verification_sandbox(turn_environment, &sandbox); ++ apply_patch_file_system_sandbox(turn_environment, Some(&sandbox)); match codex_apply_patch::verify_apply_patch_args_with_mode( args, turn_environment.cwd(), @@ -52,7 +52,7 @@ ) -> Result<Option<FunctionToolOutput>, FunctionCallError> { let turn = &step_context.turn; let sandbox = turn_environment.sandbox_context(/*additional_permissions*/ None); -+ let verification_sandbox = apply_patch_verification_sandbox(&turn_environment, &sandbox); ++ let verification_sandbox = apply_patch_file_system_sandbox(&turn_environment, Some(&sandbox)); match codex_apply_patch::maybe_parse_apply_patch_verified_with_mode( command, cwd, diff --git a/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch.rs b/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch.rs new file mode 100644 index 000000000000..14ab769e49a1 --- /dev/null +++ b/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch.rs @@ -0,0 +1,27 @@ +--- codex-rs/core/src/tools/runtimes/apply_patch.rs.orig 2026-09-18 19:04:49 UTC ++++ codex-rs/core/src/tools/runtimes/apply_patch.rs +@@ -5,6 +5,7 @@ use crate::session::turn_context::TurnEnvironment; + //! sandboxing enforced by the explicit filesystem sandbox context. + use crate::exec::is_likely_sandbox_denied; + use crate::session::turn_context::TurnEnvironment; ++use crate::tools::handlers::apply_patch::apply_patch_file_system_sandbox; + use crate::tools::sandboxing::Approvable; + use crate::tools::sandboxing::ApprovalAction; + use crate::tools::sandboxing::ExecApprovalRequirement; +@@ -174,6 +175,7 @@ impl ToolRuntime<ApplyPatchRequest, ApplyPatchRuntimeO + let started_at = Instant::now(); + let fs = req.turn_environment.environment.get_filesystem(); + let sandbox = Self::file_system_sandbox_context_for_attempt(req, attempt); ++ let sandbox = apply_patch_file_system_sandbox(&req.turn_environment, sandbox.as_ref()); + let mut stdout = Vec::new(); + let mut stderr = Vec::new(); + let result = codex_apply_patch::apply_patch_with_options( +@@ -193,7 +195,7 @@ impl ToolRuntime<ApplyPatchRequest, ApplyPatchRuntimeO + &mut stdout, + &mut stderr, + fs.as_ref(), +- sandbox.as_ref(), ++ sandbox, + ) + .await; + let stdout = String::from_utf8_lossy(&stdout).into_owned(); diff --git a/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch__tests.rs b/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch__tests.rs new file mode 100644 index 000000000000..7c59ed22ecd9 --- /dev/null +++ b/misc/codex/files/patch-codex-rs_core_src_tools_runtimes_apply__patch__tests.rs @@ -0,0 +1,18 @@ +--- codex-rs/core/src/tools/runtimes/apply_patch_tests.rs.orig 2026-09-18 19:04:49 UTC ++++ codex-rs/core/src/tools/runtimes/apply_patch_tests.rs +@@ -47,6 +47,15 @@ fn test_turn_environment(environment_id: &str) -> crat + ) + } + ++#[cfg(any(target_os = "freebsd", target_os = "openbsd"))] ++#[tokio::test] ++async fn local_bsd_omits_unenforceable_apply_patch_sandbox() { ++ let environment = test_turn_environment(codex_exec_server::LOCAL_ENVIRONMENT_ID); ++ let sandbox = environment.sandbox_context(/*additional_permissions*/ None); ++ ++ assert!(apply_patch_file_system_sandbox(&environment, Some(&sandbox)).is_none()); ++} ++ + #[test] + fn wants_no_sandbox_approval_granular_respects_sandbox_flag() { + let runtime = ApplyPatchRuntime::new(); |
