mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
Initialize execution environments with the final HTTP policy (#34995)
## Why The TUI must inspect the default execution environment before loading its final configuration. Initializing the environment manager at that point can give startup services the bootstrap HTTP policy instead of the effective policy after managed requirements are applied. ## What changed - Split environment discovery from manager construction so callers can inspect the default environment without starting remote connections. - Build the environment manager after final configuration loading and pass its resolved `HttpClientFactory` through all construction paths. - Add shared test support for managers that use the legacy default HTTP policy. ## Testing - Cover connection-free environment discovery and explicit HTTP policy propagation. - Verify TUI startup services use the final managed `respect_system_proxy` value. GitOrigin-RevId: 928fa31e6b4bcfbe1a121cade2f351427fdfa0f4
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
use codex_http_client::HttpClientFactory;
|
||||
|
||||
use crate::EnvironmentManager;
|
||||
use crate::ExecServerError;
|
||||
use crate::ExecServerRuntimePaths;
|
||||
use crate::environment_provider::EnvironmentDefault;
|
||||
use crate::environment_provider::EnvironmentProviderSnapshot;
|
||||
use crate::remote::NoiseRendezvousEnvironmentConfig;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum PreparedEnvironmentSource {
|
||||
Noise(NoiseRendezvousEnvironmentConfig),
|
||||
Snapshot(EnvironmentProviderSnapshot),
|
||||
}
|
||||
|
||||
/// Holds discovered execution environments before their HTTP policy is resolved.
|
||||
///
|
||||
/// Preparing environments does not start remote connections. Callers can inspect
|
||||
/// the default environment to choose config-loading behavior and then build the
|
||||
/// manager with the effective outbound HTTP policy.
|
||||
#[derive(Debug)]
|
||||
pub struct PreparedEnvironmentManager {
|
||||
pub(crate) source: PreparedEnvironmentSource,
|
||||
}
|
||||
|
||||
impl PreparedEnvironmentManager {
|
||||
/// Returns whether the discovered default environment is remote.
|
||||
pub fn default_environment_is_remote(&self) -> bool {
|
||||
match &self.source {
|
||||
PreparedEnvironmentSource::Noise(_) => true,
|
||||
PreparedEnvironmentSource::Snapshot(snapshot) => match &snapshot.default {
|
||||
EnvironmentDefault::Disabled => false,
|
||||
EnvironmentDefault::EnvironmentId(default_id) => snapshot
|
||||
.environments
|
||||
.iter()
|
||||
.find(|(environment_id, _)| environment_id == default_id)
|
||||
.is_some_and(|(_, environment)| environment.is_remote()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the manager and starts remote connections using the supplied policy.
|
||||
pub fn build(
|
||||
self,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> Result<EnvironmentManager, ExecServerError> {
|
||||
match self.source {
|
||||
PreparedEnvironmentSource::Noise(config) => {
|
||||
EnvironmentManager::from_noise_environment_config(
|
||||
config,
|
||||
local_runtime_paths,
|
||||
http_client_factory,
|
||||
)
|
||||
}
|
||||
PreparedEnvironmentSource::Snapshot(snapshot) => EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
local_runtime_paths,
|
||||
http_client_factory,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "environment_bootstrap_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user