mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve local path conventions in automatic approvals (#32261)
## Why Drive-shaped POSIX paths such as `/C:/workspace` can be mistaken for Windows paths when an automatic approval request converts them from `PathUri`. ## What changed - Keep approval paths as `PathUri` values together with their environment ID until the automatic review request is built. - Recover host-native paths for local working directories when strict conversion cannot determine the path convention. - Continue rejecting incompatible paths from remote environments. ## Testing Add coverage for drive-shaped local POSIX paths, foreign remote paths, and preserving apply-patch path URIs while building approval actions. GitOrigin-RevId: 3fd31cfb4e8b46f9968ff66d5e986ca777430185
This commit is contained in:
1 parent
9993fb838a
commit
b66c25c6a3
8 files changed
+166
-39
No files matched your search
@@ -73,23 +73,14 @@ impl ApplyPatchRuntime {
|
||||
&self.committed_delta
|
||||
}
|
||||
|
||||
fn build_guardian_review_request(
|
||||
req: &ApplyPatchRequest,
|
||||
call_id: &str,
|
||||
) -> std::io::Result<ApprovalAction> {
|
||||
// TODO(anp): Remove this conversion once the guardian API supports PathUri.
|
||||
let cwd = req.action.cwd.to_abs_path()?;
|
||||
let files = req
|
||||
.file_paths
|
||||
.iter()
|
||||
.map(PathUri::to_abs_path)
|
||||
.collect::<std::io::Result<Vec<_>>>()?;
|
||||
Ok(ApprovalAction::ApplyPatch {
|
||||
fn build_approval_action(req: &ApplyPatchRequest, call_id: &str) -> ApprovalAction {
|
||||
ApprovalAction::ApplyPatch {
|
||||
id: call_id.to_string(),
|
||||
cwd,
|
||||
files,
|
||||
environment_id: req.turn_environment.environment_id.clone(),
|
||||
cwd: req.action.cwd.clone(),
|
||||
files: req.file_paths.clone(),
|
||||
patch: req.action.patch.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn file_system_sandbox_context_for_attempt(
|
||||
@@ -188,7 +179,7 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
req: &ApplyPatchRequest,
|
||||
ctx: &ApprovalCtx<'_>,
|
||||
) -> std::io::Result<ApprovalAction> {
|
||||
ApplyPatchRuntime::build_guardian_review_request(req, ctx.call_id)
|
||||
Ok(ApplyPatchRuntime::build_approval_action(req, ctx.call_id))
|
||||
}
|
||||
|
||||
fn wants_no_sandbox_approval(&self, policy: AskForApproval) -> bool {
|
||||
|
||||
@@ -49,24 +49,17 @@ fn wants_no_sandbox_approval_granular_respects_sandbox_flag() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guardian_review_request_includes_patch_context() {
|
||||
let path = std::env::temp_dir()
|
||||
.join("guardian-apply-patch-test.txt")
|
||||
.abs();
|
||||
let action =
|
||||
ApplyPatchAction::new_add_for_test(&PathUri::from_abs_path(&path), "hello".to_string());
|
||||
let expected_cwd = action.cwd.to_abs_path().expect("native patch cwd");
|
||||
async fn approval_action_preserves_patch_path_uris() {
|
||||
let path = PathUri::parse("file:///C:/workspace/guardian-apply-patch-test.txt")
|
||||
.expect("valid foreign path URI");
|
||||
let action = ApplyPatchAction::new_add_for_test(&path, "hello".to_string());
|
||||
let expected_cwd = action.cwd.clone();
|
||||
let expected_patch = action.patch.clone();
|
||||
let request = ApplyPatchRequest {
|
||||
turn_environment: test_turn_environment(codex_exec_server::LOCAL_ENVIRONMENT_ID),
|
||||
action,
|
||||
file_paths: vec![PathUri::from_abs_path(&path)],
|
||||
changes: HashMap::from([(
|
||||
path.to_path_buf(),
|
||||
FileChange::Add {
|
||||
content: "hello".to_string(),
|
||||
},
|
||||
)]),
|
||||
file_paths: vec![path.clone()],
|
||||
changes: HashMap::new(),
|
||||
exec_approval_requirement: ExecApprovalRequirement::NeedsApproval {
|
||||
reason: None,
|
||||
proposed_execpolicy_amendment: None,
|
||||
@@ -75,13 +68,13 @@ async fn guardian_review_request_includes_patch_context() {
|
||||
permissions_preapproved: false,
|
||||
};
|
||||
|
||||
let guardian_request = ApplyPatchRuntime::build_guardian_review_request(&request, "call-1")
|
||||
.expect("native guardian request cwd");
|
||||
let approval_action = ApplyPatchRuntime::build_approval_action(&request, "call-1");
|
||||
|
||||
assert_eq!(
|
||||
guardian_request,
|
||||
approval_action,
|
||||
ApprovalAction::ApplyPatch {
|
||||
id: "call-1".to_string(),
|
||||
environment_id: codex_exec_server::LOCAL_ENVIRONMENT_ID.to_string(),
|
||||
cwd: expected_cwd,
|
||||
files: vec![path],
|
||||
patch: expected_patch,
|
||||
|
||||
@@ -46,6 +46,7 @@ use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_sandboxing::SandboxablePreference;
|
||||
use codex_shell_command::powershell::prefix_powershell_script_with_utf8;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use futures::future::BoxFuture;
|
||||
use std::collections::HashMap;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -183,8 +184,9 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
) -> std::io::Result<ApprovalAction> {
|
||||
Ok(ApprovalAction::Shell {
|
||||
id: ctx.call_id.to_string(),
|
||||
environment_id: req.turn_environment.environment_id.clone(),
|
||||
command: req.command.clone(),
|
||||
cwd: req.cwd.clone(),
|
||||
cwd: PathUri::from_abs_path(&req.cwd),
|
||||
sandbox_permissions: req.sandbox_permissions,
|
||||
additional_permissions: req.additional_permissions.clone(),
|
||||
justification: req.justification.clone(),
|
||||
|
||||
@@ -223,8 +223,9 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
|
||||
) -> std::io::Result<ApprovalAction> {
|
||||
Ok(ApprovalAction::ExecCommand {
|
||||
id: ctx.call_id.to_string(),
|
||||
environment_id: req.turn_environment.environment_id.clone(),
|
||||
command: req.command.clone(),
|
||||
cwd: req.cwd.to_abs_path()?,
|
||||
cwd: req.cwd.clone(),
|
||||
sandbox_permissions: req.sandbox_permissions,
|
||||
additional_permissions: req.additional_permissions.clone(),
|
||||
justification: req.justification.clone(),
|
||||
|
||||
Reference in new issue
Block a user