Show file destinations in TUI change approvals (#39285)

## What changed

- Show a description and the destination paths affected by each file-change approval.
- Include both source and target paths for moves, format cross-platform paths for display, and show `unavailable` when change details are missing.
- Recover file changes from buffered events and thread snapshots so live and replayed approvals retain their destination details.

## Testing

- Add coverage for active and replayed approvals, moved and cross-platform paths, and the missing-destination fallback.

GitOrigin-RevId: 24f90b313fd8643f90cbead1504c788b140d7fed
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-18 21:43:22 +00:00
1 parent ba37d0c45b
commit e7f9fa9cd9
14 files changed
+411 -73

No files matched your search

+119
View File
@@ -3435,6 +3435,125 @@ async fn inactive_thread_file_change_approval_recovers_buffered_changes() {
assert!(rendered.contains("1 +hello"));
}
#[tokio::test]
async fn active_thread_file_change_approval_recovers_buffered_changes() {
let (mut app, _app_event_rx, _op_rx) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
app.active_thread_id = Some(thread_id);
app.startup_protected_input_boundary = true;
app.enqueue_thread_notification(
thread_id,
ServerNotification::ItemStarted(ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: "turn-active-approval".to_string(),
started_at_ms: 0,
item: ThreadItem::FileChange {
id: "patch-active-approval".to_string(),
changes: vec![FileUpdateChange {
path: "visible-target.md".to_string(),
kind: PatchChangeKind::Add,
diff: "hello\n".to_string(),
}],
status: codex_app_server_protocol::PatchApplyStatus::InProgress,
},
}),
)
.await
.expect("enqueue file change item");
let request = ServerRequest::FileChangeRequestApproval {
request_id: AppServerRequestId::Integer(10),
params: FileChangeRequestApprovalParams {
thread_id: thread_id.to_string(),
turn_id: "turn-active-approval".to_string(),
item_id: "patch-active-approval".to_string(),
started_at_ms: 0,
reason: None,
grant_root: None,
},
};
assert_eq!(
app.pending_app_server_requests
.note_server_request(&request),
None
);
app.chat_widget.handle_server_notification(
agent_message_delta_notification(thread_id, "turn-active-approval", "agent-1", "streaming"),
/*replay_kind*/ None,
);
let event = ThreadBufferedEvent::Request(Box::new(request));
app.handle_thread_event_now_recovering_file_changes(event)
.await;
assert!(!app.chat_widget.has_active_view());
assert!(app.startup_pending_protected_request);
app.chat_widget.handle_server_notification(
ServerNotification::ItemCompleted(codex_app_server_protocol::ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: "turn-active-approval".to_string(),
completed_at_ms: 0,
item: ThreadItem::AgentMessage {
id: "agent-1".to_string(),
text: "streaming".to_string(),
phase: None,
memory_citation: None,
},
}),
/*replay_kind*/ None,
);
let rendered = render_bottom_popup(&app.chat_widget, /*width*/ 100);
let destination = app.chat_widget.config_ref().cwd.join("visible-target.md");
assert!(rendered.contains("Description: Apply proposed file edits"));
assert!(rendered.contains(&format!("Destination: {}", destination.display())));
}
#[tokio::test]
async fn replayed_file_change_approval_recovers_snapshot_changes() {
let (mut app, _app_event_rx, _op_rx) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
let cwd = test_path_buf("/tmp/project").abs();
app.replay_thread_snapshot(
ThreadEventSnapshot {
session: Some(test_thread_session(thread_id, cwd.clone().into_path_buf())),
turns: vec![test_turn(
"turn-replayed-approval",
TurnStatus::InProgress,
vec![ThreadItem::FileChange {
id: "patch-replayed-approval".to_string(),
changes: vec![FileUpdateChange {
path: "visible-target.md".to_string(),
kind: PatchChangeKind::Add,
diff: "hello\n".to_string(),
}],
status: codex_app_server_protocol::PatchApplyStatus::InProgress,
}],
)],
events: vec![ThreadBufferedEvent::Request(Box::new(
ServerRequest::FileChangeRequestApproval {
request_id: AppServerRequestId::Integer(11),
params: FileChangeRequestApprovalParams {
thread_id: thread_id.to_string(),
turn_id: "turn-replayed-approval".to_string(),
item_id: "patch-replayed-approval".to_string(),
started_at_ms: 0,
reason: None,
grant_root: None,
},
},
))],
input_state: None,
},
/*resume_restored_queue*/ false,
);
let rendered = render_bottom_popup(&app.chat_widget, /*width*/ 100).replace(
&cwd.join("visible-target.md").display().to_string(),
"/tmp/project/visible-target.md",
);
assert_app_snapshot!("replayed_file_change_approval", rendered);
}
#[tokio::test]
async fn inactive_thread_permissions_approval_preserves_file_system_permissions() {
let app = make_test_app().await;