mirror of
https://github.com/openai/codex.git
synced 2026-11-20 23:08:21 +00:00
Stop loading legacy managed config on Windows (#38947)
## What changed - Ignore the default `CODEX_HOME/managed_config.toml` on Windows and exclude it from local managed-configuration detection. - Emit a startup warning when the deprecated file exists, directing users to `%ProgramData%\OpenAI\Codex\requirements.toml` for enforced settings or `config.toml` for defaults. - Preserve explicit managed-config path overrides and Unix legacy-file support. ## Testing - Add Windows tests covering ignored legacy settings, the startup warning, and managed-configuration detection through `requirements.toml`. GitOrigin-RevId: a61d9d9912b13817ba82807a486c9ed92e49c7bc
This commit is contained in:
1 parent
e38290846c
commit
c6058ccaa9
3 files changed
+158
-21
No files matched your search
@@ -94,11 +94,12 @@ async fn first_layer_config_error_from_entries(layers: &[ConfigLayerEntry]) -> O
|
||||
/// - system `/etc/codex/requirements.toml` (Unix) or
|
||||
/// `%ProgramData%\OpenAI\Codex\requirements.toml` (Windows)
|
||||
/// - cloud: enterprise-managed cloud config bundle requirements
|
||||
/// - legacy: managed_config.toml reinterpreted as requirements.toml
|
||||
/// - legacy: `/etc/codex/managed_config.toml` (Unix) reinterpreted as
|
||||
/// requirements.toml
|
||||
/// - admin: managed preferences (*)
|
||||
///
|
||||
/// For backwards compatibility, we also load from
|
||||
/// `managed_config.toml` and map it to `requirements.toml`.
|
||||
/// For backwards compatibility, Unix continues to load
|
||||
/// `/etc/codex/managed_config.toml` and map it to `requirements.toml`.
|
||||
///
|
||||
/// Configuration is built up from multiple layers in the following order:
|
||||
///
|
||||
@@ -233,10 +234,12 @@ pub async fn load_config_layers_state(
|
||||
let loaded_config_layers =
|
||||
layer_io::load_config_layers_internal(fs, codex_home, overrides.clone(), strict_config)
|
||||
.await?;
|
||||
let mut startup_warnings = (!loaded_config_layers.startup_warnings.is_empty())
|
||||
.then(|| loaded_config_layers.startup_warnings.clone());
|
||||
if !ignore_managed_requirements {
|
||||
requirements_layers.extend(system_requirements_layer);
|
||||
requirements_layers.extend(bundle_requirements_layers);
|
||||
// Continue to support the legacy `managed_config.toml` locations as
|
||||
// Continue to support loaded legacy `managed_config.toml` sources as
|
||||
// requirements layers for backwards compatibility.
|
||||
requirements_layers.extend(requirements_layers_from_legacy_scheme(
|
||||
loaded_config_layers.clone(),
|
||||
@@ -353,7 +356,6 @@ pub async fn load_config_layers_state(
|
||||
);
|
||||
}
|
||||
|
||||
let mut startup_warnings = None;
|
||||
if !ignore_project_config && let Some(cwd) = cwd {
|
||||
let mut merged_so_far = TomlValue::Table(toml::map::Map::new());
|
||||
for layer in &layers {
|
||||
@@ -412,7 +414,9 @@ pub async fn load_config_layers_state(
|
||||
)
|
||||
.await?;
|
||||
layers.extend(project_layers.layers);
|
||||
startup_warnings = Some(project_layers.startup_warnings);
|
||||
startup_warnings
|
||||
.get_or_insert_with(Vec::new)
|
||||
.extend(project_layers.startup_warnings);
|
||||
}
|
||||
|
||||
// Add a layer for runtime overrides from the CLI or UI, if any exist.
|
||||
@@ -435,6 +439,7 @@ pub async fn load_config_layers_state(
|
||||
let LoadedConfigLayers {
|
||||
managed_config,
|
||||
managed_config_from_mdm,
|
||||
..
|
||||
} = loaded_config_layers;
|
||||
if let Some(config) = managed_config {
|
||||
let managed_parent = config.file.as_path().parent().ok_or_else(|| {
|
||||
@@ -736,9 +741,26 @@ fn system_requirements_toml_file_with_overrides(
|
||||
/// Filesystem or managed-preference errors are returned so callers can conservatively avoid
|
||||
/// assuming that administrator-controlled configuration is absent.
|
||||
pub fn has_local_managed_configuration(codex_home: &Path) -> io::Result<bool> {
|
||||
if layer_io::managed_config_default_path(codex_home).try_exists()?
|
||||
|| system_requirements_toml_file()?.as_path().try_exists()?
|
||||
{
|
||||
let system_requirements_file = system_requirements_toml_file()?;
|
||||
has_local_managed_configuration_with_system_requirements_path(
|
||||
codex_home,
|
||||
system_requirements_file.as_path(),
|
||||
)
|
||||
}
|
||||
|
||||
fn has_local_managed_configuration_with_system_requirements_path(
|
||||
codex_home: &Path,
|
||||
system_requirements_path: &Path,
|
||||
) -> io::Result<bool> {
|
||||
#[cfg(windows)]
|
||||
let _ = codex_home;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
if layer_io::managed_config_default_path(codex_home).try_exists()? {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if system_requirements_path.try_exists()? {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@@ -852,6 +874,7 @@ fn requirements_layers_from_legacy_scheme(
|
||||
let LoadedConfigLayers {
|
||||
managed_config,
|
||||
managed_config_from_mdm,
|
||||
..
|
||||
} = loaded_config_layers;
|
||||
|
||||
let layer_count =
|
||||
|
||||
Reference in new issue
Block a user