mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Propagate permission approval environment id (#25862)
## Stack 1. #25850 - Key request-permission grants by environment: stores and applies sticky permission grants per environment id. 2. #25858 - Add `environmentId` to `request_permissions`: lets the model target a selected environment and resolves relative permission paths against it. 3. This PR (#25862) - Propagate permission approval environment id: carries the selected environment id through approval events, app-server requests, TUI prompts, and delegate forwarding. 4. #25867 - Add remote request permissions integration coverage: verifies the selected remote environment across request, approval, grant reuse, and exec. This PR is stacked on #25858, and #25867 is stacked on this PR. ## Why PR2 lets the model bind a `request_permissions` call to a selected environment, but the approval event and client-facing request still needed to carry that binding. For CCA, the user-facing prompt and delegated approval path should know which environment the grant applies to instead of relying on cwd alone. ## What Changed - Added optional `environmentId` to `RequestPermissionsEvent`. - Emit the selected environment id from core permission approval events. - Preserve the environment id through delegate forwarding, including cwd-based delegated requests. - Added `environmentId` to app-server permission approval params, generated schema/TypeScript artifacts, and README examples. - Preserve and display the environment id in TUI permission approval prompts. - Updated focused core, app-server protocol, and TUI conversion coverage. ## Testing Not run locally per instruction. Performed read-only `git diff --check`.
This commit is contained in:
@@ -489,6 +489,7 @@ mod tests {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "perm-1".to_string(),
|
||||
environment_id: None,
|
||||
started_at_ms: 0,
|
||||
cwd: absolute_path(if cfg!(windows) { r"C:\tmp" } else { "/tmp" }),
|
||||
reason: None,
|
||||
|
||||
@@ -1856,12 +1856,20 @@ impl App {
|
||||
));
|
||||
}
|
||||
ApprovalRequest::Permissions {
|
||||
environment_id,
|
||||
permissions,
|
||||
reason,
|
||||
..
|
||||
} => {
|
||||
let _ = tui.enter_alt_screen();
|
||||
let mut lines = Vec::new();
|
||||
if let Some(environment_id) = environment_id {
|
||||
lines.push(Line::from(vec![
|
||||
"Environment: ".into(),
|
||||
environment_id.bold(),
|
||||
]));
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
if let Some(reason) = reason {
|
||||
lines.push(Line::from(vec!["Reason: ".into(), reason.italic()]));
|
||||
lines.push(Line::from(""));
|
||||
|
||||
@@ -2539,6 +2539,7 @@ async fn inactive_thread_permissions_approval_preserves_file_system_permissions(
|
||||
thread_id: thread_id.to_string(),
|
||||
turn_id: "turn-approval".to_string(),
|
||||
item_id: "call-approval".to_string(),
|
||||
environment_id: Some("remote".to_string()),
|
||||
started_at_ms: 0,
|
||||
cwd: test_absolute_path("/tmp"),
|
||||
reason: Some("Need access to .git".to_string()),
|
||||
@@ -2557,7 +2558,9 @@ async fn inactive_thread_permissions_approval_preserves_file_system_permissions(
|
||||
};
|
||||
|
||||
let Some(ThreadInteractiveRequest::Approval(ApprovalRequest::Permissions {
|
||||
permissions, ..
|
||||
environment_id,
|
||||
permissions,
|
||||
..
|
||||
})) = app
|
||||
.interactive_request_for_thread_request(thread_id, &request)
|
||||
.await
|
||||
@@ -2565,6 +2568,7 @@ async fn inactive_thread_permissions_approval_preserves_file_system_permissions(
|
||||
panic!("expected permissions approval request");
|
||||
};
|
||||
|
||||
assert_eq!(environment_id.as_deref(), Some("remote"));
|
||||
assert_eq!(
|
||||
permissions,
|
||||
RequestPermissionProfile {
|
||||
|
||||
@@ -310,6 +310,7 @@ impl App {
|
||||
thread_id,
|
||||
thread_label,
|
||||
call_id: params.item_id.clone(),
|
||||
environment_id: params.environment_id.clone(),
|
||||
reason: params.reason.clone(),
|
||||
permissions: params.permissions.clone().into(),
|
||||
}),
|
||||
|
||||
@@ -84,6 +84,7 @@ pub(crate) enum ApprovalRequest {
|
||||
thread_id: ThreadId,
|
||||
thread_label: Option<String>,
|
||||
call_id: String,
|
||||
environment_id: Option<String>,
|
||||
reason: Option<String>,
|
||||
permissions: RequestPermissionProfile,
|
||||
},
|
||||
@@ -713,6 +714,7 @@ fn build_header(request: &ApprovalRequest) -> Box<dyn Renderable> {
|
||||
}
|
||||
ApprovalRequest::Permissions {
|
||||
thread_label,
|
||||
environment_id,
|
||||
reason,
|
||||
permissions,
|
||||
..
|
||||
@@ -725,6 +727,13 @@ fn build_header(request: &ApprovalRequest) -> Box<dyn Renderable> {
|
||||
]));
|
||||
header.push(Line::from(""));
|
||||
}
|
||||
if let Some(environment_id) = environment_id {
|
||||
header.push(Line::from(vec![
|
||||
"Environment: ".into(),
|
||||
environment_id.clone().bold(),
|
||||
]));
|
||||
header.push(Line::from(""));
|
||||
}
|
||||
if let Some(reason) = reason {
|
||||
header.push(Line::from(vec!["Reason: ".into(), reason.clone().italic()]));
|
||||
header.push(Line::from(""));
|
||||
@@ -1227,6 +1236,7 @@ mod tests {
|
||||
thread_id: ThreadId::new(),
|
||||
thread_label: None,
|
||||
call_id: "test".to_string(),
|
||||
environment_id: None,
|
||||
reason: Some("need workspace access".to_string()),
|
||||
permissions: RequestPermissionProfile {
|
||||
network: Some(NetworkPermissions {
|
||||
|
||||
@@ -864,6 +864,7 @@ fn request_permissions_from_params(
|
||||
RequestPermissionsEvent {
|
||||
turn_id: params.turn_id,
|
||||
call_id: params.item_id,
|
||||
environment_id: params.environment_id,
|
||||
started_at_ms: params.started_at_ms,
|
||||
reason: params.reason,
|
||||
permissions: params.permissions.into(),
|
||||
|
||||
@@ -281,6 +281,7 @@ fn app_server_request_permissions_preserves_file_system_permissions() {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
environment_id: Some("remote".to_string()),
|
||||
started_at_ms: 0,
|
||||
cwd: cwd.clone(),
|
||||
reason: Some("Select a workspace root".to_string()),
|
||||
@@ -310,6 +311,7 @@ fn app_server_request_permissions_preserves_file_system_permissions() {
|
||||
}
|
||||
);
|
||||
assert_eq!(request.cwd, Some(cwd));
|
||||
assert_eq!(request.environment_id.as_deref(), Some("remote"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -441,6 +441,7 @@ impl ChatWidget {
|
||||
thread_id: self.thread_id.unwrap_or_default(),
|
||||
thread_label: None,
|
||||
call_id: ev.call_id,
|
||||
environment_id: ev.environment_id,
|
||||
reason: ev.reason,
|
||||
permissions: ev.permissions,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user