mirror of
https://github.com/openai/codex.git
synced 2026-04-29 10:53:24 +03:00
`codex-core` had accumulated config loading, requirements parsing, constraint logic, and config-layer state handling in a single crate. This change extracts that subsystem into `codex-config` to reduce `codex-core` rebuild/test surface area and isolate future config work. ## What Changed ### Added `codex-config` - Added new workspace crate `codex-rs/config` (`codex-config`). - Added workspace/build wiring in: - `codex-rs/Cargo.toml` - `codex-rs/config/Cargo.toml` - `codex-rs/config/BUILD.bazel` - Updated lockfiles (`codex-rs/Cargo.lock`, `MODULE.bazel.lock`). - Added `codex-core` -> `codex-config` dependency in `codex-rs/core/Cargo.toml`. ### Moved config internals from `core` into `config` Moved modules to `codex-rs/config/src/`: - `core/src/config/constraint.rs` -> `config/src/constraint.rs` - `core/src/config_loader/cloud_requirements.rs` -> `config/src/cloud_requirements.rs` - `core/src/config_loader/config_requirements.rs` -> `config/src/config_requirements.rs` - `core/src/config_loader/fingerprint.rs` -> `config/src/fingerprint.rs` - `core/src/config_loader/merge.rs` -> `config/src/merge.rs` - `core/src/config_loader/overrides.rs` -> `config/src/overrides.rs` - `core/src/config_loader/requirements_exec_policy.rs` -> `config/src/requirements_exec_policy.rs` - `core/src/config_loader/state.rs` -> `config/src/state.rs` `codex-config` now re-exports this surface from `config/src/lib.rs` at the crate top level. ### Updated `core` to consume/re-export `codex-config` - `core/src/config_loader/mod.rs` now imports/re-exports config-loader types/functions from top-level `codex_config::*`. - Local moved modules were removed from `core/src/config_loader/`. - `core/src/config/mod.rs` now re-exports constraint types from `codex_config`.
63 lines
1.7 KiB
Rust
63 lines
1.7 KiB
Rust
use crate::config_requirements::ConfigRequirementsToml;
|
|
use futures::future::BoxFuture;
|
|
use futures::future::FutureExt;
|
|
use futures::future::Shared;
|
|
use std::fmt;
|
|
use std::future::Future;
|
|
|
|
#[derive(Clone)]
|
|
pub struct CloudRequirementsLoader {
|
|
// TODO(gt): This should return a Result once we can fail-closed.
|
|
fut: Shared<BoxFuture<'static, Option<ConfigRequirementsToml>>>,
|
|
}
|
|
|
|
impl CloudRequirementsLoader {
|
|
pub fn new<F>(fut: F) -> Self
|
|
where
|
|
F: Future<Output = Option<ConfigRequirementsToml>> + Send + 'static,
|
|
{
|
|
Self {
|
|
fut: fut.boxed().shared(),
|
|
}
|
|
}
|
|
|
|
pub async fn get(&self) -> Option<ConfigRequirementsToml> {
|
|
self.fut.clone().await
|
|
}
|
|
}
|
|
|
|
impl fmt::Debug for CloudRequirementsLoader {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.debug_struct("CloudRequirementsLoader").finish()
|
|
}
|
|
}
|
|
|
|
impl Default for CloudRequirementsLoader {
|
|
fn default() -> Self {
|
|
Self::new(async { None })
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
use std::sync::Arc;
|
|
use std::sync::atomic::AtomicUsize;
|
|
use std::sync::atomic::Ordering;
|
|
|
|
#[tokio::test]
|
|
async fn shared_future_runs_once() {
|
|
let counter = Arc::new(AtomicUsize::new(0));
|
|
let counter_clone = Arc::clone(&counter);
|
|
let loader = CloudRequirementsLoader::new(async move {
|
|
counter_clone.fetch_add(1, Ordering::SeqCst);
|
|
Some(ConfigRequirementsToml::default())
|
|
});
|
|
|
|
let (first, second) = tokio::join!(loader.get(), loader.get());
|
|
assert_eq!(first, second);
|
|
assert_eq!(counter.load(Ordering::SeqCst), 1);
|
|
}
|
|
}
|