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;
File diff suppressed because it is too large. Load diff
@@ -197,11 +197,56 @@ pub(super) async fn start_recording_remote_app_server(
/// Proxies a real app server while optionally rejecting modern pagination like an older server.
pub(super) async fn start_recording_app_server_with_history(
config: &Config,
history_capabilities: HistoryCapabilities,
blocked_thread_list: Option<(ThreadId, oneshot::Sender<()>, oneshot::Receiver<()>)>,
failed_thread_name: Option<&'static str>,
thread_params_mode: crate::app_server_session::ThreadParamsMode,
loader_overrides: LoaderOverrides,
) -> Result<RecordingAppServer> {
start_recording_app_server_with_realtime_speech(
config,
history_capabilities,
blocked_thread_list,
failed_thread_name,
thread_params_mode,
RealtimeRequestBehavior::Forward,
loader_overrides,
)
.await
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum RealtimeRequestBehavior {
Forward,
AcceptStart,
AcceptSpeech,
AcceptSpeechAndStallStop,
}
pub(super) async fn start_recording_realtime_speech_app_server(
config: &Config,
realtime_behavior: RealtimeRequestBehavior,
) -> Result<RecordingAppServer> {
start_recording_app_server_with_realtime_speech(
config,
HistoryCapabilities::Current,
/*blocked_thread_list*/ None,
/*failed_thread_name*/ None,
crate::app_server_session::ThreadParamsMode::Embedded,
realtime_behavior,
LoaderOverrides::default(),
)
.await
}
async fn start_recording_app_server_with_realtime_speech(
config: &Config,
history_capabilities: HistoryCapabilities,
mut blocked_thread_list: Option<(ThreadId, oneshot::Sender<()>, oneshot::Receiver<()>)>,
failed_thread_name: Option<&'static str>,
thread_params_mode: crate::app_server_session::ThreadParamsMode,
realtime_behavior: RealtimeRequestBehavior,
loader_overrides: LoaderOverrides,
) -> Result<RecordingAppServer> {
let state_db =
@@ -256,6 +301,11 @@ pub(super) async fn start_recording_app_server_with_history(
.lock()
.expect("request recorder lock")
.push(request.clone());
if realtime_behavior == RealtimeRequestBehavior::AcceptSpeechAndStallStop
&& request.method == "thread/realtime/stop"
{
continue;
}
let request_id = request.id.clone();
let params = request.params.as_ref();
let requires_pagination = match request.method.as_str() {
@@ -286,7 +336,20 @@ pub(super) async fn start_recording_app_server_with_history(
.is_some_and(|tools| {
tools.iter().any(|tool| tool["type"] == "namespace")
});
let response = if let HistoryCapabilities::ConfigReadUnsupported(code) =
let fake_realtime_response = (realtime_behavior
== RealtimeRequestBehavior::AcceptStart
&& request.method == "thread/realtime/start")
|| (matches!(
realtime_behavior,
RealtimeRequestBehavior::AcceptSpeech
| RealtimeRequestBehavior::AcceptSpeechAndStallStop
) && request.method == "thread/realtime/appendSpeech");
let response = if fake_realtime_response {
JSONRPCMessage::Response(JSONRPCResponse {
id: request_id,
result: serde_json::json!({}),
})
} else if let HistoryCapabilities::ConfigReadUnsupported(code) =
history_capabilities
&& request.method == "config/read"
{
@@ -0,0 +1,7 @@
---
source: tui/src/app/tests/realtime_requests.rs
assertion_line: 1083
expression: "rendered.join(\"\\n\").replace(&thread_id.to_string(), \"<thread-id>\")"
---
• An answer to keep.
■ Voice conversation failed: thread/realtime/appendSpeech failed in TUI: thread/realtime/appendSpeech failed: thread not found: <thread-id> (code -32600)
@@ -0,0 +1,23 @@
---
source: tui/src/app/tests/realtime_requests.rs
assertion_line: 645
expression: "normalize_voice_snapshot_directory(&rendered, &app.config.cwd)"
---
╭────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: gpt-test /model to change │
│ directory: /tmp/project │
╰────────────────────────────────────────╯
To get started, describe a task or try one of these commands:
/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration
/permissions - choose what Codex is allowed to do
/model - choose what model and reasoning effort to use
/review - review any changes and find issues
› buffered question
• buffered answer
@@ -0,0 +1,20 @@
---
source: tui/src/app/tests/realtime_requests.rs
assertion_line: 182
expression: "rendered.replace(&app.config.cwd.display().to_string(), \"/tmp/project\")"
---
╭────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: gpt-test /model to change │
│ directory: /tmp/project │
╰────────────────────────────────────────╯
To get started, describe a task or try one of these commands:
/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration
/permissions - choose what Codex is allowed to do
/model - choose what model and reasoning effort to use
/review - review any changes and find issues
• spoken complete
@@ -0,0 +1,21 @@
---
source: tui/src/app/tests/realtime_requests.rs
assertion_line: 302
expression: "normalize_voice_snapshot_directory(&rendered, &app.config.cwd)"
---
╭────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: gpt-test /model to change │
│ directory: /tmp/project │
╰────────────────────────────────────────╯
To get started, describe a task or try one of these commands:
/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration
/permissions - choose what Codex is allowed to do
/model - choose what model and reasoning effort to use
/review - review any changes and find issues
› spoken partial completed
@@ -0,0 +1,33 @@
---
source: tui/src/app/tests/realtime_requests.rs
assertion_line: 561
expression: "normalize_voice_snapshot_directory(&rendered, &app.config.cwd)"
---
╭────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: gpt-test /model to change │
│ directory: /tmp/project │
╰────────────────────────────────────────╯
To get started, describe a task or try one of these commands:
/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration
/permissions - choose what Codex is allowed to do
/model - choose what model and reasoning effort to use
/review - review any changes and find issues
› show <code> & tests
• spoken answer
› typed words
› show <code> & tests
› typed words
• different caption