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

+118 -86
View File
@@ -1,11 +1,37 @@
//! Focused visual coverage and shared setup for voice behavior tests.
//! Regression coverage for thread-owned voice sessions and transcript/handoff safety.
//! Synthetic events preserve typed turns and reject stale session generations.
use super::RealtimeConversationPhase;
use crate::app_command::AppCommand;
use crate::app_event::AppEvent;
use crate::chatwidget::ChatWidget;
use crate::chatwidget::ReplayKind;
use crate::chatwidget::tests::make_chatwidget_manual_with_sender;
use crate::chatwidget::tests::render_bottom_popup;
use codex_app_server_protocol::AgentMessageDeltaNotification;
use codex_app_server_protocol::ItemCompletedNotification;
use codex_app_server_protocol::ItemStartedNotification;
use codex_app_server_protocol::ReasoningSummaryPartAddedNotification;
use codex_app_server_protocol::ReasoningSummaryTextDeltaNotification;
use codex_app_server_protocol::ReasoningTextDeltaNotification;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnCompletedNotification;
use codex_app_server_protocol::TurnItemsView;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UserInput;
use codex_protocol::ThreadId;
use codex_protocol::items::AsyncUserInputQuestion;
use codex_protocol::models::MessagePhase;
use futures::future::AbortHandle;
use std::collections::VecDeque;
fn activate_voice(chat: &mut ChatWidget) -> ThreadId {
let thread_id = ThreadId::new();
activate_voice_for_thread(chat, thread_id);
thread_id
}
pub(crate) fn activate_voice_for_thread(chat: &mut ChatWidget, thread_id: ThreadId) {
chat.thread_id = Some(thread_id);
@@ -15,93 +41,99 @@ pub(crate) fn activate_voice_for_thread(chat: &mut ChatWidget, thread_id: Thread
chat.realtime_conversation.latest_input_was_voice = true;
}
#[tokio::test]
async fn enabling_voice_on_an_open_thread_snapshots_the_new_thread_notice() {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.set_feature_enabled(
codex_features::Feature::RealtimeConversation,
/*enabled*/ true,
fn user_item(text: &str) -> ThreadItem {
ThreadItem::UserMessage {
id: format!("user-{text}"),
client_id: None,
content: vec![UserInput::Text {
text: text.to_string(),
text_elements: Vec::new(),
}],
}
}
fn agent_item(item_id: &str, text: &str, phase: Option<MessagePhase>) -> ThreadItem {
ThreadItem::AgentMessage {
id: item_id.to_string(),
text: text.to_string(),
phase,
questions: None,
memory_citation: None,
delivery: None,
}
}
fn start_item(chat: &mut ChatWidget, thread_id: ThreadId, turn_id: &str, item: ThreadItem) {
chat.handle_server_notification(
ServerNotification::ItemStarted(ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: turn_id.to_string(),
item,
started_at_ms: 0,
}),
/*replay_kind*/ None,
);
let rendered = std::iter::from_fn(|| events.try_recv().ok())
.filter_map(|event| match event {
AppEvent::InsertHistoryCell(cell) => Some(
cell.display_lines(/*width*/ 80)
.into_iter()
.map(|line| line.to_string())
.collect::<Vec<_>>()
.join("\n"),
),
_ => None,
}
fn complete_item(chat: &mut ChatWidget, thread_id: ThreadId, turn_id: &str, item: ThreadItem) {
chat.handle_server_notification(
ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: turn_id.to_string(),
item,
completed_at_ms: 0,
}),
/*replay_kind*/ None,
);
}
fn finish_turn(
chat: &mut ChatWidget,
thread_id: ThreadId,
turn_id: &str,
items: Vec<ThreadItem>,
status: TurnStatus,
) {
chat.handle_server_notification(
ServerNotification::TurnCompleted(TurnCompletedNotification {
thread_id: thread_id.to_string(),
turn: Turn {
id: turn_id.to_string(),
items,
items_view: TurnItemsView::Summary,
status,
error: None,
started_at: None,
completed_at: None,
duration_ms: None,
},
}),
/*replay_kind*/ None,
);
}
fn without_completion_metadata(rendered: &str) -> String {
rendered
.lines()
.filter_map(|line| {
let stable = line
.split_once(" done ")
.map_or(line, |(before, _)| before);
(!stable.is_empty()).then_some(stable)
})
.collect::<Vec<_>>()
.join("\n");
insta::assert_snapshot!(rendered, @"• Voice conversations will be available in new threads.");
.join("\n")
}
#[tokio::test]
async fn voice_footer_renders_the_main_conversation_states() {
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
let mut states = Vec::new();
for (label, phase, muted, level, speaker_level, role, transcript) in [
(
"connecting",
RealtimeConversationPhase::Starting,
false,
0,
0,
None,
"",
),
(
"listening",
RealtimeConversationPhase::Active,
false,
0,
0,
None,
"",
),
(
"speaking",
RealtimeConversationPhase::Active,
false,
4,
5,
None,
"",
),
(
"muted",
RealtimeConversationPhase::Active,
true,
4,
4,
None,
"",
),
(
"transcript",
RealtimeConversationPhase::Active,
false,
2,
2,
Some("assistant"),
"Hello there",
),
] {
chat.realtime_conversation.phase = phase;
chat.realtime_conversation.microphone_muted = muted;
chat.realtime_conversation.microphone_level = level;
chat.realtime_conversation.speaker_level = speaker_level;
chat.realtime_conversation.transcript_role = role.map(str::to_string);
chat.realtime_conversation.transcript = transcript.to_string();
chat.update_realtime_footer();
states.push(format!(
"{label}:\n{}",
render_bottom_popup(&chat, /*width*/ 80)
));
}
insta::assert_snapshot!(states.join("\n\n"));
}
#[path = "realtime_tests/caption_replay.rs"]
mod caption_replay;
#[path = "realtime_tests/handoff_privacy.rs"]
mod handoff_privacy;
#[path = "realtime_tests/handoffs.rs"]
mod handoffs;
#[path = "realtime_tests/lifecycle.rs"]
mod lifecycle;
#[path = "realtime_tests/speech_recovery.rs"]
mod speech_recovery;
#[path = "realtime_tests/transcripts.rs"]
mod transcripts;