mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why Different backends can return the same thread ID. A Cloud environment selection must apply to the draft on the backend that opened the picker. When the TUI reads or resumes a specific thread, an unexpected server response can otherwise attach history or apply settings to the wrong thread. ## What changed - Match Cloud environment selections against both the backend and the draft thread ID. - Reject mismatched thread IDs in read and resume flows before hydrating history or applying resume permission settings. Preserve subscription bookkeeping so a rejected resume can still be cleaned up. ## Testing Add regression coverage for a thread start that reuses an ID from another backend and a mismatched resume that preserves the active conversation, composer draft, and approval override without sending a settings update. GitOrigin-RevId: 603efe7aa37e510dacf91b58487a94469c7f183d
65 lines
2.4 KiB
Rust
65 lines
2.4 KiB
Rust
#![cfg(test)]
|
|
|
|
use super::*;
|
|
use crate::app::tests::make_test_app_with_channels;
|
|
use crate::chatwidget::tests::render_bottom_popup;
|
|
use crossterm::event::KeyCode;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[tokio::test]
|
|
async fn cloud_environment_picker_shows_default_and_saved_choice() {
|
|
let (mut app, mut events, _) = make_test_app_with_channels().await;
|
|
let source = crate::backend_id::BackendId::new().thread(codex_protocol::ThreadId::new());
|
|
let saved = SavedEnvironment {
|
|
id: "ws~asenvcfg_saved".into(),
|
|
name: "Team Rust".into(),
|
|
workspace_shared: true,
|
|
};
|
|
app.chat_widget
|
|
.show_selection_view(cloud_environment_picker(Ok(vec![saved.clone()]), source));
|
|
|
|
let rendered = render_bottom_popup(&app.chat_widget, /*width*/ 110);
|
|
let rows = ["Cloud environment", "Default", "Team Rust"].map(|label| {
|
|
let line = rendered.lines().find(|line| line.contains(label)).unwrap();
|
|
line[line.find(label).unwrap()..]
|
|
.split_whitespace()
|
|
.collect::<Vec<_>>()
|
|
.join(" ")
|
|
});
|
|
insta::assert_snapshot!(rows.join("\n"), @"
|
|
Cloud environment
|
|
Default Use the default environment with the current GitHub project, if available
|
|
Team Rust Workspace environment
|
|
");
|
|
|
|
for key in "rust".chars().map(KeyCode::Char) {
|
|
app.chat_widget.handle_key_event(key.into());
|
|
}
|
|
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
|
let selection = std::iter::from_fn(|| events.try_recv().ok()).find_map(|event| match event {
|
|
AppEvent::StartCloudConversation {
|
|
source,
|
|
saved_environment,
|
|
} => Some((source, saved_environment)),
|
|
_ => None,
|
|
});
|
|
assert_eq!(selection, Some((source, Some(saved))));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn dismissing_cloud_environment_loading_keeps_the_draft() {
|
|
let (mut app, _, _) = make_test_app_with_channels().await;
|
|
app.chat_widget.apply_external_edit("draft".into());
|
|
app.chat_widget.show_selection_view(loading_view());
|
|
app.chat_widget.handle_key_event(KeyCode::Esc.into());
|
|
let view = cloud_environment_picker(
|
|
Ok(Vec::new()),
|
|
crate::backend_id::BackendId::new().thread(codex_protocol::ThreadId::new()),
|
|
);
|
|
assert!(
|
|
!app.chat_widget
|
|
.replace_selection_view_if_present(LOADING_VIEW_ID, view)
|
|
);
|
|
assert_eq!(app.chat_widget.composer_text_with_pending(), "draft");
|
|
}
|