mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Resolve Guardian command path conventions inside ReviewAction (#57507)
## What changed Move executor path-convention selection from the approval caller into `ReviewAction::from_approval_action`, using the supplied `GuardianReviewContext`. Preserve Windows and POSIX rendering based on the executor OS, with path inference for legacy executors that do not report an OS. ## Testing Update the command approval test to exercise `ReviewAction` with Windows, Linux, and legacy executor contexts, checking both approval JSON and assessment working directories. GitOrigin-RevId: b13fad1d4033976cb94b899b62a3779c97e171fa
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
//! Tool-call provenance is separate from the item's display identity.
|
||||
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_utils_path_uri::PathConvention;
|
||||
use std::sync::Arc;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
@@ -11,6 +12,7 @@ use super::GuardianReviewContext;
|
||||
use super::GuardianReviewOptions;
|
||||
use super::approval_request::guardian_approval_request_to_json;
|
||||
use crate::session::session::Session;
|
||||
use crate::tools::sandboxing::ApprovalAction;
|
||||
|
||||
/// Carries the original action even when the legacy synchronous renderer cannot handle its paths.
|
||||
/// This lets the extension return AskUser before invoking that renderer.
|
||||
@@ -49,9 +51,32 @@ impl From<GuardianApprovalRequest> for ReviewAction {
|
||||
|
||||
impl ReviewAction {
|
||||
pub(crate) fn from_approval_action(
|
||||
action: crate::tools::sandboxing::ApprovalAction,
|
||||
exec_command_cwd_convention: Option<codex_utils_path_uri::PathConvention>,
|
||||
action: ApprovalAction,
|
||||
context: &GuardianReviewContext,
|
||||
) -> Self {
|
||||
let exec_command_cwd_convention = match &action {
|
||||
ApprovalAction::ExecCommand {
|
||||
environment_id,
|
||||
cwd,
|
||||
..
|
||||
} => Some(
|
||||
match context
|
||||
.environments()
|
||||
.turn_environments()
|
||||
.find(|environment| environment.selection.environment_id == *environment_id)
|
||||
.and_then(|environment| environment.executor_platform_os.as_deref())
|
||||
{
|
||||
Some("windows") => PathConvention::Windows,
|
||||
Some(_) => PathConvention::Posix,
|
||||
// Legacy executors did not report their OS. Preserve the
|
||||
// previous spelling-based behavior for those executors.
|
||||
None => cwd
|
||||
.infer_path_convention()
|
||||
.unwrap_or_else(PathConvention::native),
|
||||
},
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
let category = action.guardian_scope();
|
||||
let original = serde_json::to_value(&action).map_err(|error| error.to_string());
|
||||
match action.into_guardian_request(exec_command_cwd_convention) {
|
||||
|
||||
@@ -1478,12 +1478,22 @@ fn guardian_write_stdin_preserves_input_and_foreign_cwd(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(codex_utils_path_uri::PathConvention::Windows, r"C:\workspace"; "windows")]
|
||||
#[test_case::test_case(codex_utils_path_uri::PathConvention::Posix, "/C:/workspace"; "posix")]
|
||||
fn guardian_exec_command_uses_executor_cwd_convention(
|
||||
cwd_convention: codex_utils_path_uri::PathConvention,
|
||||
#[test_case::test_case(Some("windows"), r"C:\workspace"; "windows")]
|
||||
#[test_case::test_case(Some("linux"), "/C:/workspace"; "posix")]
|
||||
#[test_case::test_case(None, r"C:\workspace"; "legacy")]
|
||||
#[tokio::test]
|
||||
async fn guardian_exec_command_uses_executor_cwd_convention(
|
||||
platform_os: Option<&str>,
|
||||
expected_cwd: &str,
|
||||
) -> serde_json::Result<()> {
|
||||
let (_session, mut turn) = crate::session::tests::make_session_and_context().await;
|
||||
let mut executor = turn.initial_environments.primary().unwrap().clone();
|
||||
executor.selection.environment_id = codex_exec_server::REMOTE_ENVIRONMENT_ID.to_string();
|
||||
executor.executor_platform_os = platform_os.map(str::to_owned);
|
||||
turn.initial_environments
|
||||
.environments
|
||||
.push(TurnEnvironmentState::Ready(executor));
|
||||
let context = GuardianReviewContext::from(Arc::new(turn));
|
||||
let cwd = PathUri::parse("file:///C:/workspace").expect("valid executor cwd");
|
||||
let action = crate::tools::sandboxing::ApprovalAction::ExecCommand {
|
||||
id: "command-1".to_string(),
|
||||
@@ -1496,9 +1506,10 @@ fn guardian_exec_command_uses_executor_cwd_convention(
|
||||
justification: None,
|
||||
tty: false,
|
||||
proposed_execpolicy_amendment: None,
|
||||
}
|
||||
.into_guardian_request(Some(cwd_convention))
|
||||
.expect("Guardian request should render executor cwd");
|
||||
};
|
||||
let action = ReviewAction::from_approval_action(action, &context)
|
||||
.request
|
||||
.expect("Guardian request should render executor cwd");
|
||||
|
||||
assert_eq!(
|
||||
guardian_approval_request_to_json(&action)?,
|
||||
|
||||
@@ -623,34 +623,7 @@ impl Session {
|
||||
}
|
||||
let is_network_approval = matches!(&action, ApprovalAction::NetworkAccess { .. });
|
||||
let review_id = new_guardian_review_id();
|
||||
let exec_command_cwd_convention = match &action {
|
||||
ApprovalAction::ExecCommand {
|
||||
environment_id,
|
||||
cwd,
|
||||
..
|
||||
} => Some(
|
||||
match ctx
|
||||
.review_context
|
||||
.environments()
|
||||
.turn_environments()
|
||||
.find(|environment| environment.selection.environment_id == *environment_id)
|
||||
.and_then(|environment| environment.executor_platform_os.as_deref())
|
||||
{
|
||||
Some("windows") => PathConvention::Windows,
|
||||
Some(_) => PathConvention::Posix,
|
||||
// Legacy executors did not report their OS. Preserve the
|
||||
// previous spelling-based behavior for those executors.
|
||||
None => cwd
|
||||
.infer_path_convention()
|
||||
.unwrap_or_else(PathConvention::native),
|
||||
},
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
let action = crate::guardian::ReviewAction::from_approval_action(
|
||||
action,
|
||||
exec_command_cwd_convention,
|
||||
);
|
||||
let action = crate::guardian::ReviewAction::from_approval_action(action, &context);
|
||||
|
||||
let reasons = ApprovalRequestReasons {
|
||||
approval: ctx.approval_reason.clone(),
|
||||
|
||||
Reference in New Issue
Block a user