Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: nit tui on terminal interactions (#9602)

jif-oai13358fa13144
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index 0d0624cff9..110280612c 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -1528,6 +1528,7 @@ impl ChatWidget {
#[inline]
fn handle_streaming_delta(&mut self, delta: String) {
// Before streaming agent content, flush any active exec cell group.
+ self.flush_unified_exec_wait_streak();
self.flush_active_cell();
if self.stream_controller.is_none() {
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_after_final_agent_message.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_after_final_agent_message.snap
new file mode 100644
index 0000000000..5caf42e1bc
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_after_final_agent_message.snap
@@ -0,0 +1,8 @@
+---
+source: tui/src/chatwidget/tests.rs
+expression: combined
+---
+↳ Interacted with background terminal · cargo test -p codex-core
+ └ (waited)
+
+• Final response.
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_before_streamed_agent_message.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_before_streamed_agent_message.snap
new file mode 100644
index 0000000000..cfea4f8a66
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__unified_exec_wait_before_streamed_agent_message.snap
@@ -0,0 +1,8 @@
+---
+source: tui/src/chatwidget/tests.rs
+expression: combined
+---
+↳ Interacted with background terminal · cargo test -p codex-core
+ └ (waited)
+
+• Streaming response.
diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs
index 0610a640c7..35ab9579e4 100644
--- a/codex-rs/tui/src/chatwidget/tests.rs
+++ b/codex-rs/tui/src/chatwidget/tests.rs
@@ -1754,6 +1754,79 @@ async fn unified_exec_interaction_after_task_complete_is_suppressed() {
);
}
+#[tokio::test]
+async fn unified_exec_wait_after_final_agent_message_snapshot() {
+ let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(None).await;
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::TurnStarted(TurnStartedEvent {
+ model_context_window: None,
+ }),
+ });
+
+ begin_unified_exec_startup(&mut chat, "call-wait", "proc-1", "cargo test -p codex-core");
+ terminal_interaction(&mut chat, "call-wait-stdin", "proc-1", "");
+
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::AgentMessage(AgentMessageEvent {
+ message: "Final response.".into(),
+ }),
+ });
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::TurnComplete(TurnCompleteEvent {
+ last_agent_message: Some("Final response.".into()),
+ }),
+ });
+
+ let cells = drain_insert_history(&mut rx);
+ let combined = cells
+ .iter()
+ .map(|lines| lines_to_single_string(lines))
+ .collect::<String>();
+ assert_snapshot!("unified_exec_wait_after_final_agent_message", combined);
+}
+
+#[tokio::test]
+async fn unified_exec_wait_before_streamed_agent_message_snapshot() {
+ let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(None).await;
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::TurnStarted(TurnStartedEvent {
+ model_context_window: None,
+ }),
+ });
+
+ begin_unified_exec_startup(
+ &mut chat,
+ "call-wait-stream",
+ "proc-1",
+ "cargo test -p codex-core",
+ );
+ terminal_interaction(&mut chat, "call-wait-stream-stdin", "proc-1", "");
+
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::AgentMessageDelta(AgentMessageDeltaEvent {
+ delta: "Streaming response.".into(),
+ }),
+ });
+ chat.handle_codex_event(Event {
+ id: "turn-1".into(),
+ msg: EventMsg::TurnComplete(TurnCompleteEvent {
+ last_agent_message: None,
+ }),
+ });
+
+ let cells = drain_insert_history(&mut rx);
+ let combined = cells
+ .iter()
+ .map(|lines| lines_to_single_string(lines))
+ .collect::<String>();
+ assert_snapshot!("unified_exec_wait_before_streamed_agent_message", combined);
+}
+
#[tokio::test]
async fn unified_exec_wait_status_header_updates_on_late_command_display() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(None).await;