mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +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:
@@ -63,6 +63,7 @@ windows-sys = { version = "0.52", features = [
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
codex-exec-server-test-support = { workspace = true }
|
||||
codex-test-binary-support = { workspace = true }
|
||||
ctor = { workspace = true }
|
||||
http = { workspace = true }
|
||||
|
||||
@@ -5,6 +5,8 @@ use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::RwLock;
|
||||
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use futures::FutureExt;
|
||||
@@ -21,6 +23,8 @@ use crate::client::LazyRemoteExecServerClient;
|
||||
use crate::client::http_client::ReqwestHttpClient;
|
||||
use crate::client_api::DEFAULT_REMOTE_EXEC_SERVER_CONNECT_TIMEOUT;
|
||||
use crate::client_api::ExecServerTransportParams;
|
||||
use crate::environment_bootstrap::PreparedEnvironmentManager;
|
||||
use crate::environment_bootstrap::PreparedEnvironmentSource;
|
||||
use crate::environment_provider::DefaultEnvironmentProvider;
|
||||
use crate::environment_provider::EnvironmentDefault;
|
||||
use crate::environment_provider::EnvironmentProvider;
|
||||
@@ -76,6 +80,7 @@ pub struct EnvironmentManager {
|
||||
pub(super) environments: RwLock<HashMap<String, Arc<Environment>>>,
|
||||
local_environment: Option<Arc<Environment>>,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
}
|
||||
|
||||
/// Information supplied by the environment owner when a deferred environment is ready.
|
||||
@@ -134,16 +139,18 @@ impl EnvironmentManager {
|
||||
)])),
|
||||
local_environment: Some(Arc::new(Environment::default_for_tests())),
|
||||
local_runtime_paths: None,
|
||||
http_client_factory: HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a manager with no configured execution environments.
|
||||
pub fn without_environments() -> Self {
|
||||
pub fn without_environments(http_client_factory: HttpClientFactory) -> Self {
|
||||
Self {
|
||||
default_environment: None,
|
||||
environments: RwLock::new(HashMap::new()),
|
||||
local_environment: None,
|
||||
local_runtime_paths: None,
|
||||
http_client_factory,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,59 +158,78 @@ impl EnvironmentManager {
|
||||
pub async fn create_for_tests(
|
||||
exec_server_url: Option<String>,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
) -> Self {
|
||||
Self::from_default_provider_url(exec_server_url, local_runtime_paths).await
|
||||
}
|
||||
|
||||
/// Builds a manager from `CODEX_HOME` and local runtime paths used when
|
||||
/// creating local filesystem helpers.
|
||||
///
|
||||
/// If `CODEX_HOME/environments.toml` is present, it defines the configured
|
||||
/// environments. Otherwise this preserves the legacy
|
||||
/// `CODEX_EXEC_SERVER_URL` behavior.
|
||||
pub async fn from_codex_home(
|
||||
codex_home: impl AsRef<std::path::Path>,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
if let Some(config) = noise_environment_config_from_env()? {
|
||||
return Self::from_noise_environment_config(config, local_runtime_paths);
|
||||
}
|
||||
let provider = environment_provider_from_codex_home(codex_home.as_ref())?;
|
||||
Self::from_snapshot(provider.snapshot().await?, local_runtime_paths)
|
||||
}
|
||||
|
||||
/// Builds a manager from the legacy environment-variable provider without
|
||||
/// reading user config files from `CODEX_HOME`.
|
||||
pub async fn from_env(
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
if let Some(config) = noise_environment_config_from_env()? {
|
||||
return Self::from_noise_environment_config(config, local_runtime_paths);
|
||||
}
|
||||
let provider = DefaultEnvironmentProvider::from_env();
|
||||
Self::from_snapshot(provider.snapshot().await?, local_runtime_paths)
|
||||
}
|
||||
|
||||
async fn from_default_provider_url(
|
||||
exec_server_url: Option<String>,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
) -> Self {
|
||||
let provider = DefaultEnvironmentProvider::new(exec_server_url);
|
||||
match Self::from_snapshot(provider.snapshot_inner(), local_runtime_paths) {
|
||||
match Self::from_snapshot(
|
||||
provider.snapshot_inner(),
|
||||
local_runtime_paths,
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
) {
|
||||
Ok(manager) => manager,
|
||||
Err(err) => panic!("default provider should create valid environments: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_noise_environment_config(
|
||||
/// Discovers configured environments without starting remote connections.
|
||||
///
|
||||
/// If `CODEX_HOME/environments.toml` is present, it defines the configured
|
||||
/// environments. Otherwise this preserves the legacy
|
||||
/// `CODEX_EXEC_SERVER_URL` behavior.
|
||||
pub async fn prepare_from_codex_home(
|
||||
codex_home: impl AsRef<std::path::Path>,
|
||||
) -> Result<PreparedEnvironmentManager, ExecServerError> {
|
||||
let source = if let Some(config) = noise_environment_config_from_env()? {
|
||||
PreparedEnvironmentSource::Noise(config)
|
||||
} else {
|
||||
let provider = environment_provider_from_codex_home(codex_home.as_ref())?;
|
||||
PreparedEnvironmentSource::Snapshot(provider.snapshot().await?)
|
||||
};
|
||||
Ok(PreparedEnvironmentManager { source })
|
||||
}
|
||||
|
||||
/// Builds a manager from `CODEX_HOME` with an explicit outbound HTTP policy.
|
||||
pub async fn from_codex_home(
|
||||
codex_home: impl AsRef<std::path::Path>,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
Self::prepare_from_codex_home(codex_home)
|
||||
.await?
|
||||
.build(local_runtime_paths, http_client_factory)
|
||||
}
|
||||
|
||||
/// Discovers environment-variable environments without starting connections.
|
||||
pub async fn prepare_from_env() -> Result<PreparedEnvironmentManager, ExecServerError> {
|
||||
let source = if let Some(config) = noise_environment_config_from_env()? {
|
||||
PreparedEnvironmentSource::Noise(config)
|
||||
} else {
|
||||
let provider = DefaultEnvironmentProvider::from_env();
|
||||
PreparedEnvironmentSource::Snapshot(provider.snapshot().await?)
|
||||
};
|
||||
Ok(PreparedEnvironmentManager { source })
|
||||
}
|
||||
|
||||
/// Builds a manager from environment variables with an explicit outbound HTTP policy.
|
||||
pub async fn from_env(
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
Self::prepare_from_env()
|
||||
.await?
|
||||
.build(local_runtime_paths, http_client_factory)
|
||||
}
|
||||
|
||||
pub(crate) fn from_noise_environment_config(
|
||||
config: NoiseRendezvousEnvironmentConfig,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
let manager = Self {
|
||||
default_environment: Some(REMOTE_ENVIRONMENT_ID.to_string()),
|
||||
environments: RwLock::new(HashMap::new()),
|
||||
local_environment: None,
|
||||
local_runtime_paths,
|
||||
http_client_factory,
|
||||
};
|
||||
manager.upsert_noise_environment(
|
||||
REMOTE_ENVIRONMENT_ID.to_string(),
|
||||
@@ -220,15 +246,20 @@ impl EnvironmentManager {
|
||||
) -> Self {
|
||||
let mut snapshot = DefaultEnvironmentProvider::new(exec_server_url).snapshot_inner();
|
||||
snapshot.include_local = true;
|
||||
match Self::from_snapshot(snapshot, Some(local_runtime_paths)) {
|
||||
match Self::from_snapshot(
|
||||
snapshot,
|
||||
Some(local_runtime_paths),
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
) {
|
||||
Ok(manager) => manager,
|
||||
Err(err) => panic!("test provider with local should create valid environments: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_snapshot(
|
||||
pub(crate) fn from_snapshot(
|
||||
snapshot: EnvironmentProviderSnapshot,
|
||||
local_runtime_paths: Option<ExecServerRuntimePaths>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> Result<Self, ExecServerError> {
|
||||
let EnvironmentProviderSnapshot {
|
||||
environments,
|
||||
@@ -292,6 +323,7 @@ impl EnvironmentManager {
|
||||
environments: RwLock::new(environment_map),
|
||||
local_environment,
|
||||
local_runtime_paths,
|
||||
http_client_factory,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -341,6 +373,11 @@ impl EnvironmentManager {
|
||||
.cloned()
|
||||
}
|
||||
|
||||
/// Returns the outbound HTTP policy carried by this manager.
|
||||
pub fn http_client_factory(&self) -> &HttpClientFactory {
|
||||
&self.http_client_factory
|
||||
}
|
||||
|
||||
/// Returns the current status of one named environment when it is configured.
|
||||
pub async fn get_environment_status(
|
||||
&self,
|
||||
@@ -836,11 +873,17 @@ mod tests {
|
||||
use crate::client_api::StdioExecServerCommand;
|
||||
use crate::environment_provider::EnvironmentDefault;
|
||||
use crate::environment_provider::EnvironmentProviderSnapshot;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::time::timeout;
|
||||
|
||||
fn legacy_http_client_factory() -> HttpClientFactory {
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault)
|
||||
}
|
||||
|
||||
fn test_runtime_paths() -> ExecServerRuntimePaths {
|
||||
ExecServerRuntimePaths::new(
|
||||
std::env::current_exe().expect("current exe"),
|
||||
@@ -878,7 +921,9 @@ mod tests {
|
||||
.expect("noise environment configuration");
|
||||
|
||||
let manager = EnvironmentManager::from_noise_environment_config(
|
||||
config, /*local_runtime_paths*/ None,
|
||||
config,
|
||||
/*local_runtime_paths*/ None,
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("build environment manager");
|
||||
|
||||
@@ -929,13 +974,19 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn disabled_environment_manager_has_no_default_or_local_environment() {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = EnvironmentManager::without_environments(HttpClientFactory::new(
|
||||
OutboundProxyPolicy::RespectSystemProxy,
|
||||
));
|
||||
|
||||
assert!(manager.default_environment().is_none());
|
||||
assert_eq!(manager.default_environment_id(), None);
|
||||
assert_local_environment_unavailable(&manager);
|
||||
assert!(manager.get_environment(LOCAL_ENVIRONMENT_ID).is_none());
|
||||
assert!(manager.get_environment(REMOTE_ENVIRONMENT_ID).is_none());
|
||||
assert_eq!(
|
||||
manager.http_client_factory().outbound_proxy_policy(),
|
||||
OutboundProxyPolicy::RespectSystemProxy
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -987,8 +1038,12 @@ mod tests {
|
||||
default: EnvironmentDefault::EnvironmentId(REMOTE_ENVIRONMENT_ID.to_string()),
|
||||
include_local: false,
|
||||
};
|
||||
let manager = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect("environment manager");
|
||||
let manager = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("environment manager");
|
||||
|
||||
assert_eq!(
|
||||
manager.default_environment_id(),
|
||||
@@ -1011,8 +1066,12 @@ mod tests {
|
||||
default: EnvironmentDefault::Disabled,
|
||||
include_local: false,
|
||||
};
|
||||
let err = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect_err("empty id should fail");
|
||||
let err = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect_err("empty id should fail");
|
||||
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
@@ -1030,8 +1089,12 @@ mod tests {
|
||||
default: EnvironmentDefault::Disabled,
|
||||
include_local: false,
|
||||
};
|
||||
let err = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect_err("local id should fail");
|
||||
let err = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect_err("local id should fail");
|
||||
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
@@ -1050,8 +1113,12 @@ mod tests {
|
||||
default: EnvironmentDefault::EnvironmentId("devbox".to_string()),
|
||||
include_local: true,
|
||||
};
|
||||
let manager = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect("manager");
|
||||
let manager = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("manager");
|
||||
|
||||
assert_eq!(manager.default_environment_id(), Some("devbox"));
|
||||
assert_eq!(
|
||||
@@ -1072,8 +1139,12 @@ mod tests {
|
||||
default: EnvironmentDefault::Disabled,
|
||||
include_local: true,
|
||||
};
|
||||
let manager = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect("manager");
|
||||
let manager = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("manager");
|
||||
|
||||
assert_eq!(manager.default_environment_id(), None);
|
||||
assert!(manager.default_environment().is_none());
|
||||
@@ -1096,8 +1167,12 @@ mod tests {
|
||||
default: EnvironmentDefault::EnvironmentId("missing".to_string()),
|
||||
include_local: true,
|
||||
};
|
||||
let err = EnvironmentManager::from_snapshot(snapshot, Some(test_runtime_paths()))
|
||||
.expect_err("unknown default should fail");
|
||||
let err = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
Some(test_runtime_paths()),
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect_err("unknown default should fail");
|
||||
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
@@ -1178,9 +1253,12 @@ mod tests {
|
||||
};
|
||||
snapshot.include_local = false;
|
||||
snapshot.default = EnvironmentDefault::Disabled;
|
||||
let manager =
|
||||
EnvironmentManager::from_snapshot(snapshot, /*local_runtime_paths*/ None)
|
||||
.expect("environment manager");
|
||||
let manager = EnvironmentManager::from_snapshot(
|
||||
snapshot,
|
||||
/*local_runtime_paths*/ None,
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("environment manager");
|
||||
|
||||
assert!(manager.default_environment().is_none());
|
||||
assert_eq!(manager.default_environment_id(), None);
|
||||
@@ -1197,7 +1275,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn environment_manager_upserts_named_remote_environment() {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = EnvironmentManager::without_environments(legacy_http_client_factory());
|
||||
|
||||
manager
|
||||
.upsert_environment(
|
||||
@@ -1231,7 +1309,7 @@ mod tests {
|
||||
let listener = TcpListener::bind("127.0.0.1:0")
|
||||
.await
|
||||
.expect("bind websocket listener");
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = EnvironmentManager::without_environments(legacy_http_client_factory());
|
||||
|
||||
manager
|
||||
.upsert_environment(
|
||||
@@ -1290,6 +1368,7 @@ mod tests {
|
||||
include_local: false,
|
||||
},
|
||||
/*local_runtime_paths*/ None,
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("environment manager");
|
||||
let environment = manager.get_environment("stdio").expect("stdio environment");
|
||||
@@ -1323,6 +1402,7 @@ mod tests {
|
||||
include_local: false,
|
||||
},
|
||||
/*local_runtime_paths*/ None,
|
||||
legacy_http_client_factory(),
|
||||
)
|
||||
.expect("environment manager");
|
||||
let environment = manager.get_environment("stdio").expect("stdio environment");
|
||||
@@ -1373,7 +1453,7 @@ mod tests {
|
||||
let second_listener = TcpListener::bind("127.0.0.1:0")
|
||||
.await
|
||||
.expect("bind second websocket listener");
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = EnvironmentManager::without_environments(legacy_http_client_factory());
|
||||
manager
|
||||
.upsert_environment(
|
||||
"executor-a".to_string(),
|
||||
@@ -1421,7 +1501,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn environment_manager_rejects_empty_remote_environment_url() {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = EnvironmentManager::without_environments(legacy_http_client_factory());
|
||||
|
||||
let err = manager
|
||||
.upsert_environment(
|
||||
|
||||
@@ -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;
|
||||
@@ -0,0 +1,87 @@
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::PreparedEnvironmentManager;
|
||||
use super::PreparedEnvironmentSource;
|
||||
use crate::DefaultEnvironmentProvider;
|
||||
use crate::Environment;
|
||||
use crate::EnvironmentConnectionState;
|
||||
use crate::ExecServerRuntimePaths;
|
||||
use crate::LOCAL_ENVIRONMENT_ID;
|
||||
use crate::REMOTE_ENVIRONMENT_ID;
|
||||
use crate::environment_provider::EnvironmentDefault;
|
||||
use crate::environment_provider::EnvironmentProviderSnapshot;
|
||||
|
||||
#[test]
|
||||
fn prepared_remote_environment_is_detected_without_starting_a_connection() {
|
||||
let environment = Environment::create_for_tests(Some("ws://127.0.0.1:8765".to_string()))
|
||||
.expect("remote environment");
|
||||
let connection_state = environment
|
||||
.subscribe_connection_state()
|
||||
.expect("remote connection state");
|
||||
let prepared = PreparedEnvironmentManager {
|
||||
source: PreparedEnvironmentSource::Snapshot(EnvironmentProviderSnapshot {
|
||||
environments: vec![(REMOTE_ENVIRONMENT_ID.to_string(), environment)],
|
||||
default: EnvironmentDefault::EnvironmentId(REMOTE_ENVIRONMENT_ID.to_string()),
|
||||
include_local: false,
|
||||
}),
|
||||
};
|
||||
|
||||
assert!(prepared.default_environment_is_remote());
|
||||
assert_eq!(
|
||||
*connection_state.borrow(),
|
||||
EnvironmentConnectionState::Disconnected
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepared_local_and_disabled_environments_are_not_remote() {
|
||||
let local = PreparedEnvironmentManager {
|
||||
source: PreparedEnvironmentSource::Snapshot(EnvironmentProviderSnapshot {
|
||||
environments: Vec::new(),
|
||||
default: EnvironmentDefault::EnvironmentId(LOCAL_ENVIRONMENT_ID.to_string()),
|
||||
include_local: true,
|
||||
}),
|
||||
};
|
||||
let disabled = PreparedEnvironmentManager {
|
||||
source: PreparedEnvironmentSource::Snapshot(EnvironmentProviderSnapshot {
|
||||
environments: Vec::new(),
|
||||
default: EnvironmentDefault::Disabled,
|
||||
include_local: false,
|
||||
}),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
[
|
||||
local.default_environment_is_remote(),
|
||||
disabled.default_environment_is_remote()
|
||||
],
|
||||
[false, false]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prepared_environment_manager_builds_with_the_explicit_http_policy() {
|
||||
let prepared = PreparedEnvironmentManager {
|
||||
source: PreparedEnvironmentSource::Snapshot(
|
||||
DefaultEnvironmentProvider::new(/*exec_server_url*/ None).snapshot_inner(),
|
||||
),
|
||||
};
|
||||
let runtime_paths = ExecServerRuntimePaths::new(
|
||||
std::env::current_exe().expect("current exe"),
|
||||
/*codex_linux_sandbox_exe*/ None,
|
||||
)
|
||||
.expect("runtime paths");
|
||||
let manager = prepared
|
||||
.build(
|
||||
Some(runtime_paths),
|
||||
HttpClientFactory::new(OutboundProxyPolicy::RespectSystemProxy),
|
||||
)
|
||||
.expect("environment manager");
|
||||
|
||||
assert_eq!(
|
||||
manager.http_client_factory().outbound_proxy_policy(),
|
||||
OutboundProxyPolicy::RespectSystemProxy
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ mod client_api;
|
||||
mod client_transport;
|
||||
mod connection;
|
||||
mod environment;
|
||||
mod environment_bootstrap;
|
||||
mod environment_provider;
|
||||
mod environment_registry;
|
||||
mod environment_toml;
|
||||
@@ -85,6 +86,7 @@ pub use environment::EnvironmentReadyInfo;
|
||||
pub use environment::LOCAL_ENVIRONMENT_ID;
|
||||
pub use environment::MAX_SELECTED_CAPABILITY_ROOTS;
|
||||
pub use environment::REMOTE_ENVIRONMENT_ID;
|
||||
pub use environment_bootstrap::PreparedEnvironmentManager;
|
||||
pub use environment_provider::DefaultEnvironmentProvider;
|
||||
pub use environment_provider::EnvironmentProvider;
|
||||
pub use environment_provider::EnvironmentProviderFuture;
|
||||
|
||||
@@ -2,12 +2,12 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
use codex_exec_server::EnvironmentReadyInfo;
|
||||
use codex_exec_server::ExecServerError;
|
||||
use codex_exec_server::NoiseChannelPublicKey;
|
||||
use codex_exec_server::NoiseRendezvousConnectBundle;
|
||||
use codex_exec_server::NoiseRendezvousConnectProvider;
|
||||
use codex_exec_server_test_support::environment_manager_without_environments;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -56,7 +56,7 @@ fn ready_info(root_id: &str, environment_id: &str) -> anyhow::Result<Environment
|
||||
|
||||
#[tokio::test]
|
||||
async fn deferred_environment_waits_before_connecting() -> anyhow::Result<()> {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let provider = Arc::new(FailingNoiseConnectProvider::default());
|
||||
let registration =
|
||||
manager.register_deferred_noise_environment("tools".to_string(), provider.clone())?;
|
||||
@@ -85,7 +85,7 @@ async fn deferred_environment_waits_before_connecting() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn failure_and_dropped_registration_are_terminal() -> anyhow::Result<()> {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let failed_provider = Arc::new(FailingNoiseConnectProvider::default());
|
||||
let failed = manager
|
||||
.register_deferred_noise_environment("failed".to_string(), failed_provider.clone())?;
|
||||
@@ -118,7 +118,7 @@ async fn failure_and_dropped_registration_are_terminal() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalid_ready_info_is_terminal() -> anyhow::Result<()> {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let provider = Arc::new(FailingNoiseConnectProvider::default());
|
||||
let registration =
|
||||
manager.register_deferred_noise_environment("tools".to_string(), provider.clone())?;
|
||||
@@ -141,7 +141,7 @@ async fn invalid_ready_info_is_terminal() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn late_completion_is_isolated_from_replacement() -> anyhow::Result<()> {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let old_provider = Arc::new(FailingNoiseConnectProvider::default());
|
||||
let old_registration =
|
||||
manager.register_deferred_noise_environment("tools".to_string(), old_provider.clone())?;
|
||||
@@ -183,7 +183,7 @@ async fn late_completion_is_isolated_from_replacement() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn eager_noise_environment_connects_without_registration() -> anyhow::Result<()> {
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let provider = Arc::new(FailingNoiseConnectProvider::default());
|
||||
manager.upsert_noise_environment("tools".to_string(), provider.clone())?;
|
||||
let environment = manager.get_environment("tools").expect("environment");
|
||||
|
||||
@@ -16,7 +16,6 @@ use base64::Engine as _;
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use codex_api::AuthProvider;
|
||||
use codex_exec_server::EnvironmentConnectionState;
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
use codex_exec_server::EnvironmentReadyInfo;
|
||||
use codex_exec_server::ExecParams;
|
||||
use codex_exec_server::ExecResponse;
|
||||
@@ -31,6 +30,7 @@ use codex_exec_server::NoiseRendezvousConnectBundle;
|
||||
use codex_exec_server::NoiseRendezvousConnectProvider;
|
||||
use codex_exec_server::ProcessId;
|
||||
use codex_exec_server::RemoteEnvironmentConfig;
|
||||
use codex_exec_server_test_support::environment_manager_without_environments;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -156,7 +156,7 @@ async fn deferred_noise_environment_connects_and_reconnects_with_fresh_bundle()
|
||||
executor_public_key: registered_executor_public_key(®istry).await?,
|
||||
calls: AtomicUsize::new(0),
|
||||
});
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let registration = manager
|
||||
.register_deferred_noise_environment(ENVIRONMENT_ID.to_string(), provider.clone())?;
|
||||
let environment = manager
|
||||
|
||||
@@ -5,7 +5,7 @@ mod common;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
use codex_exec_server_test_support::environment_manager_without_environments;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -15,7 +15,7 @@ use pretty_assertions::assert_eq;
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn selected_capability_roots_use_captured_handle_after_replacement() -> anyhow::Result<()> {
|
||||
let mut executor = exec_server().await?;
|
||||
let manager = EnvironmentManager::without_environments();
|
||||
let manager = environment_manager_without_environments();
|
||||
let selected_root = SelectedCapabilityRoot {
|
||||
id: "demo@1".to_string(),
|
||||
location: CapabilityRootLocation::Environment {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
load("//:defs.bzl", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "support",
|
||||
crate_name = "codex_exec_server_test_support",
|
||||
crate_srcs = glob(["*.rs"]),
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "codex-exec-server-test-support"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
test = false
|
||||
doctest = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
codex-exec-server = { workspace = true }
|
||||
codex-http-client = { workspace = true }
|
||||
@@ -0,0 +1,10 @@
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
|
||||
/// Builds a manager without environments using the legacy outbound HTTP policy.
|
||||
pub fn environment_manager_without_environments() -> EnvironmentManager {
|
||||
EnvironmentManager::without_environments(HttpClientFactory::new(
|
||||
OutboundProxyPolicy::ReqwestDefault,
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user