mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Fall back to the built-in status line for invalid providers (#61915)
## Why An invalid `tui.status_line_provider` should not prevent startup in normal mode. ## What changed Use the built-in status line when the effective provider selection is invalid and emit a startup warning identifying its source. Keep the invalid selection's precedence so it overrides lower-priority providers, while preserving the original configuration for diagnostics and `config/read`. With `--strict-config`, reject invalid provider selections in every configuration source. ## Testing Update coverage for malformed user settings and incomplete profile selections, and add a CLI case verifying strict provider validation before terminal checks. GitOrigin-RevId: 797d1c71dd4803db59ca91880a07e2e2118ce097
This commit is contained in:
@@ -91,6 +91,12 @@ fn interactive_validates_config_before_requiring_terminal() -> Result<()> {
|
||||
"",
|
||||
"unknown configuration field",
|
||||
),
|
||||
(
|
||||
&["--strict-config", "-c", "tui.status_line_provider=42"],
|
||||
"config.toml",
|
||||
"",
|
||||
"Invalid `tui.status_line_provider` in session-flags",
|
||||
),
|
||||
(
|
||||
&["--profile", "work"],
|
||||
"work.config.toml",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::types::StatusLineSelection;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::borrow::Cow;
|
||||
@@ -47,22 +48,33 @@ pub(crate) fn without_status_line_provider(config: &TomlValue) -> Cow<'_, TomlVa
|
||||
}
|
||||
|
||||
impl ConfigLayerSource {
|
||||
/// Project settings and packaged defaults cannot select a status line provider.
|
||||
pub(crate) fn effective_values<'a>(&self, config: &'a TomlValue) -> Cow<'a, TomlValue> {
|
||||
pub(crate) fn allows_status_line_provider(&self) -> bool {
|
||||
match self {
|
||||
Self::PackagedDefaults { .. } | Self::Project { .. } => {
|
||||
without_status_line_provider(config)
|
||||
}
|
||||
Self::PackagedDefaults { .. } | Self::Project { .. } => false,
|
||||
Self::User { .. }
|
||||
| Self::SessionFlags
|
||||
| Self::System { .. }
|
||||
| Self::EnterpriseManaged { .. }
|
||||
| Self::Mdm { .. }
|
||||
| Self::LegacyManagedConfigTomlFromFile { .. }
|
||||
| Self::LegacyManagedConfigTomlFromMdm => Cow::Borrowed(config),
|
||||
| Self::LegacyManagedConfigTomlFromMdm => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep the original layer for diagnostics and config/read. An invalid selection
|
||||
/// still overrides lower providers, just like an explicit built-in selection.
|
||||
pub(crate) fn effective_values<'a>(&self, config: &'a TomlValue) -> Cow<'a, TomlValue> {
|
||||
if !self.allows_status_line_provider() {
|
||||
return without_status_line_provider(config);
|
||||
}
|
||||
if status_line_provider_is_valid(config) == Some(false) {
|
||||
let mut effective = config.clone();
|
||||
effective["tui"]["status_line_provider"] = "default".into();
|
||||
return Cow::Owned(effective);
|
||||
}
|
||||
Cow::Borrowed(config)
|
||||
}
|
||||
|
||||
/// A setting from a layer with a higher precedence overrides a setting
|
||||
/// from a layer with a lower precedence.
|
||||
pub fn precedence(&self) -> i16 {
|
||||
@@ -86,6 +98,11 @@ impl ConfigLayerSource {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn status_line_provider_is_valid(config: &TomlValue) -> Option<bool> {
|
||||
let value = config.get("tui")?.get("status_line_provider")?;
|
||||
Some(value.clone().try_into::<StatusLineSelection>().is_ok())
|
||||
}
|
||||
|
||||
/// Compares [`ConfigLayerSource`] by precedence, so `A < B` means settings
|
||||
/// from layer `A` will be overridden by settings from layer `B`.
|
||||
impl PartialOrd for ConfigLayerSource {
|
||||
|
||||
@@ -45,6 +45,7 @@ use crate::state::validate_enabled_config_layers;
|
||||
use crate::strict_config::config_error_from_ignored_toml_value_fields;
|
||||
use crate::strict_config::ignored_config_warning;
|
||||
use crate::strict_config::ignored_toml_value_fields;
|
||||
use crate::strict_config::status_line_provider_warning;
|
||||
use crate::strict_config::unknown_feature_toml_value_field;
|
||||
use crate::strict_config::unknown_tui_toml_value_path;
|
||||
use crate::thread_config::ThreadConfigContext;
|
||||
@@ -525,6 +526,10 @@ pub async fn load_config_layers_state(
|
||||
);
|
||||
config_layer_stack.is_projectless = is_projectless;
|
||||
config_layer_stack.project_trust = project_trust;
|
||||
startup_warnings.extend(status_line_provider_warning(
|
||||
&config_layer_stack,
|
||||
strict_config,
|
||||
)?);
|
||||
if config_layer_stack.layers_low_to_high().any(|layer| {
|
||||
matches!(
|
||||
layer.name,
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::ConfigLayerStack;
|
||||
use crate::ConfigRequirementsToml;
|
||||
use crate::NetworkRequirementsToml;
|
||||
use crate::RequirementsLayerEntry;
|
||||
use crate::config_layer_source::status_line_provider_is_valid;
|
||||
use crate::config_toml::ConfigToml;
|
||||
use crate::diagnostics::ConfigDiagnosticSource;
|
||||
use crate::diagnostics::ConfigError;
|
||||
@@ -22,6 +23,7 @@ use serde::de::DeserializeOwned;
|
||||
use std::any::TypeId;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt::Write;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
@@ -226,6 +228,31 @@ fn push_ignored_path_segments(path: &serde_ignored::Path<'_>, segments: &mut Vec
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn status_line_provider_warning(
|
||||
config: &ConfigLayerStack,
|
||||
strict_config: bool,
|
||||
) -> io::Result<Option<String>> {
|
||||
let mut providers = config
|
||||
.layers_high_to_low()
|
||||
.filter(|layer| strict_config || layer.name.allows_status_line_provider())
|
||||
.filter_map(|layer| Some((&layer.name, status_line_provider_is_valid(&layer.config)?)));
|
||||
// Normal mode warns about the winning selection. Strict mode checks every source.
|
||||
let selection = if strict_config {
|
||||
providers.find(|(_, valid)| !valid)
|
||||
} else {
|
||||
providers.next()
|
||||
};
|
||||
let Some((source, false)) = selection else {
|
||||
return Ok(None);
|
||||
};
|
||||
let source = bounded_label(&format_config_layer_source(source, CONFIG_TOML_FILE));
|
||||
let message = format!("Invalid `tui.status_line_provider` in {source}.");
|
||||
if strict_config {
|
||||
return Err(io::Error::new(io::ErrorKind::InvalidData, message));
|
||||
}
|
||||
Ok(Some(format!("{message} Using the built-in status line.")))
|
||||
}
|
||||
|
||||
pub(crate) fn ignored_config_warning(
|
||||
config: &ConfigLayerStack,
|
||||
requirements: &[RequirementsLayerEntry],
|
||||
|
||||
@@ -328,14 +328,28 @@ async fn malformed_status_line_provider_uses_project_and_user_validation_rules()
|
||||
.expect_err("malformed project preference");
|
||||
assert_error_at(error, &project_file, 3);
|
||||
|
||||
std::fs::write(&user_config, malformed)?;
|
||||
for strict in [false, true] {
|
||||
assert_error_at(
|
||||
build(strict).await.expect_err("malformed user preference"),
|
||||
&user_config,
|
||||
2,
|
||||
);
|
||||
}
|
||||
std::fs::write(
|
||||
&user_config,
|
||||
"[tui]\nstatus_line_provider = { plugin = 'old', server = 'local', tool = 'usage' }\n",
|
||||
)?;
|
||||
let config = build(/*strict*/ false).await?;
|
||||
assert_eq!(
|
||||
config.tui_status_line_provider.as_deref(),
|
||||
Some(&StatusLineSelection::Builtin(BuiltinStatusLine::Default))
|
||||
);
|
||||
assert!(
|
||||
config
|
||||
.startup_warnings
|
||||
.iter()
|
||||
.any(|warning| warning.contains("tui.status_line_provider"))
|
||||
);
|
||||
assert_error_at(
|
||||
build(/*strict*/ true)
|
||||
.await
|
||||
.expect_err("malformed user preference"),
|
||||
&user_config,
|
||||
2,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -353,7 +367,7 @@ async fn status_line_provider_requires_a_complete_identity_in_the_selected_profi
|
||||
&profile,
|
||||
format!("[tui]\nstatus_line_provider = {{ {partial} }}\n"),
|
||||
)?;
|
||||
let result = ConfigBuilder::default()
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(home.path().to_path_buf())
|
||||
.loader_overrides(LoaderOverrides {
|
||||
user_config_path: Some(profile.clone()),
|
||||
@@ -361,10 +375,10 @@ async fn status_line_provider_requires_a_complete_identity_in_the_selected_profi
|
||||
..LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.build()
|
||||
.await;
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"accepted an incomplete provider: {partial}"
|
||||
.await?;
|
||||
assert_eq!(
|
||||
config.tui_status_line_provider.as_deref(),
|
||||
Some(&StatusLineSelection::Builtin(BuiltinStatusLine::Default))
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user