mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Support sandboxed exec-server test environments (#40717)
## What changed - Add a `TestCodexBuilder` entry point that accepts an explicit `TestEnv`. - Teach the exec-server test fixture to dispatch filesystem-helper invocations. - Allow the fixture to receive the Linux sandbox executable through `CODEX_TEST_LINUX_SANDBOX_EXE` and run the server on a multithreaded Tokio runtime. GitOrigin-RevId: cb9c27e9db0363d4022a084bc186ccc749e25a95
This commit is contained in:
@@ -493,13 +493,22 @@ impl TestCodexBuilder {
|
||||
pub async fn build_with_auto_env(
|
||||
&mut self,
|
||||
server: &wiremock::MockServer,
|
||||
) -> anyhow::Result<TestCodex> {
|
||||
let test_env = test_env().await?;
|
||||
self.build_with_environment(server, test_env).await
|
||||
}
|
||||
|
||||
/// Builds a test runtime using an explicitly selected execution environment.
|
||||
pub async fn build_with_environment(
|
||||
&mut self,
|
||||
server: &wiremock::MockServer,
|
||||
test_env: TestEnv,
|
||||
) -> anyhow::Result<TestCodex> {
|
||||
let home = match self.home.clone() {
|
||||
Some(home) => home,
|
||||
None => Arc::new(TempDir::new()?),
|
||||
};
|
||||
let base_url = format!("{}/v1", server.uri());
|
||||
let test_env = test_env().await?;
|
||||
Box::pin(self.build_with_home_and_base_url(
|
||||
base_url, home, /*resume_from*/ None, test_env,
|
||||
/*include_local_environment*/ false,
|
||||
|
||||
@@ -7,31 +7,32 @@
|
||||
use codex_exec_server::ExecServerRuntimePaths;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
#[cfg(unix)]
|
||||
use std::ffi::OsStr;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
const CODEX_LINUX_SANDBOX_EXE_ENV_VAR: &str = "CODEX_TEST_LINUX_SANDBOX_EXE";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut args = std::env::args_os();
|
||||
let _ = args.next();
|
||||
let argv1 = args.next();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let mut args = std::env::args_os();
|
||||
let _ = args.next();
|
||||
if args.next().as_deref()
|
||||
== Some(OsStr::new(
|
||||
codex_exec_server::CODEX_ARG0_EXEC_HELPER_ARG1,
|
||||
))
|
||||
{
|
||||
codex_exec_server::run_arg0_exec_helper_main();
|
||||
}
|
||||
if argv1.as_deref() == Some(OsStr::new(codex_exec_server::CODEX_ARG0_EXEC_HELPER_ARG1)) {
|
||||
codex_exec_server::run_arg0_exec_helper_main();
|
||||
}
|
||||
if argv1.as_deref() == Some(OsStr::new(codex_exec_server::CODEX_FS_HELPER_ARG1)) {
|
||||
codex_exec_server::run_fs_helper_main();
|
||||
}
|
||||
|
||||
let current_exe = std::env::current_exe()?;
|
||||
let runtime_paths =
|
||||
ExecServerRuntimePaths::new(current_exe, /*codex_linux_sandbox_exe*/ None)?;
|
||||
codex_exec_server::run_main(
|
||||
"ws://127.0.0.1:0",
|
||||
runtime_paths,
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
)
|
||||
.await
|
||||
let codex_linux_sandbox_exe =
|
||||
std::env::var_os(CODEX_LINUX_SANDBOX_EXE_ENV_VAR).map(std::path::PathBuf::from);
|
||||
let runtime_paths = ExecServerRuntimePaths::new(current_exe, codex_linux_sandbox_exe)?;
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()?
|
||||
.block_on(codex_exec_server::run_main(
|
||||
"ws://127.0.0.1:0",
|
||||
runtime_paths,
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user