Files
codex/codex-rs/config/src/loader/project_discovery.rs
T
joeflorencio-openai 6ec012668b Honor managed config during project discovery (#39306)
## What changed

- Include legacy managed-file and MDM settings when resolving project root markers and project trust in both canonical and executor-local config loads.
- Preserve the existing managed-layer precedence in the final config stack and resolve managed relative paths against the same bases used by the final loader.
- Update explicit-untrusted warnings to describe the effective configuration and direct users to an administrator when the setting is managed.

## Testing

- Cover managed root markers, managed trust overrides, MDM precedence, app-server config reads, and the remote TUI warning.

GitOrigin-RevId: 9b5ddd54b4530f73589d6842a15cbab7e6d6bbb9
2026-08-18 22:44:28 +00:00

43 lines
1.5 KiB
Rust

//! Shared configuration composition for project-root and trust discovery.
use super::layer_io::LoadedConfigLayers;
use super::resolve_relative_paths_in_config_toml;
use crate::merge_toml_values;
use std::io;
use std::path::Path;
use toml::Value as TomlValue;
/// Overlay the already-read managed sources at their normal precedence: file,
/// then MDM. Resolve paths as the final loader does, without changing the raw
/// layers or reading either source again.
pub(super) fn merge_managed_config_for_discovery(
discovery_config: &mut TomlValue,
loaded: &LoadedConfigLayers,
codex_home: &Path,
) -> io::Result<()> {
if let Some(config) = &loaded.managed_config {
let base_dir = config.file.as_path().parent().ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidData,
format!(
"Managed config file {} has no parent directory",
config.file.as_path().display()
),
)
})?;
let resolved =
resolve_relative_paths_in_config_toml(config.managed_config.clone(), base_dir)?;
merge_toml_values(discovery_config, &resolved);
}
if let Some(config) = &loaded.managed_config_from_mdm {
let resolved =
resolve_relative_paths_in_config_toml(config.managed_config.clone(), codex_home)?;
merge_toml_values(discovery_config, &resolved);
}
Ok(())
}
#[cfg(test)]
#[path = "managed_project_discovery_tests.rs"]
mod tests;