mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Represent terminal input in approval reviews (#40528)
## What changed - Add a `writeStdin` Guardian action carrying the approval, process, input, and working-directory details. - Distinguish `command` and `writeStdin` execution approval requests while defaulting missing kinds to `command` for compatibility with older events. - Render terminal-input review progress, denials, timeouts, and retry actions in the TUI, and record the action separately in analytics. - Keep terminal-input reviews as child approvals so they do not change the parent command item's lifecycle or reconstructed history. ## Testing - Cover Guardian serialization, app-server protocol conversion, command history reconstruction, analytics classification, and TUI review flows for terminal input. GitOrigin-RevId: b083d5e2963bdd23b928644ec03c7eb68ebf2950
This commit is contained in:
1 parent
a7b86b6201
commit
9c9675d3d0
51 files changed
+833
-26
No files matched your search
@@ -53,6 +53,7 @@ fn app_server_exec_approval_request_splits_shell_wrapped_command() {
|
||||
let script = r#"python3 -c 'print("Hello, world!")'"#;
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
@@ -95,6 +96,7 @@ fn app_server_exec_approval_request_preserves_permissions_context() {
|
||||
let write_api_path = LegacyAppPathString::from_abs_path(&write_path);
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
@@ -155,6 +157,7 @@ async fn network_exec_approval_history_describes_session_host_allowance() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
@@ -197,6 +200,7 @@ async fn network_exec_approval_history_describes_one_time_host_allowance() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
@@ -239,6 +243,7 @@ async fn network_exec_approval_history_describes_canceled_host_request() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
|
||||
@@ -481,6 +481,7 @@ fn app_server_exec_approval_request_splits_shell_wrapped_command() {
|
||||
let script = r#"python3 -c 'print("Hello, world!")'"#;
|
||||
let request = exec_approval_request_from_params(
|
||||
AppServerCommandExecutionRequestApprovalParams {
|
||||
kind: Default::default(),
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
item_id: "item-1".to_string(),
|
||||
|
||||
@@ -51,6 +51,148 @@ fn guardian_command_event(
|
||||
}
|
||||
}
|
||||
|
||||
fn guardian_write_stdin_notification(status: GuardianApprovalReviewStatus) -> ServerNotification {
|
||||
let action = AppServerGuardianApprovalReviewAction::WriteStdin {
|
||||
approval_id: "stdin-approval".to_string(),
|
||||
process_id: "42".to_string(),
|
||||
stdin: "confirm\n".to_string(),
|
||||
cwd: test_path_buf("/tmp/project").abs().into(),
|
||||
};
|
||||
let review = GuardianApprovalReview {
|
||||
status,
|
||||
risk_level: None,
|
||||
user_authorization: None,
|
||||
rationale: (status == GuardianApprovalReviewStatus::Denied)
|
||||
.then(|| "Would confirm a destructive operation.".to_string()),
|
||||
};
|
||||
if status == GuardianApprovalReviewStatus::InProgress {
|
||||
ServerNotification::ItemGuardianApprovalReviewStarted(
|
||||
ItemGuardianApprovalReviewStartedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-2".to_string(),
|
||||
started_at_ms: 0,
|
||||
review_id: "guardian-write-stdin".to_string(),
|
||||
target_item_id: Some("parent-terminal".to_string()),
|
||||
review,
|
||||
action,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
ServerNotification::ItemGuardianApprovalReviewCompleted(
|
||||
ItemGuardianApprovalReviewCompletedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-2".to_string(),
|
||||
started_at_ms: 0,
|
||||
completed_at_ms: 1,
|
||||
review_id: "guardian-write-stdin".to_string(),
|
||||
target_item_id: Some("parent-terminal".to_string()),
|
||||
decision_source: AppServerGuardianApprovalReviewDecisionSource::Agent,
|
||||
review,
|
||||
action,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn app_server_guardian_write_stdin_denial_preserves_child_action() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id = ThreadId::new();
|
||||
chat.thread_id = Some(thread_id);
|
||||
chat.on_task_started();
|
||||
|
||||
chat.handle_server_notification(
|
||||
guardian_write_stdin_notification(GuardianApprovalReviewStatus::InProgress),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
assert_chatwidget_snapshot!(
|
||||
"guardian_write_stdin_review_status",
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
);
|
||||
|
||||
chat.handle_server_notification(
|
||||
guardian_write_stdin_notification(GuardianApprovalReviewStatus::Denied),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
assert!(chat.status_state.pending_guardian_review_status.is_empty());
|
||||
assert_eq!(chat.status_state.current_status.header, "Working");
|
||||
let history = drain_insert_history(&mut rx);
|
||||
let [denial] = history.as_slice() else {
|
||||
panic!("expected only the stdin denial in history");
|
||||
};
|
||||
assert_chatwidget_snapshot!(
|
||||
"guardian_write_stdin_denied_history",
|
||||
lines_to_single_string(denial)
|
||||
);
|
||||
|
||||
chat.open_auto_review_denials_popup();
|
||||
assert_chatwidget_snapshot!(
|
||||
"guardian_write_stdin_denials_popup",
|
||||
render_bottom_popup(&chat, /*width*/ 110)
|
||||
);
|
||||
|
||||
chat.approve_recent_auto_review_denial(thread_id, "guardian-write-stdin".to_string());
|
||||
let Ok(AppEvent::SubmitThreadOp {
|
||||
thread_id: submitted_thread_id,
|
||||
op: Op::ApproveGuardianDeniedAction { event },
|
||||
}) = rx.try_recv()
|
||||
else {
|
||||
panic!("expected a structured approval for the stdin denial");
|
||||
};
|
||||
assert_eq!(
|
||||
(submitted_thread_id, event.action),
|
||||
(
|
||||
thread_id,
|
||||
GuardianAssessmentAction::WriteStdin {
|
||||
approval_id: "stdin-approval".to_string(),
|
||||
process_id: "42".to_string(),
|
||||
stdin: "confirm\n".to_string(),
|
||||
cwd: test_path_buf("/tmp/project").abs().into(),
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn app_server_guardian_write_stdin_approval_and_timeout_clear_review_status() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_task_started();
|
||||
|
||||
for status in [
|
||||
GuardianApprovalReviewStatus::InProgress,
|
||||
GuardianApprovalReviewStatus::Approved,
|
||||
] {
|
||||
chat.handle_server_notification(
|
||||
guardian_write_stdin_notification(status),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
}
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
assert!(chat.status_state.pending_guardian_review_status.is_empty());
|
||||
assert_eq!(chat.status_state.current_status.header, "Working");
|
||||
|
||||
for status in [
|
||||
GuardianApprovalReviewStatus::InProgress,
|
||||
GuardianApprovalReviewStatus::TimedOut,
|
||||
] {
|
||||
chat.handle_server_notification(
|
||||
guardian_write_stdin_notification(status),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
}
|
||||
assert!(chat.status_state.pending_guardian_review_status.is_empty());
|
||||
assert!(chat.review.recent_auto_review_denials.is_empty());
|
||||
assert_eq!(chat.status_state.current_status.header, "Working");
|
||||
let history = drain_insert_history(&mut rx);
|
||||
let [timeout] = history.as_slice() else {
|
||||
panic!("expected only the stdin timeout in history");
|
||||
};
|
||||
assert_chatwidget_snapshot!(
|
||||
"guardian_write_stdin_timed_out_history",
|
||||
lines_to_single_string(timeout)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn auto_review_denials_popup_lists_stored_auto_review_denials() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in new issue
Block a user