mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
Discover TUI collaboration modes from the app server (#42401)
## What changed - Fetch `collaborationMode/list` during TUI startup and reconnect, and use the returned catalog for visible collaboration-mode selection. - Keep collaboration-mode discovery optional with a two-second timeout so an unavailable, invalid, or unsupported response does not block bootstrap. - Preserve discovered modes when the model catalog refreshes, clear restored developer-instruction overrides when selecting a server mode, and retain a `/plan` draft when plan mode is unavailable. ## Testing - Cover optional discovery failures and catalog refresh on reconnect. - Cover server mode selection, model refreshes, restored settings, and unavailable plan mode. GitOrigin-RevId: a6e35c14aab2e38526606164091ac64c500151bb
This commit is contained in:
1 parent
54a4077c8b
commit
d4dc882998
15 files changed
+292
-22
No files matched your search
@@ -0,0 +1,93 @@
|
||||
//! Server choices are independent of model refresh and restored task settings.
|
||||
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn collaboration_catalog_selection_clears_restored_prompt_and_survives_model_refresh() {
|
||||
let (mut chat, _events, _ops) = make_chatwidget_manual(Some("gpt-5.2")).await;
|
||||
let restored = CollaborationMode {
|
||||
mode: ModeKind::Default,
|
||||
settings: Settings {
|
||||
model: "gpt-5.2".into(),
|
||||
reasoning_effort: Some(ReasoningEffortConfig::Low),
|
||||
developer_instructions: Some("stale restored prompt".into()),
|
||||
},
|
||||
};
|
||||
chat.set_effective_collaboration_mode(restored.clone());
|
||||
let plan = CollaborationModeMask {
|
||||
name: "Server plan".into(),
|
||||
mode: Some(ModeKind::Plan),
|
||||
model: None,
|
||||
reasoning_effort: Some(Some(ReasoningEffortConfig::High)),
|
||||
developer_instructions: Some(None),
|
||||
};
|
||||
Arc::make_mut(&mut chat.model_catalog).collaboration_modes = vec![plan.clone()];
|
||||
let mut models = chat.model_catalog.try_list_models().unwrap();
|
||||
models[0].description = "Refreshed model description".into();
|
||||
let request_id = uuid::Uuid::new_v4();
|
||||
chat.model_popup_request_id = Some(request_id);
|
||||
assert!(chat.on_models_loaded(request_id, Ok(models)));
|
||||
assert_eq!(chat.model_catalog.collaboration_modes, vec![plan]);
|
||||
assert_eq!(chat.effective_collaboration_mode(), restored);
|
||||
assert!(collaboration_modes::default_mode_mask(&chat.model_catalog).is_none());
|
||||
|
||||
chat.cycle_collaboration_mode();
|
||||
assert_eq!(
|
||||
chat.effective_collaboration_mode(),
|
||||
CollaborationMode {
|
||||
mode: ModeKind::Plan,
|
||||
settings: Settings {
|
||||
model: "gpt-5.2".into(),
|
||||
reasoning_effort: Some(ReasoningEffortConfig::High),
|
||||
developer_instructions: None,
|
||||
},
|
||||
}
|
||||
);
|
||||
chat.set_plan_mode_reasoning_effort(Some(ReasoningEffortConfig::Ultra));
|
||||
chat.cycle_collaboration_mode();
|
||||
assert_eq!(
|
||||
chat.effective_reasoning_effort(),
|
||||
Some(ReasoningEffortConfig::Ultra)
|
||||
);
|
||||
chat.set_plan_mode_reasoning_effort(/*effort*/ None);
|
||||
assert_eq!(
|
||||
chat.effective_reasoning_effort(),
|
||||
Some(ReasoningEffortConfig::High)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn collaboration_catalog_unavailable_preserves_task_and_plan_input() {
|
||||
let (mut chat, _events, _ops) = make_chatwidget_manual(Some("gpt-5.2")).await;
|
||||
Arc::make_mut(&mut chat.model_catalog)
|
||||
.collaboration_modes
|
||||
.clear();
|
||||
for mode in [ModeKind::Default, ModeKind::Plan] {
|
||||
let restored = CollaborationMode {
|
||||
mode,
|
||||
settings: Settings {
|
||||
model: "task-model".into(),
|
||||
reasoning_effort: Some(ReasoningEffortConfig::Ultra),
|
||||
developer_instructions: Some("restored prompt".into()),
|
||||
},
|
||||
};
|
||||
chat.set_effective_collaboration_mode(restored.clone());
|
||||
chat.cycle_collaboration_mode();
|
||||
assert_eq!(chat.effective_collaboration_mode(), restored);
|
||||
}
|
||||
chat.set_effective_collaboration_mode(CollaborationMode {
|
||||
mode: ModeKind::Default,
|
||||
settings: Settings {
|
||||
model: "task-model".into(),
|
||||
reasoning_effort: Some(ReasoningEffortConfig::Low),
|
||||
developer_instructions: None,
|
||||
},
|
||||
});
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.bottom_pane
|
||||
.set_composer_text("/plan keep my draft".into(), Vec::new(), Vec::new());
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert_eq!(chat.bottom_pane.composer_text(), "/plan keep my draft");
|
||||
assert_eq!(chat.active_mode_kind(), ModeKind::Default);
|
||||
}
|
||||
@@ -140,9 +140,12 @@ pub(super) fn test_session_telemetry(config: &Config, model: &str) -> SessionTel
|
||||
}
|
||||
|
||||
pub(super) fn test_model_catalog(_config: &Config) -> Arc<ModelCatalog> {
|
||||
Arc::new(ModelCatalog::new(
|
||||
crate::test_support::TEST_MODEL_PRESETS.clone(),
|
||||
))
|
||||
Arc::new(
|
||||
ModelCatalog::new(crate::test_support::TEST_MODEL_PRESETS.clone())
|
||||
.with_collaboration_modes(
|
||||
codex_models_manager::collaboration_mode_presets::builtin_collaboration_mode_presets(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// --- Helpers for tests that need direct construction and event draining ---
|
||||
@@ -309,7 +312,7 @@ pub(crate) fn set_fast_mode_test_catalog(chat: &mut ChatWidget) {
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
|
||||
chat.model_catalog = Arc::new(ModelCatalog::new(models));
|
||||
Arc::make_mut(&mut chat.model_catalog).models = models;
|
||||
}
|
||||
|
||||
pub(crate) async fn make_chatwidget_manual_with_sender() -> (
|
||||
|
||||
@@ -1483,7 +1483,7 @@ async fn plan_slash_command_with_hidden_shell_paste_rejected_image_remains_liter
|
||||
.expect("current model")
|
||||
.input_modalities
|
||||
.retain(|modality| *modality != InputModality::Image);
|
||||
chat.model_catalog = Arc::new(ModelCatalog::new(models));
|
||||
Arc::make_mut(&mut chat.model_catalog).models = models;
|
||||
let payload = paste_hidden_plan_shell_payload(&mut chat);
|
||||
chat.set_remote_image_urls(vec!["https://example.com/image.png".to_string()]);
|
||||
|
||||
@@ -1558,7 +1558,7 @@ async fn rejected_initial_image_does_not_submit_later_queued_prompt() {
|
||||
.expect("current model")
|
||||
.input_modalities
|
||||
.retain(|modality| *modality != InputModality::Image);
|
||||
chat.model_catalog = Arc::new(ModelCatalog::new(models));
|
||||
Arc::make_mut(&mut chat.model_catalog).models = models;
|
||||
let mut initial_message = UserMessage::from("initial prompt");
|
||||
initial_message.remote_image_urls = vec!["https://example.com/image.png".to_string()];
|
||||
chat.initial_user_message = Some(initial_message);
|
||||
|
||||
Reference in new issue
Block a user