Files
codex/codex-rs/tui/src/async_question_reply_tests.rs
T
Eric Traut dbf478850f Make TUI async question replies compatible with desktop (#46486)
## Why

Async questions answered on another client should disappear from the TUI without losing drafts for other questions, even when questions have identical titles.

## What changed

- Send answers using the desktop reply envelope with stable per-question IDs, and resolve matching questions from committed messages and replayed history.
- Render replies as readable question-and-answer text in transcripts, queue previews, and input history.
- Preserve separate reply envelopes and message order when retrying rejected or interrupted input.
- Account for JSON escaping in input limits and fall back to plain text for oversized question IDs.

## Testing

Add regression coverage for cross-client dismissal, draft preservation, replay ordering, reply parsing, IDE context, distinct replies with identical text, and retry ordering. Update the async question scenario to use the reply envelope.

GitOrigin-RevId: 9b9e4b1e140508590401622d96cfc16fc192eb7c
2026-09-18 22:40:37 +00:00

36 lines
1.7 KiB
Rust

use super::*;
use pretty_assertions::assert_eq;
use serde_json::json;
#[test]
fn desktop_question_reply_accepts_single_and_batched_envelopes() {
let reply = json!({"questionItemId": "[\"request_user_input_async\",\"item\",0]", "question": "Which environment?", "answer": "Staging", "extra": true});
for payload in [reply.clone(), json!([reply])] {
let text = format!(
" \n<send_user_message_question_reply>\n{payload}\n</send_user_message_question_reply>\n "
);
assert_eq!(
display_text(&text).as_deref(),
Some("> Which environment?\n\nStaging")
);
}
let text = "<send_user_message_question_reply>[{\"questionItemId\":\"one\",\"question\":\"First?\",\"answer\":\"Yes\"},{\"questionItemId\":\"two\",\"question\":\"Second?\",\"answer\":\"No\"}]</send_user_message_question_reply>";
assert_eq!(
display_text(text).as_deref(),
Some("> First?\n\nYes\n\n> Second?\n\nNo")
);
}
#[test]
fn malformed_or_embedded_question_envelopes_remain_ordinary_text() {
for text in [
"> Which environment?\n\nStaging",
"<send_user_message_question_reply>[]</send_user_message_question_reply>",
"<send_user_message_question_reply>[{\"questionItemId\":\"one\",\"question\":\"First?\",\"answer\":\"Yes\"},null]</send_user_message_question_reply>",
"Quoted: <send_user_message_question_reply>{\"questionItemId\":\"one\",\"question\":\"First?\",\"answer\":\"Yes\"}</send_user_message_question_reply>",
"<send_user_message_question_reply>{\"questionItemId\":\"one\",\"question\":\"First?\",\"answer\":\"Yes\"}</send_user_message_question_reply> trailing text",
] {
assert_eq!(parse(text), None, "{text}");
}
}