Skip to content

Commit 981e2f7

Browse files
correctly recognize WorkspaceWrite policy on /approvals (#7301)
the `/approvals` popup fails to recognize that the CLI is in WorkspaceWrite mode if that policy has extra bits, like `writable_roots` etc. This change matches the policy, ignoring additional config aspects.
1 parent 401f94c commit 981e2f7

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

codex-rs/tui/src/chatwidget.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ impl ChatWidget {
23322332
let presets: Vec<ApprovalPreset> = builtin_approval_presets();
23332333
for preset in presets.into_iter() {
23342334
let is_current =
2335-
current_approval == preset.approval && current_sandbox == preset.sandbox;
2335+
Self::preset_matches_current(current_approval, &current_sandbox, &preset);
23362336
let name = preset.label.to_string();
23372337
let description_text = preset.description;
23382338
let description = Some(description_text.to_string());
@@ -2420,6 +2420,28 @@ impl ChatWidget {
24202420
})]
24212421
}
24222422

2423+
fn preset_matches_current(
2424+
current_approval: AskForApproval,
2425+
current_sandbox: &SandboxPolicy,
2426+
preset: &ApprovalPreset,
2427+
) -> bool {
2428+
if current_approval != preset.approval {
2429+
return false;
2430+
}
2431+
matches!(
2432+
(&preset.sandbox, current_sandbox),
2433+
(SandboxPolicy::ReadOnly, SandboxPolicy::ReadOnly)
2434+
| (
2435+
SandboxPolicy::DangerFullAccess,
2436+
SandboxPolicy::DangerFullAccess
2437+
)
2438+
| (
2439+
SandboxPolicy::WorkspaceWrite { .. },
2440+
SandboxPolicy::WorkspaceWrite { .. }
2441+
)
2442+
)
2443+
}
2444+
24232445
#[cfg(target_os = "windows")]
24242446
pub(crate) fn world_writable_warning_details(&self) -> Option<(Vec<String>, usize, bool)> {
24252447
if self

codex-rs/tui/src/chatwidget/tests.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,29 @@ fn approvals_selection_popup_snapshot() {
15671567
assert_snapshot!("approvals_selection_popup", popup);
15681568
}
15691569

1570+
#[test]
1571+
fn preset_matching_ignores_extra_writable_roots() {
1572+
let preset = builtin_approval_presets()
1573+
.into_iter()
1574+
.find(|p| p.id == "auto")
1575+
.expect("auto preset exists");
1576+
let current_sandbox = SandboxPolicy::WorkspaceWrite {
1577+
writable_roots: vec![PathBuf::from("C:\\extra")],
1578+
network_access: false,
1579+
exclude_tmpdir_env_var: false,
1580+
exclude_slash_tmp: false,
1581+
};
1582+
1583+
assert!(
1584+
ChatWidget::preset_matches_current(AskForApproval::OnRequest, &current_sandbox, &preset),
1585+
"WorkspaceWrite with extra roots should still match the Agent preset"
1586+
);
1587+
assert!(
1588+
!ChatWidget::preset_matches_current(AskForApproval::Never, &current_sandbox, &preset),
1589+
"approval mismatch should prevent matching the preset"
1590+
);
1591+
}
1592+
15701593
#[test]
15711594
fn full_access_confirmation_popup_snapshot() {
15721595
let (mut chat, _rx, _op_rx) = make_chatwidget_manual();

0 commit comments

Comments
 (0)