Expand TUI regression coverage for realtime voice conversations (#43645)

## What changed

- Add app-to-RPC tests for voice startup, shutdown, thread switching, speech delivery, and rejected or stale speech, using a recording app server without audio hardware.
- Cover session retries, typed and voice handoffs, reasoning visibility, and recovery of undelivered answers in focused chat widget test modules.
- Add transcript and buffered replay tests for caption reconciliation, partial transcript preservation, and voice output ownership across thread changes, with rendering snapshots.

GitOrigin-RevId: 8a76523907289f94f257fe97386db7d2e7f33ca5
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-08 02:09:29 +00:00
1 parent e7637306bc
commit 6fee98cc85
32 files changed
+5396 -88

No files matched your search

@@ -71,6 +71,360 @@ fn buffered_replay_keeps_unfinished_and_unrelated_deltas_in_order() {
assert_eq!(store.snapshot().events.len(), 6);
}
#[test]
fn evicted_voice_delegation_marker_still_suppresses_private_replay() {
let mut store = ThreadEventStore::new(/*capacity*/ 2);
let voice_request = ThreadItem::UserMessage {
id: "user".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "<realtime_delegation><input>question</input></realtime_delegation>".into(),
text_elements: Vec::new(),
}],
};
store.push_notification(ServerNotification::ItemStarted(
codex_app_server_protocol::ItemStartedNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
started_at_ms: 0,
item: voice_request.clone(),
},
));
store.push_notification(delta("thread", "voice-turn", "reasoning"));
let private = ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
completed_at_ms: 0,
item: ThreadItem::AgentMessage {
id: "reasoning".into(),
text: "[ANALYSIS] private".into(),
phase: None,
memory_citation: None,
delivery: None,
questions: None,
},
});
store.push_notification(private.clone());
assert!(store.snapshot().events.is_empty());
store.push_notification(delta("thread", "voice-turn", "unfinished"));
assert!(store.snapshot().events.is_empty());
assert_eq!(store.snapshot().delegated_turns, vec!["voice-turn"]);
for notification in [
ServerNotification::ReasoningSummaryPartAdded(
codex_app_server_protocol::ReasoningSummaryPartAddedNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
item_id: "reasoning".into(),
summary_index: 0,
},
),
ServerNotification::ReasoningSummaryTextDelta(
codex_app_server_protocol::ReasoningSummaryTextDeltaNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
item_id: "reasoning".into(),
delta: "private summary".into(),
summary_index: 0,
},
),
ServerNotification::ReasoningTextDelta(
codex_app_server_protocol::ReasoningTextDeltaNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
item_id: "reasoning".into(),
delta: "private raw reasoning".into(),
content_index: 0,
},
),
ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: "thread".into(),
turn_id: "voice-turn".into(),
completed_at_ms: 0,
item: ThreadItem::Reasoning {
id: "reasoning".into(),
summary: vec!["private summary".into()],
content: vec!["private raw reasoning".into()],
},
}),
] {
store.push_notification(notification);
assert!(store.snapshot().events.is_empty());
}
let mut resumed = ThreadEventStore::new(/*capacity*/ 1);
resumed.set_turns(vec![Turn {
id: "voice-turn".into(),
items: vec![voice_request],
items_view: codex_app_server_protocol::TurnItemsView::Summary,
status: TurnStatus::InProgress,
error: None,
started_at: None,
completed_at: None,
duration_ms: None,
}]);
resumed.push_notification(delta("thread", "voice-turn", "unfinished"));
let mut newer = resumed.turns[0].clone();
newer.id = "newer-turn".into();
resumed.set_turns(vec![resumed.turns[0].clone(), newer]);
assert!(resumed.snapshot().events.is_empty());
resumed.push_notification(delta("thread", "newer-turn", "unfinished"));
assert!(resumed.snapshot().events.is_empty());
let mut ordinary = ThreadEventStore::new(/*capacity*/ 2);
let ServerNotification::ItemCompleted(mut normal) = private else {
unreachable!()
};
normal.turn_id = "normal-turn".into();
ordinary.push_notification(ServerNotification::ItemCompleted(normal));
assert_eq!(ordinary.snapshot().events.len(), 1);
}
#[test]
fn saved_voice_turn_suppresses_reasoning_without_hiding_typed_reasoning() {
let reasoning = ThreadItem::Reasoning {
id: "reasoning".into(),
summary: vec!["private summary".into()],
content: vec!["private raw reasoning".into()],
};
let voice_request = ThreadItem::UserMessage {
id: "voice-request".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "<realtime_delegation><input>question</input></realtime_delegation>".into(),
text_elements: Vec::new(),
}],
};
let turn = |id: &str, items| Turn {
id: id.into(),
items,
items_view: codex_app_server_protocol::TurnItemsView::Full,
status: TurnStatus::Completed,
error: None,
started_at: None,
completed_at: None,
duration_ms: None,
};
let mut store = ThreadEventStore::new(/*capacity*/ 4);
store.set_turns(vec![
turn("voice", vec![voice_request.clone(), reasoning.clone()]),
turn("typed", vec![reasoning.clone()]),
]);
assert_eq!(
store.snapshot().turns,
vec![
turn("voice", vec![voice_request]),
turn("typed", vec![reasoning])
]
);
}
#[test]
fn snapshot_keeps_typed_output_before_voice_handoff_in_the_same_turn() {
let commentary = |id: &str, text: &str| ThreadItem::AgentMessage {
id: id.into(),
text: text.into(),
phase: Some(codex_protocol::models::MessagePhase::Commentary),
questions: None,
memory_citation: None,
delivery: None,
};
let marker = ThreadItem::UserMessage {
id: "voice".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "<realtime_delegation><input>question</input></realtime_delegation>".into(),
text_elements: Vec::new(),
}],
};
let typed = commentary("typed", "Earlier typed commentary");
let private = commentary("private", "Later voice-private commentary");
let mut store = ThreadEventStore::new(/*capacity*/ 8);
store.set_turns(vec![Turn {
id: "shared".into(),
items: vec![typed.clone(), marker.clone(), private.clone()],
items_view: codex_app_server_protocol::TurnItemsView::Full,
status: TurnStatus::InProgress,
error: None,
started_at: None,
completed_at: None,
duration_ms: None,
}]);
for item in [typed.clone(), marker.clone(), private] {
store.push_notification(ServerNotification::ItemCompleted(
ItemCompletedNotification {
thread_id: "thread".into(),
turn_id: "shared".into(),
completed_at_ms: 0,
item,
},
));
}
let snapshot = store.snapshot();
assert_eq!(snapshot.turns[0].items, vec![typed.clone(), marker]);
let completed = snapshot
.events
.into_iter()
.filter_map(|event| match event {
ThreadBufferedEvent::Notification(notification) => match *notification {
ServerNotification::ItemCompleted(item) => Some(item.item),
_ => None,
},
_ => None,
})
.collect::<Vec<_>>();
assert_eq!(completed, vec![typed, snapshot.turns[0].items[1].clone()]);
}
#[test]
fn snapshot_keeps_typed_item_completed_after_voice_handoff() {
let typed = ThreadItem::AgentMessage {
id: "typed".into(),
text: "Typed commentary completed late".into(),
phase: Some(codex_protocol::models::MessagePhase::Commentary),
questions: None,
memory_citation: None,
delivery: None,
};
let private = ThreadItem::AgentMessage {
id: "private".into(),
text: "Voice-private commentary".into(),
phase: Some(codex_protocol::models::MessagePhase::Commentary),
questions: None,
memory_citation: None,
delivery: None,
};
let marker = ThreadItem::UserMessage {
id: "voice".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "<realtime_delegation><input>question</input></realtime_delegation>".into(),
text_elements: Vec::new(),
}],
};
let mut store = ThreadEventStore::new(/*capacity*/ 8);
for item in [typed.clone(), marker, private.clone()] {
store.push_notification(ServerNotification::ItemStarted(
codex_app_server_protocol::ItemStartedNotification {
thread_id: "thread".into(),
turn_id: "shared".into(),
started_at_ms: 0,
item,
},
));
}
for item in [typed.clone(), private] {
store.push_notification(ServerNotification::ItemCompleted(
ItemCompletedNotification {
thread_id: "thread".into(),
turn_id: "shared".into(),
completed_at_ms: 0,
item,
},
));
}
let completed = store
.snapshot()
.events
.into_iter()
.filter_map(|event| match event {
ThreadBufferedEvent::Notification(notification) => match *notification {
ServerNotification::ItemCompleted(n) => Some(n.item),
_ => None,
},
_ => None,
})
.collect::<Vec<_>>();
assert_eq!(completed, vec![typed]);
}
#[tokio::test]
async fn evicted_voice_marker_survives_widget_snapshot_for_late_reasoning() {
let thread_id = ThreadId::new();
let mut store = ThreadEventStore::new(/*capacity*/ 1);
store.push_notification(ServerNotification::ItemStarted(
codex_app_server_protocol::ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: "voice-turn".into(),
started_at_ms: 0,
item: ThreadItem::UserMessage {
id: "user".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "<realtime_delegation><input>question</input></realtime_delegation>"
.into(),
text_elements: Vec::new(),
}],
},
},
));
store.push_notification(delta(&thread_id.to_string(), "voice-turn", "private"));
let snapshot = store.snapshot();
assert!(snapshot.events.is_empty());
assert!(snapshot.turns.is_empty());
assert_eq!(snapshot.delegated_turns, vec!["voice-turn"]);
let mut app = make_test_app().await;
let (widget, _sender, mut events, _ops) =
crate::chatwidget::tests::make_chatwidget_manual_with_sender().await;
app.active_thread_id = Some(thread_id);
app.replace_chat_widget(widget);
app.replay_thread_snapshot(snapshot, /*resume_restored_queue*/ false);
app.chat_widget.handle_server_notification(
ServerNotification::ReasoningSummaryTextDelta(
codex_app_server_protocol::ReasoningSummaryTextDeltaNotification {
thread_id: thread_id.to_string(),
turn_id: "voice-turn".into(),
item_id: "late-reasoning".into(),
delta: "private after switch".into(),
summary_index: 0,
},
),
/*replay_kind*/ None,
);
app.chat_widget.handle_server_notification(
ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: "voice-turn".into(),
completed_at_ms: 0,
item: ThreadItem::Reasoning {
id: "late-reasoning".into(),
summary: vec!["private after switch".into()],
content: Vec::new(),
},
}),
/*replay_kind*/ None,
);
app.chat_widget.handle_server_notification(
delta(&thread_id.to_string(), "voice-turn", "private-commentary"),
/*replay_kind*/ None,
);
app.chat_widget.handle_server_notification(
ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: "voice-turn".into(),
completed_at_ms: 0,
item: ThreadItem::AgentMessage {
id: "private-commentary".into(),
text: "[COMMENTARY] private after switch".into(),
phase: None,
memory_citation: None,
delivery: None,
questions: None,
},
}),
/*replay_kind*/ None,
);
while let Ok(event) = events.try_recv() {
if let AppEvent::InsertHistoryCell(cell) = event {
let rendered = cell
.transcript_lines(/*width*/ 80)
.into_iter()
.map(|line| line.to_string())
.collect::<String>();
assert!(!rendered.contains("private"), "{rendered}");
}
}
}
#[tokio::test]
async fn buffered_replay_renders_completed_text_without_streaming_again() {
let (mut app, mut events, _ops) = make_test_app_with_channels().await;