mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
Build TUI startup preferences from the final config layers (#64641)
## What changed Reuse the local settings bootstrap parser on the final in-memory config layers before applying TUI startup preferences. ## Testing Extend the local settings test to check parity with preferences derived from the full config and verify that a managed layer seen only by the final load overrides the startup values for paste burst handling and alternate screen mode. GitOrigin-RevId: a8cc2fd667ca10fb9765be429974bd04c634e9c0
This commit is contained in:
@@ -161,6 +161,21 @@ impl LocalSettings {
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
/// Build client preferences from configuration layers already in memory.
|
||||
pub(crate) fn from_layers(
|
||||
codex_home: &AbsolutePathBuf,
|
||||
layers: &ConfigLayerStack,
|
||||
) -> std::io::Result<Self> {
|
||||
let bootstrap = ConfigTomlLoadResult {
|
||||
config_toml: crate::legacy_core::config::deserialize_config_toml_with_base(
|
||||
layers.effective_config(),
|
||||
codex_home.as_path(),
|
||||
)?,
|
||||
config_layer_stack: layers.clone(),
|
||||
};
|
||||
Self::from_bootstrap(&bootstrap, codex_home.clone()).map_err(std::io::Error::other)
|
||||
}
|
||||
|
||||
fn apply_host_preferences(
|
||||
&mut self,
|
||||
layers: &ConfigLayerStack,
|
||||
|
||||
@@ -185,11 +185,20 @@ fast_default_opt_out = true
|
||||
config_text.is_empty().into(),
|
||||
),
|
||||
];
|
||||
// Only the final load sees this managed layer.
|
||||
let managed = home.path().join("managed_config.toml");
|
||||
let managed_override = !config_text.is_empty();
|
||||
if managed_override {
|
||||
std::fs::write(
|
||||
&managed,
|
||||
"[tui]\nalternate_screen = 'never'\ndisable_paste_burst = false\n",
|
||||
)?;
|
||||
}
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(home.path().to_path_buf())
|
||||
.fallback_cwd(Some(project.path().to_path_buf()))
|
||||
.strict_config(true)
|
||||
.loader_overrides(LoaderOverrides::without_managed_config_for_tests())
|
||||
.loader_overrides(LoaderOverrides::with_managed_config_path_for_tests(managed))
|
||||
.cli_overrides(cli_overrides.clone())
|
||||
.build()
|
||||
.await?;
|
||||
@@ -208,33 +217,26 @@ fast_default_opt_out = true
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
LocalSettings::from_bootstrap(&bootstrap, config.codex_home.clone())?,
|
||||
LocalSettings::from(&config),
|
||||
);
|
||||
let early = LocalSettings::from_bootstrap(&bootstrap, config.codex_home.clone())?;
|
||||
assert_eq!(early.tui.disable_paste_burst, Some(true));
|
||||
let settings = LocalSettings::from_layers(&config.codex_home, &config.config_layer_stack)?;
|
||||
assert_eq!(settings, LocalSettings::from(&config));
|
||||
assert_eq!(settings.tui.disable_paste_burst, Some(!managed_override));
|
||||
assert_eq!(settings.transcript_mode.is_owned(), !managed_override);
|
||||
assert_eq!(config.features.legacy_feature_usages().count(), 1);
|
||||
assert_eq!(config.tui_theme.as_deref(), Some("project-theme"));
|
||||
assert_eq!(settings.tui.theme.as_deref(), Some("project-theme"));
|
||||
assert_eq!(
|
||||
config.tui_status_line_provider.as_deref(),
|
||||
settings.tui.status_line_provider.as_deref(),
|
||||
Some(&StatusLineSelection::Builtin(BuiltinStatusLine::Default)),
|
||||
);
|
||||
assert!(
|
||||
LocalSettings::from(&config)
|
||||
.tui
|
||||
.default_hosts
|
||||
.get("project_a")
|
||||
.and_then(|users| users.get("user_b"))
|
||||
.is_none()
|
||||
);
|
||||
let hosts = settings.tui.default_hosts.get("project_a");
|
||||
assert_eq!(
|
||||
LocalSettings::from(&config)
|
||||
.tui
|
||||
.default_hosts
|
||||
.get("project_a")
|
||||
hosts
|
||||
.and_then(|users| users.get("user_a"))
|
||||
.map(String::as_str),
|
||||
expected_server,
|
||||
);
|
||||
assert!(hosts.is_none_or(|users| !users.contains_key("user_b")));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -524,10 +524,11 @@ pub(super) async fn run_main_inner(
|
||||
if app_server_target.uses_embedded_network_policy() {
|
||||
embedded_network_policy.activate(&mut config);
|
||||
}
|
||||
startup_draft.apply_settings(
|
||||
&crate::local_settings::LocalSettings::from(&config),
|
||||
config.cwd.as_path(),
|
||||
);
|
||||
let local_settings = crate::local_settings::LocalSettings::from_layers(
|
||||
&config.codex_home,
|
||||
&config.config_layer_stack,
|
||||
)?;
|
||||
startup_draft.apply_settings(&local_settings, config.cwd.as_path());
|
||||
|
||||
let mut cloud_config_bundle = if workload_identity_selected {
|
||||
cloud_config_bundle
|
||||
|
||||
Reference in New Issue
Block a user