mirror of
https://github.com/openai/codex.git
synced 2026-05-05 13:51:29 +03:00
## Why Config loading had become split across crates: `codex-config` owned the config types and merge logic, while `codex-core` still owned the loader that assembled the layer stack. This change consolidates that responsibility in `codex-config`, so the crate that defines config behavior also owns how configs are discovered and loaded. To make that move possible without reintroducing the old dependency cycle, the shell-environment policy types and helpers that `codex-exec-server` needs now live in `codex-protocol` instead of flowing through `codex-config`. This also makes the migrated loader tests more deterministic on machines that already have managed or system Codex config installed by letting tests override the system config and requirements paths instead of reading the host's `/etc/codex`. ## What Changed - moved the config loader implementation from `codex-core` into `codex-config::loader` and deleted the old `core::config_loader` module instead of leaving a compatibility shim - moved shell-environment policy types and helpers into `codex-protocol`, then updated `codex-exec-server` and other downstream crates to import them from their new home - updated downstream callers to use loader/config APIs from `codex-config` - added test-only loader overrides for system config and requirements paths so loader-focused tests do not depend on host-managed config state - cleaned up now-unused dependency entries and platform-specific cfgs that were surfaced by post-push CI ## Testing - `cargo test -p codex-config` - `cargo test -p codex-core config_loader_tests::` - `cargo test -p codex-protocol -p codex-exec-server -p codex-cloud-requirements -p codex-rmcp-client --lib` - `cargo test --lib -p codex-app-server-client -p codex-exec` - `cargo test --no-run --lib -p codex-app-server` - `cargo test -p codex-linux-sandbox --lib` - `cargo shear` - `just bazel-lock-check` ## Notes - I did not chase unrelated full-suite failures outside the migrated loader surface. - `cargo test -p codex-core --lib` still hits unrelated proxy-sensitive failures on this machine, and Windows CI still shows unrelated long-running/timeouting test noise outside the loader migration itself.
138 lines
4.2 KiB
Rust
138 lines
4.2 KiB
Rust
#[cfg(target_os = "macos")]
|
|
use super::macos::ManagedAdminConfigLayer;
|
|
#[cfg(target_os = "macos")]
|
|
use super::macos::load_managed_admin_config_layer;
|
|
use crate::diagnostics::config_error_from_toml;
|
|
use crate::diagnostics::io_error_from_config_error;
|
|
use crate::state::LoaderOverrides;
|
|
use codex_exec_server::ExecutorFileSystem;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use std::io;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
use toml::Value as TomlValue;
|
|
|
|
#[cfg(unix)]
|
|
const CODEX_MANAGED_CONFIG_SYSTEM_PATH: &str = "/etc/codex/managed_config.toml";
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(super) struct MangedConfigFromFile {
|
|
pub managed_config: TomlValue,
|
|
pub file: AbsolutePathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(super) struct ManagedConfigFromMdm {
|
|
pub managed_config: TomlValue,
|
|
pub raw_toml: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(super) struct LoadedConfigLayers {
|
|
/// If present, data read from a file such as `/etc/codex/managed_config.toml`.
|
|
pub managed_config: Option<MangedConfigFromFile>,
|
|
/// If present, data read from managed preferences (macOS only).
|
|
pub managed_config_from_mdm: Option<ManagedConfigFromMdm>,
|
|
}
|
|
|
|
pub(super) async fn load_config_layers_internal(
|
|
fs: &dyn ExecutorFileSystem,
|
|
codex_home: &Path,
|
|
overrides: LoaderOverrides,
|
|
) -> io::Result<LoadedConfigLayers> {
|
|
#[cfg(target_os = "macos")]
|
|
let LoaderOverrides {
|
|
managed_config_path,
|
|
managed_preferences_base64,
|
|
..
|
|
} = overrides;
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
let LoaderOverrides {
|
|
managed_config_path,
|
|
..
|
|
} = overrides;
|
|
|
|
let managed_config_path = AbsolutePathBuf::from_absolute_path(
|
|
managed_config_path.unwrap_or_else(|| managed_config_default_path(codex_home)),
|
|
)?;
|
|
|
|
let managed_config =
|
|
read_config_from_path(fs, &managed_config_path, /*log_missing_as_info*/ false)
|
|
.await?
|
|
.map(|managed_config| MangedConfigFromFile {
|
|
managed_config,
|
|
file: managed_config_path.clone(),
|
|
});
|
|
|
|
#[cfg(target_os = "macos")]
|
|
let managed_preferences =
|
|
load_managed_admin_config_layer(managed_preferences_base64.as_deref())
|
|
.await?
|
|
.map(map_managed_admin_layer);
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
let managed_preferences = None;
|
|
|
|
Ok(LoadedConfigLayers {
|
|
managed_config,
|
|
managed_config_from_mdm: managed_preferences,
|
|
})
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
fn map_managed_admin_layer(layer: ManagedAdminConfigLayer) -> ManagedConfigFromMdm {
|
|
let ManagedAdminConfigLayer { config, raw_toml } = layer;
|
|
ManagedConfigFromMdm {
|
|
managed_config: config,
|
|
raw_toml,
|
|
}
|
|
}
|
|
|
|
pub(super) async fn read_config_from_path(
|
|
fs: &dyn ExecutorFileSystem,
|
|
path: &AbsolutePathBuf,
|
|
log_missing_as_info: bool,
|
|
) -> io::Result<Option<TomlValue>> {
|
|
match fs.read_file_text(path, /*sandbox*/ None).await {
|
|
Ok(contents) => match toml::from_str::<TomlValue>(&contents) {
|
|
Ok(value) => Ok(Some(value)),
|
|
Err(err) => {
|
|
tracing::error!("Failed to parse {}: {err}", path.as_path().display());
|
|
let config_error = config_error_from_toml(path.as_path(), &contents, err.clone());
|
|
Err(io_error_from_config_error(
|
|
io::ErrorKind::InvalidData,
|
|
config_error,
|
|
Some(err),
|
|
))
|
|
}
|
|
},
|
|
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
|
if log_missing_as_info {
|
|
tracing::info!("{} not found, using defaults", path.as_path().display());
|
|
} else {
|
|
tracing::debug!("{} not found", path.as_path().display());
|
|
}
|
|
Ok(None)
|
|
}
|
|
Err(err) => {
|
|
tracing::error!("Failed to read {}: {err}", path.as_path().display());
|
|
Err(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Return the default managed config path.
|
|
pub(super) fn managed_config_default_path(codex_home: &Path) -> PathBuf {
|
|
#[cfg(unix)]
|
|
{
|
|
let _ = codex_home;
|
|
PathBuf::from(CODEX_MANAGED_CONFIG_SYSTEM_PATH)
|
|
}
|
|
|
|
#[cfg(not(unix))]
|
|
{
|
|
codex_home.join("managed_config.toml")
|
|
}
|
|
}
|