mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Enable remote named permission profile selection in the TUI (#43340)
## Why The permissions picker displayed profiles from the connected app server but disabled selection of remote custom profiles. ## What changed - Enable named profile selection through `thread/settings/update` and track pending selections until server confirmation. - Use pending or confirmed server permissions for subsequent turns, preserve profiles across forks and prompt edits, and reconcile pending selections on reconnect. - Block conflicting permission changes and forks while selection is pending. Preserve input when selection fails and report unsupported app servers. - Reject working directory changes while a remote named profile is active. ## Testing Add regression coverage for profile selection, turn permissions, pending-selection guards, prompt-edit profile preservation, reconnect reconciliation, and profile inheritance in forks and side conversations. GitOrigin-RevId: 76e9bb7b4d631b1066974da013d9915a89dc54a7
This commit is contained in:
1 parent
1fb5158b34
commit
121f91fd5d
24 files changed
+914
-50
No files matched your search
@@ -19,6 +19,7 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
(false, false, -32600),
|
||||
(true, true, -32600),
|
||||
] {
|
||||
let pending_profile = !recovered_queue && resume_error_code == -32600;
|
||||
let (mut app, mut events, mut ops) = make_test_app_with_channels().await;
|
||||
let id = ThreadId::new();
|
||||
let cwd = app.config.cwd.clone();
|
||||
@@ -108,8 +109,8 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
assert!(!recovered_queue);
|
||||
let params = request.params.as_ref().unwrap();
|
||||
assert_eq!(params["input"][0]["text"], "fresh follow-up");
|
||||
assert_eq!(params["approvalPolicy"], "on-request");
|
||||
assert_eq!(params["sandboxPolicy"]["type"], "readOnly");
|
||||
assert_eq!(params["approvalPolicy"], if pending_profile { "never" } else { "on-request" });
|
||||
assert_eq!(params["sandboxPolicy"]["type"], if pending_profile { json!(null) } else { json!("readOnly") });
|
||||
assert_eq!(params["collaborationMode"], json!(expected_submitted_mode));
|
||||
Some(json!({"result": {"turn": {"id": "fresh", "items": [], "status": "inProgress"}}}))
|
||||
}
|
||||
@@ -166,6 +167,17 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
Some("1.0.0"),
|
||||
);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
if pending_profile {
|
||||
app.pending_server_profiles.insert(
|
||||
id,
|
||||
PermissionProfileSelection {
|
||||
profile_id: "server-only".into(),
|
||||
approval_policy: None,
|
||||
approvals_reviewer: None,
|
||||
display_label: "server-only".into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
app.begin_reconnect();
|
||||
if edit_offline {
|
||||
app.handle_tui_event(
|
||||
@@ -215,6 +227,7 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
);
|
||||
app.finish_reconnect(&mut tui, &mut session, &mut events, connected)
|
||||
.await?;
|
||||
assert!(app.pending_server_profiles.is_empty());
|
||||
assert!(!app.reconnect.offline);
|
||||
assert!(!app.thread_unavailable(id));
|
||||
assert_eq!(app.last_subagent_backfill_attempt, None);
|
||||
@@ -330,6 +343,147 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconnect_reconciles_offscreen_pending_profile_before_restoring_permissions() -> Result<()>
|
||||
{
|
||||
let (mut app, mut events, _) = make_test_app_with_channels().await;
|
||||
let primary = ThreadId::new();
|
||||
let displayed = ThreadId::new();
|
||||
let cwd = app.config.cwd.to_path_buf();
|
||||
app.config
|
||||
.permissions
|
||||
.set_permission_profile(PermissionProfile::Disabled)?;
|
||||
app.runtime_permission_profile_override =
|
||||
Some(RuntimePermissionProfileOverride::from_config(&app.config));
|
||||
app.primary_thread_id = Some(primary);
|
||||
app.active_thread_id = Some(displayed);
|
||||
for id in [primary, displayed] {
|
||||
let mut session = test_thread_session(id, cwd.clone());
|
||||
session.permission_profile = PermissionProfile::Disabled;
|
||||
app.ensure_thread_channel(id)
|
||||
.store
|
||||
.lock()
|
||||
.await
|
||||
.set_session(session.clone(), Vec::new());
|
||||
if id == primary {
|
||||
app.primary_session_configured = Some(session);
|
||||
app.upsert_agent_picker_thread(
|
||||
id, /*agent_nickname*/ None, /*agent_role*/ None,
|
||||
/*is_closed*/ false,
|
||||
);
|
||||
} else {
|
||||
app.chat_widget.handle_thread_session(session);
|
||||
}
|
||||
}
|
||||
app.pending_server_profiles.insert(
|
||||
primary,
|
||||
PermissionProfileSelection {
|
||||
profile_id: "server-only".into(),
|
||||
approval_policy: None,
|
||||
approvals_reviewer: None,
|
||||
display_label: "server-only".into(),
|
||||
},
|
||||
);
|
||||
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
app.app_server_target = AppServerTarget::Remote {
|
||||
endpoint: crate::resolve_remote_addr(&format!("ws://{}", listener.local_addr()?))?,
|
||||
};
|
||||
let server = tokio::spawn(async move {
|
||||
let (stream, _) = listener.accept().await?;
|
||||
serve_reconnect_requests(tokio_tungstenite::accept_async(stream).await?, |request| {
|
||||
let id = request.params.as_ref().and_then(|params| params["threadId"].as_str());
|
||||
let thread = |id: ThreadId| json!({
|
||||
"id": id, "sessionId": id, "preview": "task", "ephemeral": false,
|
||||
"modelProvider": "test-provider", "createdAt": 1, "updatedAt": 2,
|
||||
"status": {"type": "idle"}, "cwd": cwd, "cliVersion": "0.0.0",
|
||||
"source": "cli", "turns": []
|
||||
});
|
||||
std::future::ready(Some(match request.method.as_str() {
|
||||
"thread/resume" => {
|
||||
let pending = id == Some(primary.to_string().as_str());
|
||||
json!({"result": {"thread": thread(if pending { primary } else { displayed }),
|
||||
"model": "gpt-test", "modelProvider": "test-provider", "cwd": cwd,
|
||||
"approvalPolicy": if pending { "on-request" } else { "never" },
|
||||
"approvalsReviewer": "user",
|
||||
"sandbox": {"type": if pending { "readOnly" } else { "dangerFullAccess" }},
|
||||
"activePermissionProfile": if pending { Some(json!({"id": "server-only"})) } else { None },
|
||||
"reasoningEffort": null}})
|
||||
}
|
||||
"thread/read" => json!({"result": {"thread": thread(primary)}}),
|
||||
"turn/start" => {
|
||||
let params = request.params.as_ref().unwrap();
|
||||
assert_eq!(params["permissions"], "server-only");
|
||||
assert_eq!(params["approvalPolicy"], "on-request");
|
||||
assert_eq!(params["sandboxPolicy"], json!(null));
|
||||
json!({"result": {"turn": {"id": "fresh", "items": [], "status": "inProgress"}}})
|
||||
}
|
||||
"thread/list" | "thread/loaded/list" =>
|
||||
json!({"result": {"data": [], "nextCursor": null}}),
|
||||
"thread/goal/get" => json!({"result": {"goal": null}}),
|
||||
method => panic!("unexpected reconnect request: {method}"),
|
||||
}))
|
||||
})
|
||||
.await
|
||||
});
|
||||
let mut session = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.begin_reconnect();
|
||||
let connected = reconnect(
|
||||
app.app_server_target.clone(),
|
||||
app.config.clone(),
|
||||
app.local_settings.clone(),
|
||||
Some(displayed),
|
||||
/*remote_cwd*/ None,
|
||||
session.thread_tool_transport(),
|
||||
ReconnectPresentation::Conversation,
|
||||
)
|
||||
.await?;
|
||||
app.finish_reconnect(&mut tui, &mut session, &mut events, connected)
|
||||
.await?;
|
||||
assert!(app.pending_server_profiles.contains_key(&primary));
|
||||
|
||||
app.select_agent_thread(&mut tui, &mut session, primary)
|
||||
.await?;
|
||||
assert!(!app.thread_unavailable(primary));
|
||||
assert!(!app.pending_server_profiles.contains_key(&primary));
|
||||
assert_eq!(
|
||||
app.chat_widget
|
||||
.config_ref()
|
||||
.permissions
|
||||
.permission_profile(),
|
||||
&PermissionProfile::read_only()
|
||||
);
|
||||
assert_eq!(
|
||||
app.chat_widget
|
||||
.config_ref()
|
||||
.permissions
|
||||
.active_permission_profile()
|
||||
.as_ref()
|
||||
.map(|profile| profile.id.as_str()),
|
||||
Some("server-only")
|
||||
);
|
||||
app.chat_widget
|
||||
.restore_user_message_to_composer("safe follow-up".into());
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
while let Ok(event) = events.try_recv() {
|
||||
if matches!(event, AppEvent::CodexOp(AppCommand::UserTurn { .. })) {
|
||||
app.handle_event(&mut tui, &mut session, event).await?;
|
||||
}
|
||||
}
|
||||
session.shutdown().await?;
|
||||
let methods = server.await??;
|
||||
assert_eq!(
|
||||
methods
|
||||
.iter()
|
||||
.filter(|method| *method == "turn/start")
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconnect_exhaustion_and_unknown_initial_thread_stay_offline() -> Result<()> {
|
||||
let (mut app, _, _) = make_test_app_with_channels().await;
|
||||
|
||||
@@ -75,6 +75,22 @@ async fn permission_shortcut_rejections_leave_state_unchanged() -> Result<()> {
|
||||
.replace(&thread_id.to_string(), "<THREAD_ID>")
|
||||
);
|
||||
assert!(events.try_recv().is_err());
|
||||
if !experimental_api {
|
||||
app.select_permission_profile(
|
||||
&mut app_server,
|
||||
PermissionProfileSelection {
|
||||
profile_id: "server-only".into(),
|
||||
approval_policy: None,
|
||||
approvals_reviewer: None,
|
||||
display_label: "server-only".into(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
insta::assert_snapshot!(
|
||||
next_history_message(&mut events),
|
||||
@"■ Named profiles require a newer app server."
|
||||
);
|
||||
}
|
||||
app_server.shutdown().await?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user