From 0435890df97d8f5808fd8fbacc56317b9c85bd4c Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sun, 29 Nov 2026 22:46:44 +0000 Subject: [PATCH] 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 --- codex-rs/tui/src/local_settings.rs | 15 +++++++++ codex-rs/tui/src/local_settings_tests.rs | 40 ++++++++++++----------- codex-rs/tui/src/startup_orchestration.rs | 9 ++--- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/codex-rs/tui/src/local_settings.rs b/codex-rs/tui/src/local_settings.rs index 8c0def4b50..cfd29624e7 100644 --- a/codex-rs/tui/src/local_settings.rs +++ b/codex-rs/tui/src/local_settings.rs @@ -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 { + 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, diff --git a/codex-rs/tui/src/local_settings_tests.rs b/codex-rs/tui/src/local_settings_tests.rs index 8661e569bd..9b2ce018a1 100644 --- a/codex-rs/tui/src/local_settings_tests.rs +++ b/codex-rs/tui/src/local_settings_tests.rs @@ -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(()) } diff --git a/codex-rs/tui/src/startup_orchestration.rs b/codex-rs/tui/src/startup_orchestration.rs index 31410478a5..8ff497f0df 100644 --- a/codex-rs/tui/src/startup_orchestration.rs +++ b/codex-rs/tui/src/startup_orchestration.rs @@ -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