mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Warn when saved model defaults are overridden (#42639)
## Why A model-default config write can succeed even when a higher-priority configuration layer overrides the saved value, leaving the TUI's success message misleading. ## What changed - Show a warning when saved model, reasoning-effort, or service-tier defaults are overridden. - Preserve the active conversation's explicit selection while reporting the saved default's effective status. ## Testing - Cover successful, overridden, and rejected writes against the app server's target config profile. GitOrigin-RevId: 6720d66a58629447b71cd9363c9e08c1c5b9edc1
This commit is contained in:
1 parent
0e0f55fc4e
commit
68e9c4a31a
6 files changed
+185
-6
No files matched your search
@@ -0,0 +1,130 @@
|
||||
use super::*;
|
||||
use codex_app_server_client::AppServerClient;
|
||||
use codex_config::LoaderOverrides;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn model_default_saves_report_server_outcomes_and_target_server_profile() -> Result<()> {
|
||||
for outcome in ["saved", "overridden", "rejected"] {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
app.config.model_reasoning_effort = Some(ReasoningEffortConfig::Medium);
|
||||
let local_config_path = app.config.codex_home.join("config.toml");
|
||||
let local_config_before = std::fs::read(&local_config_path).ok();
|
||||
let server_home = tempfile::tempdir()?;
|
||||
let base_path = server_home.path().join("config.toml");
|
||||
let profile_path = server_home.path().join("work.config.toml");
|
||||
std::fs::write(&base_path, "# Base configuration stays unchanged.\n")?;
|
||||
std::fs::write(&profile_path, "")?;
|
||||
let mut loader_overrides = LoaderOverrides::without_managed_config_for_tests();
|
||||
loader_overrides.user_config_path =
|
||||
Some(AbsolutePathBuf::from_absolute_path(&profile_path)?);
|
||||
loader_overrides.user_config_profile = Some("work".parse()?);
|
||||
let overrides = if outcome == "overridden" {
|
||||
vec![
|
||||
("model".into(), toml::Value::String("gpt-5.2".into())),
|
||||
(
|
||||
"model_reasoning_effort".into(),
|
||||
toml::Value::String("low".into()),
|
||||
),
|
||||
(
|
||||
"plan_mode_reasoning_effort".into(),
|
||||
toml::Value::String("low".into()),
|
||||
),
|
||||
("service_tier".into(), toml::Value::String("flex".into())),
|
||||
]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(server_home.path().to_path_buf())
|
||||
.cli_overrides(overrides.clone())
|
||||
.loader_overrides(loader_overrides.clone())
|
||||
.harness_overrides(ConfigOverrides {
|
||||
cwd: Some(server_home.path().to_path_buf()),
|
||||
..Default::default()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
let client = crate::start_embedded_app_server(
|
||||
codex_arg0::Arg0DispatchPaths::default(),
|
||||
config,
|
||||
overrides,
|
||||
loader_overrides,
|
||||
/*strict_config*/ false,
|
||||
codex_config::CloudConfigBundleLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
/*state_db*/ None,
|
||||
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
|
||||
)
|
||||
.await?;
|
||||
let mut server = AppServerSession::new(
|
||||
AppServerClient::InProcess(client),
|
||||
crate::app_server_session::ThreadParamsMode::Remote,
|
||||
);
|
||||
if outcome == "rejected" {
|
||||
std::fs::write(&profile_path, "[broken")?;
|
||||
}
|
||||
while events.try_recv().is_ok() {}
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
for event in [
|
||||
AppEvent::PersistModelSelection {
|
||||
model: "gpt-5.4".into(),
|
||||
effort: Some(ReasoningEffortConfig::High),
|
||||
},
|
||||
AppEvent::PersistPlanModeReasoningEffort(Some(ReasoningEffortConfig::High)),
|
||||
AppEvent::PersistServiceTierSelection {
|
||||
service_tier: Some(ServiceTier::Fast.request_value().into()),
|
||||
},
|
||||
AppEvent::ApplyAdvancedReasoning {
|
||||
model: "gpt-5.4".into(),
|
||||
effort: ReasoningEffortConfig::Ultra,
|
||||
},
|
||||
] {
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, event)).await?;
|
||||
}
|
||||
let messages = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => {
|
||||
Some(lines_to_single_string(&cell.display_lines(/*width*/ 80)))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert_eq!(
|
||||
messages.matches("higher-priority").count(),
|
||||
if outcome == "overridden" { 4 } else { 0 }
|
||||
);
|
||||
assert_eq!(
|
||||
messages.matches("Failed to save").count(),
|
||||
if outcome == "rejected" { 4 } else { 0 }
|
||||
);
|
||||
if outcome == "overridden" {
|
||||
insta::assert_snapshot!("overridden_model_defaults", messages);
|
||||
}
|
||||
let persisted = std::fs::read_to_string(&profile_path)?;
|
||||
if outcome == "rejected" {
|
||||
assert_eq!(persisted, "[broken");
|
||||
assert!(!messages.contains("Model changed"));
|
||||
assert!(!messages.contains("Service tier set"));
|
||||
} else {
|
||||
assert_eq!(
|
||||
toml::from_str::<toml::Value>(&persisted)?,
|
||||
toml::Value::Table(toml::toml! {
|
||||
model = "gpt-5.4"
|
||||
model_reasoning_effort = "medium"
|
||||
plan_mode_reasoning_effort = "high"
|
||||
service_tier = "fast"
|
||||
})
|
||||
);
|
||||
}
|
||||
assert_eq!(std::fs::read(&local_config_path).ok(), local_config_before);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(&base_path)?,
|
||||
"# Base configuration stays unchanged.\n"
|
||||
);
|
||||
server.shutdown().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/app/tests/model_defaults_tests.rs
|
||||
assertion_line: 91
|
||||
expression: messages
|
||||
---
|
||||
⚠ Saved default model and reasoning effort, but a higher-priority configuration
|
||||
layer overrides the saved value.
|
||||
• Model changed to gpt-5.4 high
|
||||
⚠ Saved Plan mode reasoning effort, but a higher-priority configuration layer
|
||||
overrides the saved value.
|
||||
⚠ Saved default service tier, but a higher-priority configuration layer
|
||||
overrides the saved value.
|
||||
• Service tier set to priority
|
||||
⚠ Saved default model and reasoning effort, but a higher-priority configuration
|
||||
layer overrides the saved value.
|
||||
• Model changed to gpt-5.4 ultra for this conversation
|
||||
Reference in new issue
Block a user