Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

correctly recognize WorkspaceWrite policy on /approvals (#7301)

iceweasel-oai981e2f742d61
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index 53c77f82be..fbabbc300e 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -2332,7 +2332,7 @@ impl ChatWidget {
let presets: Vec<ApprovalPreset> = builtin_approval_presets();
for preset in presets.into_iter() {
let is_current =
- current_approval == preset.approval && current_sandbox == preset.sandbox;
+ Self::preset_matches_current(current_approval, &current_sandbox, &preset);
let name = preset.label.to_string();
let description_text = preset.description;
let description = Some(description_text.to_string());
@@ -2420,6 +2420,28 @@ impl ChatWidget {
})]
}
+ fn preset_matches_current(
+ current_approval: AskForApproval,
+ current_sandbox: &SandboxPolicy,
+ preset: &ApprovalPreset,
+ ) -> bool {
+ if current_approval != preset.approval {
+ return false;
+ }
+ matches!(
+ (&preset.sandbox, current_sandbox),
+ (SandboxPolicy::ReadOnly, SandboxPolicy::ReadOnly)
+ | (
+ SandboxPolicy::DangerFullAccess,
+ SandboxPolicy::DangerFullAccess
+ )
+ | (
+ SandboxPolicy::WorkspaceWrite { .. },
+ SandboxPolicy::WorkspaceWrite { .. }
+ )
+ )
+ }
+
#[cfg(target_os = "windows")]
pub(crate) fn world_writable_warning_details(&self) -> Option<(Vec<String>, usize, bool)> {
if self
diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs
index 7b044e8dfb..fde52a0646 100644
--- a/codex-rs/tui/src/chatwidget/tests.rs
+++ b/codex-rs/tui/src/chatwidget/tests.rs
@@ -1567,6 +1567,29 @@ fn approvals_selection_popup_snapshot() {
assert_snapshot!("approvals_selection_popup", popup);
}
+#[test]
+fn preset_matching_ignores_extra_writable_roots() {
+ let preset = builtin_approval_presets()
+ .into_iter()
+ .find(|p| p.id == "auto")
+ .expect("auto preset exists");
+ let current_sandbox = SandboxPolicy::WorkspaceWrite {
+ writable_roots: vec![PathBuf::from("C:\\extra")],
+ network_access: false,
+ exclude_tmpdir_env_var: false,
+ exclude_slash_tmp: false,
+ };
+
+ assert!(
+ ChatWidget::preset_matches_current(AskForApproval::OnRequest, &current_sandbox, &preset),
+ "WorkspaceWrite with extra roots should still match the Agent preset"
+ );
+ assert!(
+ !ChatWidget::preset_matches_current(AskForApproval::Never, &current_sandbox, &preset),
+ "approval mismatch should prevent matching the preset"
+ );
+}
+
#[test]
fn full_access_confirmation_popup_snapshot() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual();