mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Support inline permission profile selection with /permissions (#54383)
## What changed Allow `/permissions <profile-id>` to select a built-in or custom permission profile, for example `/permissions :read-only`. Support `:ask-for-approval` and `:approve-for-me` aliases while preserving feature gates, profile requirements, full-access confirmation, and Windows sandbox setup. Hold queued input until the selection is confirmed, and retain it on cancellation or failure. Reload custom profile definitions on re-selection without leaving unchanged requests pending. ## Testing Add coverage for unknown and disabled profiles, approval aliases, confirmation and cancellation, discovery retries, Windows sandbox setup, and queued prompts waiting for server confirmation. GitOrigin-RevId: ada38d3cfc6d6ac4e84ce5645fe33432c55d63cc
This commit is contained in:
@@ -130,6 +130,7 @@ impl ChatWidget {
|
||||
model_popup_request_id: None,
|
||||
permission_popup_request_id: None,
|
||||
permission_discovery: None,
|
||||
inline_permission_profile_selection: None,
|
||||
worktree_popup_request_id: None,
|
||||
permission_profiles_menu_opened: false,
|
||||
model_popup_model_ids: Vec::new(),
|
||||
|
||||
@@ -125,6 +125,12 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
pub(super) fn on_modal_or_popup_closed(&mut self) {
|
||||
if self.apply_pending_permission_profile() {
|
||||
return;
|
||||
}
|
||||
if self.cancel_pending_permission_profile_selection() {
|
||||
return;
|
||||
}
|
||||
if self.input_queue.suppress_queue_autosend {
|
||||
self.app_event_tx.send(AppEvent::SettingsSelectionClosed);
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,22 @@ use crate::permission_discovery::PermissionDiscovery;
|
||||
|
||||
pub(super) const VIEW_ID: &str = "permission-profiles";
|
||||
|
||||
pub(super) enum InlinePermissionProfileSelection {
|
||||
Discovering(String),
|
||||
Applying,
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn select_permission_profile_by_id(&mut self, profile_id: &str) {
|
||||
self.set_queue_autosend_suppressed(/*suppressed*/ true);
|
||||
self.inline_permission_profile_selection = Some(
|
||||
InlinePermissionProfileSelection::Discovering(profile_id.to_string()),
|
||||
);
|
||||
if !self.apply_pending_permission_profile() {
|
||||
self.request_permission_profiles();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn retain_input_after_failed_permission_selection(&mut self) {
|
||||
self.input_queue.recovered_queue |= self.input_queue.has_queued_follow_up_messages()
|
||||
|| !self.input_queue.pending_steers.is_empty();
|
||||
@@ -13,6 +28,54 @@ impl ChatWidget {
|
||||
self.restore_user_message_to_composer(message);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn apply_pending_permission_profile(&mut self) -> bool {
|
||||
let Some(discovery) = self.permission_discovery.clone() else {
|
||||
return false;
|
||||
};
|
||||
let Some(profile_id) = self.pending_permission_profile_id().map(str::to_owned) else {
|
||||
return false;
|
||||
};
|
||||
self.inline_permission_profile_selection = Some(InlinePermissionProfileSelection::Applying);
|
||||
if !self.try_select_permission_profile_by_id(&discovery, &profile_id) {
|
||||
self.recover_inline_permission_profile_selection();
|
||||
}
|
||||
self.app_event_tx.send(AppEvent::SettingsSelectionClosed);
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) fn cancel_pending_permission_profile_selection(&mut self) -> bool {
|
||||
if self.pending_permission_profile_id().is_none() {
|
||||
return false;
|
||||
}
|
||||
self.recover_inline_permission_profile_selection();
|
||||
self.app_event_tx.send(AppEvent::SettingsSelectionClosed);
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn complete_inline_permission_profile_selection(&mut self) -> bool {
|
||||
self.inline_permission_profile_selection.take().is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn recover_inline_permission_profile_selection(&mut self) -> bool {
|
||||
if !self.complete_inline_permission_profile_selection() {
|
||||
return false;
|
||||
}
|
||||
self.retain_input_after_failed_permission_selection();
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn inline_permission_profile_selection_pending(&self) -> bool {
|
||||
self.inline_permission_profile_selection.is_some()
|
||||
}
|
||||
|
||||
fn pending_permission_profile_id(&self) -> Option<&str> {
|
||||
match self.inline_permission_profile_selection.as_ref() {
|
||||
Some(InlinePermissionProfileSelection::Discovering(profile_id)) => Some(profile_id),
|
||||
Some(InlinePermissionProfileSelection::Applying) | None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn request_permission_profiles(&mut self) {
|
||||
self.bottom_pane.dismiss_view_by_id(VIEW_ID);
|
||||
if let Some(discovery) = self.permission_discovery.clone() {
|
||||
@@ -44,6 +107,9 @@ impl ChatWidget {
|
||||
pub(super) fn invalidate_permission_discovery(&mut self) {
|
||||
self.permission_popup_request_id = None;
|
||||
self.bottom_pane.dismiss_view_by_id(VIEW_ID);
|
||||
if self.recover_inline_permission_profile_selection() {
|
||||
self.app_event_tx.send(AppEvent::SettingsSelectionClosed);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn permission_popup_request_is_current(&self, request_id: uuid::Uuid) -> bool {
|
||||
@@ -63,26 +129,46 @@ impl ChatWidget {
|
||||
self.permission_discovery = Some(discovery.clone());
|
||||
}
|
||||
if !self.bottom_pane.dismiss_active_view_if_id(VIEW_ID) {
|
||||
self.bottom_pane.dismiss_view_by_id(VIEW_ID);
|
||||
let was_covered = self.bottom_pane.dismiss_view_by_id(VIEW_ID);
|
||||
if was_covered && result.is_ok() {
|
||||
return;
|
||||
}
|
||||
if let Err(message) = result
|
||||
&& self.pending_permission_profile_id().is_some()
|
||||
{
|
||||
self.add_error_message(message);
|
||||
}
|
||||
self.cancel_pending_permission_profile_selection();
|
||||
return;
|
||||
}
|
||||
match result {
|
||||
Ok(discovery) => {
|
||||
self.permission_profiles_menu_opened = true;
|
||||
self.open_permission_profiles_popup(discovery);
|
||||
if !self.apply_pending_permission_profile() {
|
||||
self.permission_profiles_menu_opened = true;
|
||||
self.open_permission_profiles_popup(discovery);
|
||||
}
|
||||
}
|
||||
Err(message) => {
|
||||
let retry_profile_id = self.pending_permission_profile_id().map(str::to_owned);
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
view_id: Some(VIEW_ID),
|
||||
title: Some("Update Model Permissions".to_string()),
|
||||
subtitle: Some(message),
|
||||
items: vec![SelectionItem {
|
||||
name: "Retry".to_string(),
|
||||
actions: vec![Box::new(move |tx| {
|
||||
if let Some(profile_id) = retry_profile_id.clone() {
|
||||
tx.send(AppEvent::ResolvePermissionProfile { profile_id });
|
||||
} else {
|
||||
tx.send(AppEvent::OpenPermissionsPopup);
|
||||
}
|
||||
})],
|
||||
dismiss_on_select: false,
|
||||
..Default::default()
|
||||
}],
|
||||
..SelectionViewParams::picker()
|
||||
});
|
||||
}
|
||||
Err(message) => self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
view_id: Some(VIEW_ID),
|
||||
title: Some("Update Model Permissions".to_string()),
|
||||
subtitle: Some(message),
|
||||
items: vec![SelectionItem {
|
||||
name: "Retry".to_string(),
|
||||
actions: vec![Box::new(|tx| tx.send(AppEvent::OpenPermissionsPopup))],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
}],
|
||||
..SelectionViewParams::picker()
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::*;
|
||||
use crate::permission_discovery::PermissionDiscovery;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_WORKSPACE;
|
||||
|
||||
pub(super) fn permission_preset_description(preset: &ApprovalPreset) -> &'static str {
|
||||
match preset.id {
|
||||
@@ -49,6 +50,89 @@ pub(crate) fn cyber_model_approval_reviewer(config: &Config) -> Option<Approvals
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn try_select_permission_profile_by_id(
|
||||
&mut self,
|
||||
discovery: &PermissionDiscovery,
|
||||
profile_id: &str,
|
||||
) -> bool {
|
||||
let reviewer = match profile_id {
|
||||
":approve-for-me" if !self.config.features.enabled(Feature::GuardianApproval) => {
|
||||
self.add_error_message(
|
||||
"Approve for me is unavailable. Run `/permissions` to see available profiles."
|
||||
.into(),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
":approve-for-me" => ApprovalsReviewer::AutoReview,
|
||||
_ => ApprovalsReviewer::User,
|
||||
};
|
||||
let profile_id = match profile_id {
|
||||
":ask-for-approval" | ":approve-for-me" => BUILT_IN_PERMISSION_PROFILE_WORKSPACE,
|
||||
id => id,
|
||||
};
|
||||
let Some(profile) = discovery
|
||||
.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.id == profile_id)
|
||||
else {
|
||||
self.add_error_message(format!(
|
||||
"Unknown permission profile `{profile_id}`. Run `/permissions` to see available profiles."
|
||||
));
|
||||
return false;
|
||||
};
|
||||
let preset = builtin_approval_presets()
|
||||
.into_iter()
|
||||
.find(|preset| preset.active_permission_profile.id == profile_id);
|
||||
let approval_policy = preset
|
||||
.as_ref()
|
||||
.map(|preset| AskForApproval::from(preset.approval));
|
||||
let approvals_reviewer = preset.as_ref().map(|_| reviewer);
|
||||
if let Some(reason) = discovery.disabled_reason(
|
||||
profile_id,
|
||||
approval_policy,
|
||||
approvals_reviewer.map(Into::into),
|
||||
) {
|
||||
self.add_error_message(format!(
|
||||
"Permission profile `{profile_id}` is unavailable: {reason}."
|
||||
));
|
||||
return false;
|
||||
}
|
||||
let display_label =
|
||||
preset
|
||||
.as_ref()
|
||||
.map_or(profile.id.as_str(), |preset| match (preset.id, reviewer) {
|
||||
("auto", ApprovalsReviewer::AutoReview) => APPROVE_FOR_ME_LABEL,
|
||||
("auto", ApprovalsReviewer::User) => ASK_FOR_APPROVAL_LABEL,
|
||||
_ => preset.label,
|
||||
});
|
||||
let selection = PermissionProfileSelection {
|
||||
profile_id: profile_id.to_string(),
|
||||
approval_policy,
|
||||
approvals_reviewer,
|
||||
display_label: display_label.to_string(),
|
||||
};
|
||||
if let Some(preset) = preset {
|
||||
let Some(action) = self
|
||||
.permission_mode_actions(
|
||||
&preset,
|
||||
display_label.to_string(),
|
||||
reviewer,
|
||||
/*profile_selection*/ Some(selection),
|
||||
/*return_to_permissions*/ true,
|
||||
)
|
||||
.into_iter()
|
||||
.next()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
action(&self.app_event_tx);
|
||||
return true;
|
||||
}
|
||||
self.app_event_tx
|
||||
.send(AppEvent::SelectPermissionProfile(selection));
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) fn open_permission_profiles_popup(&mut self, discovery: PermissionDiscovery) {
|
||||
let active_profile_id = self
|
||||
.config
|
||||
|
||||
@@ -806,12 +806,26 @@ impl ChatWidget {
|
||||
source,
|
||||
} = prepared;
|
||||
let trimmed = args.trim();
|
||||
if trimmed.is_empty() {
|
||||
self.dispatch_command_from_source(cmd, source);
|
||||
return;
|
||||
}
|
||||
match cmd {
|
||||
SlashCommand::Model if !trimmed.is_empty() => {
|
||||
self.handle_model_command_args(trimmed);
|
||||
self.app_event_tx.send(AppEvent::SettingsSelectionClosed);
|
||||
}
|
||||
SlashCommand::Export if trimmed.is_empty() => self.show_transcript_export_popup(),
|
||||
SlashCommand::Permissions
|
||||
if self.windows_sandbox_local_server
|
||||
&& self.windows_sandbox_host != WindowsSandboxHost::Remote
|
||||
&& self.windows_sandbox_config.requirements.is_none() =>
|
||||
{
|
||||
self.set_queue_autosend_suppressed(/*suppressed*/ true);
|
||||
self.app_event_tx.send(AppEvent::ResolvePermissionProfile {
|
||||
profile_id: trimmed.to_string(),
|
||||
});
|
||||
}
|
||||
SlashCommand::Permissions => self.select_permission_profile_by_id(trimmed),
|
||||
SlashCommand::Export => {
|
||||
self.set_queue_autosend_suppressed(/*suppressed*/ true);
|
||||
self.app_event_tx.send(AppEvent::ExportTranscript {
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::legacy_core::config::PermissionProfileCatalogEntry;
|
||||
use crate::permission_discovery::PermissionDiscovery as Discovery;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_READ_ONLY;
|
||||
use codex_protocol::models::ManagedFileSystemPermissions;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
@@ -87,6 +88,208 @@ async fn permission_discovery_uses_server_catalog_for_remote_custom_selection()
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn permissions_command_waits_for_covering_modal_before_selecting_profile() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.select_permission_profile_by_id(BUILT_IN_PERMISSION_PROFILE_READ_ONLY);
|
||||
let request_id = assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::FetchPermissionProfiles { request_id, .. }) => request_id
|
||||
);
|
||||
chat.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
view_id: Some("other-modal"),
|
||||
title: Some("Other modal".to_string()),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
chat.on_permission_profiles_loaded(request_id, Ok(Discovery::local(&chat.config)));
|
||||
|
||||
assert_eq!(chat.bottom_pane.active_view_id(), Some("other-modal"));
|
||||
assert!(events.try_recv().is_err());
|
||||
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Esc));
|
||||
|
||||
assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::SelectPermissionProfile(PermissionProfileSelection { profile_id, .. }))
|
||||
if profile_id == BUILT_IN_PERMISSION_PROFILE_READ_ONLY
|
||||
);
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cancelled_permissions_command_does_not_apply_after_later_modal() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
chat.select_permission_profile_by_id(BUILT_IN_PERMISSION_PROFILE_READ_ONLY);
|
||||
let request_id = assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::FetchPermissionProfiles { request_id, .. }) => request_id
|
||||
);
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Esc));
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(chat.input_queue.recovered_queue);
|
||||
|
||||
chat.on_permission_profiles_loaded(request_id, Ok(Discovery::local(&chat.config)));
|
||||
chat.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
view_id: Some("other-modal"),
|
||||
title: Some("Other modal".to_string()),
|
||||
..Default::default()
|
||||
});
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Esc));
|
||||
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(
|
||||
events.try_recv().is_err(),
|
||||
"cancelled profile must not apply"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn permissions_command_preserves_full_access_confirmation() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.permission_discovery = Some(Discovery::local(&chat.config));
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
|
||||
chat.dispatch_command_with_args(
|
||||
SlashCommand::Permissions,
|
||||
BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS.to_string(),
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
let (preset, return_to_permissions, profile_selection) = assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::OpenFullAccessConfirmation {
|
||||
preset,
|
||||
return_to_permissions,
|
||||
profile_selection: Some(profile_selection),
|
||||
}) if preset.id == "full-access"
|
||||
&& profile_selection.profile_id == BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS
|
||||
=> (preset, return_to_permissions, Some(profile_selection))
|
||||
);
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
chat.open_full_access_confirmation(preset, return_to_permissions, profile_selection);
|
||||
|
||||
// Cancel returns to the picker; closing that picker must still recover the queue.
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::OpenPermissionsPopup));
|
||||
chat.open_permissions_popup();
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(chat.inline_permission_profile_selection_pending());
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Esc));
|
||||
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(chat.inline_permission_profile_selection_pending());
|
||||
assert!(chat.recover_inline_permission_profile_selection());
|
||||
assert!(chat.input_queue.recovered_queue);
|
||||
assert!(events.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn permissions_command_rejects_disabled_profile() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let mut discovery = Discovery::local(&chat.config);
|
||||
discovery.requirements = Some(
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"allowedPermissionProfiles": {BUILT_IN_PERMISSION_PROFILE_READ_ONLY: false}
|
||||
}))
|
||||
.unwrap(),
|
||||
);
|
||||
chat.permission_discovery = Some(discovery);
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
|
||||
chat.dispatch_command_with_args(
|
||||
SlashCommand::Permissions,
|
||||
BUILT_IN_PERMISSION_PROFILE_READ_ONLY.to_string(),
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
let cell = assert_matches!(events.try_recv(), Ok(AppEvent::InsertHistoryCell(cell)) => cell);
|
||||
insta::assert_snapshot!(
|
||||
"permissions_command_disabled_profile",
|
||||
lines_to_single_string(&cell.display_lines(/*width*/ 80))
|
||||
);
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(chat.input_queue.recovered_queue);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn permissions_command_rejects_unknown_profile() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.permission_discovery = Some(Discovery::local(&chat.config));
|
||||
|
||||
chat.dispatch_command_with_args(
|
||||
SlashCommand::Permissions,
|
||||
"unknown-profile".to_string(),
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
let cell = assert_matches!(events.try_recv(), Ok(AppEvent::InsertHistoryCell(cell)) => cell);
|
||||
insta::assert_snapshot!(
|
||||
"permissions_command_unknown_profile",
|
||||
lines_to_single_string(&cell.display_lines(/*width*/ 80))
|
||||
);
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalidating_inline_permission_discovery_recovers_queued_input() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
chat.select_permission_profile_by_id(BUILT_IN_PERMISSION_PROFILE_READ_ONLY);
|
||||
let request_id = assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::FetchPermissionProfiles { request_id, .. }) => request_id
|
||||
);
|
||||
|
||||
chat.invalidate_permission_discovery();
|
||||
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::SettingsSelectionClosed));
|
||||
assert!(chat.input_queue.recovered_queue);
|
||||
chat.on_permission_profiles_loaded(request_id, Ok(Discovery::local(&chat.config)));
|
||||
assert!(events.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inline_permission_discovery_retry_preserves_profile_id() {
|
||||
let (mut chat, mut events, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.select_permission_profile_by_id("server-only");
|
||||
let request_id = assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::FetchPermissionProfiles { request_id, .. }) => request_id
|
||||
);
|
||||
chat.on_permission_profiles_loaded(
|
||||
request_id,
|
||||
Err("Failed to load permissions: disconnected".to_string()),
|
||||
);
|
||||
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
|
||||
assert_matches!(
|
||||
events.try_recv(),
|
||||
Ok(AppEvent::ResolvePermissionProfile { profile_id }) if profile_id == "server-only"
|
||||
);
|
||||
assert_eq!(
|
||||
chat.bottom_pane.active_view_id(),
|
||||
Some("permission-profiles")
|
||||
);
|
||||
assert!(events.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn permission_discovery_discards_stale_results_and_preserves_covering_modal() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
@@ -331,15 +534,26 @@ async fn profile_permissions_selection_emits_named_profile_event_only() {
|
||||
|
||||
let events = std::iter::from_fn(|| rx.try_recv().ok()).collect::<Vec<_>>();
|
||||
assert_eq!(events.len(), 1);
|
||||
assert!(matches!(
|
||||
&events[0],
|
||||
AppEvent::SelectPermissionProfile(PermissionProfileSelection {
|
||||
profile_id,
|
||||
approval_policy: Some(AskForApproval::OnRequest),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
display_label,
|
||||
}) if profile_id == ":workspace" && display_label == "Ask for approval"
|
||||
));
|
||||
assert!(
|
||||
chat.try_select_permission_profile_by_id(
|
||||
&Discovery::local(&chat.config),
|
||||
":ask-for-approval",
|
||||
)
|
||||
);
|
||||
for event in events
|
||||
.into_iter()
|
||||
.chain(std::iter::from_fn(|| rx.try_recv().ok()))
|
||||
{
|
||||
assert!(matches!(
|
||||
event,
|
||||
AppEvent::SelectPermissionProfile(PermissionProfileSelection {
|
||||
profile_id,
|
||||
approval_policy: Some(AskForApproval::OnRequest),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
display_label,
|
||||
}) if profile_id == ":workspace" && display_label == "Ask for approval"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -397,15 +611,26 @@ async fn profile_permissions_selection_emits_auto_review_mode_event() {
|
||||
|
||||
let events = std::iter::from_fn(|| rx.try_recv().ok()).collect::<Vec<_>>();
|
||||
assert_eq!(events.len(), 1);
|
||||
assert!(matches!(
|
||||
&events[0],
|
||||
AppEvent::SelectPermissionProfile(PermissionProfileSelection {
|
||||
profile_id,
|
||||
approval_policy: Some(AskForApproval::OnRequest),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::AutoReview),
|
||||
display_label,
|
||||
}) if profile_id == ":workspace" && display_label == "Approve for me"
|
||||
));
|
||||
assert!(
|
||||
chat.try_select_permission_profile_by_id(
|
||||
&Discovery::local(&chat.config),
|
||||
":approve-for-me",
|
||||
)
|
||||
);
|
||||
for event in events
|
||||
.into_iter()
|
||||
.chain(std::iter::from_fn(|| rx.try_recv().ok()))
|
||||
{
|
||||
assert!(matches!(
|
||||
event,
|
||||
AppEvent::SelectPermissionProfile(PermissionProfileSelection {
|
||||
profile_id,
|
||||
approval_policy: Some(AskForApproval::OnRequest),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::AutoReview),
|
||||
display_label,
|
||||
}) if profile_id == ":workspace" && display_label == "Approve for me"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1199,7 +1424,7 @@ async fn permissions_selection_emits_history_cell_when_current_is_selected() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn permissions_selection_hides_auto_review_when_feature_disabled() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
chat.set_windows_sandbox_mode(Some(WindowsSandboxSetupMode::Unelevated));
|
||||
@@ -1212,6 +1437,14 @@ async fn permissions_selection_hides_auto_review_when_feature_disabled() {
|
||||
!popup.contains("Approve for me"),
|
||||
"expected Approve for me to stay hidden until the feature is enabled: {popup}"
|
||||
);
|
||||
assert!(
|
||||
!chat.try_select_permission_profile_by_id(
|
||||
&Discovery::local(&chat.config),
|
||||
":approve-for-me",
|
||||
)
|
||||
);
|
||||
let cell = assert_matches!(rx.try_recv(), Ok(AppEvent::InsertHistoryCell(cell)) => cell);
|
||||
insta::assert_snapshot!(lines_to_single_string(&cell.display_lines(/*width*/ 120)), @"■ Approve for me is unavailable. Run `/permissions` to see available profiles.");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -456,7 +456,7 @@ async fn queued_slash_menu_cancel_drains_next_input() {
|
||||
)
|
||||
.await;
|
||||
assert_cancelled_queued_menu_drains_next_input(
|
||||
"/permissions",
|
||||
"/permissions ",
|
||||
"Update Model Permissions",
|
||||
KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL),
|
||||
)
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/permissions.rs
|
||||
assertion_line: 168
|
||||
expression: lines_to_single_string(&cell.display_lines(80))
|
||||
---
|
||||
■ Permission profile `:read-only` is unavailable: Disabled by requirements.
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/permissions.rs
|
||||
expression: lines_to_single_string(&cell.display_lines(80))
|
||||
---
|
||||
■ Unknown permission profile `unknown-profile`. Run `/permissions` to see available profiles.
|
||||
Reference in New Issue
Block a user