mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Cache remote Bash environment exports
This commit is contained in:
@@ -7,6 +7,8 @@ use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_exec_server::ExecBackend;
|
||||
#[cfg(unix)]
|
||||
use codex_exec_server::ExecEnvPolicy;
|
||||
use codex_exec_server::ExecOutputStream;
|
||||
use codex_exec_server::ExecParams;
|
||||
use codex_exec_server::ExecProcess;
|
||||
@@ -16,6 +18,8 @@ use codex_exec_server::ProcessSignal;
|
||||
use codex_exec_server::ReadResponse;
|
||||
use codex_exec_server::StartedExecProcess;
|
||||
use codex_exec_server::WriteStatus;
|
||||
#[cfg(unix)]
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
@@ -96,6 +100,68 @@ async fn assert_exec_process_starts_and_exits(use_remote: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
async fn assert_bash_env_exports_are_cached(use_remote: bool) -> Result<()> {
|
||||
let context = create_process_context(use_remote).await?;
|
||||
let temp = tempfile::tempdir()?;
|
||||
let bash_env = temp.path().join("bash_env.sh");
|
||||
let counter = temp.path().join("counter");
|
||||
std::fs::write(
|
||||
&bash_env,
|
||||
"printf x >> \"$COUNTER_FILE\"\nexport CACHED_VALUE=ready\nexport PATH=\"$PATH:/from-bash-env\"\n",
|
||||
)?;
|
||||
let cwd = PathUri::from_host_native_path(temp.path())?;
|
||||
|
||||
for index in 0..2 {
|
||||
let process = context
|
||||
.backend
|
||||
.start(ExecParams {
|
||||
process_id: format!("bash-env-cache-{index}").into(),
|
||||
argv: vec![
|
||||
"/bin/bash".to_string(),
|
||||
"-c".to_string(),
|
||||
"printf '%s|%s' \"$CACHED_VALUE\" \"$PATH\"".to_string(),
|
||||
],
|
||||
cwd: cwd.clone(),
|
||||
env_policy: Some(ExecEnvPolicy {
|
||||
inherit: ShellEnvironmentPolicyInherit::None,
|
||||
ignore_default_excludes: true,
|
||||
exclude: Vec::new(),
|
||||
r#set: HashMap::new(),
|
||||
include_only: Vec::new(),
|
||||
bash_env_cache_scope: Some(cwd.clone()),
|
||||
}),
|
||||
env: HashMap::from([
|
||||
(
|
||||
"BASH_ENV".to_string(),
|
||||
bash_env.to_string_lossy().into_owned(),
|
||||
),
|
||||
(
|
||||
"COUNTER_FILE".to_string(),
|
||||
counter.to_string_lossy().into_owned(),
|
||||
),
|
||||
("PATH".to_string(), "/usr/bin:/bin".to_string()),
|
||||
]),
|
||||
tty: false,
|
||||
pipe_stdin: false,
|
||||
arg0: None,
|
||||
sandbox: None,
|
||||
enforce_managed_network: false,
|
||||
managed_network: None,
|
||||
})
|
||||
.await?;
|
||||
let wake = process.process.subscribe_wake();
|
||||
let (output, exit_code, closed) =
|
||||
collect_process_output_from_reads(process.process, wake).await?;
|
||||
assert_eq!(output, "ready|/usr/bin:/bin:/from-bash-env");
|
||||
assert_eq!(exit_code, Some(0));
|
||||
assert!(closed);
|
||||
}
|
||||
|
||||
assert_eq!(std::fs::read_to_string(counter)?, "x");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn read_process_until_change(
|
||||
session: Arc<dyn ExecProcess>,
|
||||
wake_rx: &mut watch::Receiver<u64>,
|
||||
@@ -928,3 +994,13 @@ async fn exec_process_signal_reports_unsupported_on_windows(use_remote: bool) ->
|
||||
async fn exec_process_preserves_queued_events_before_subscribe(use_remote: bool) -> Result<()> {
|
||||
assert_exec_process_preserves_queued_events_before_subscribe(use_remote).await
|
||||
}
|
||||
|
||||
#[test_case(false ; "local")]
|
||||
#[test_case(true ; "remote")]
|
||||
#[cfg(unix)]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
// Serialize tests that launch a real exec-server process through the full CLI.
|
||||
#[serial_test::serial(remote_exec_server)]
|
||||
async fn bash_env_exports_are_cached(use_remote: bool) -> Result<()> {
|
||||
assert_bash_env_exports_are_cached(use_remote).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user