mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
fix(exec-server): retain output until streams close
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use codex_exec_server::CODEX_FS_HELPER_ARG1;
|
||||
use codex_exec_server::ExecServerRuntimePaths;
|
||||
@@ -11,6 +15,11 @@ use ctor::ctor;
|
||||
|
||||
pub(crate) mod exec_server;
|
||||
|
||||
pub(crate) const DELAYED_OUTPUT_AFTER_EXIT_PARENT_ARG: &str =
|
||||
"--codex-test-delayed-output-after-exit-parent";
|
||||
|
||||
const DELAYED_OUTPUT_AFTER_EXIT_CHILD_ARG: &str = "--codex-test-delayed-output-after-exit-child";
|
||||
|
||||
#[ctor]
|
||||
pub static TEST_BINARY_DISPATCH_GUARD: Option<TestBinaryDispatchGuard> = {
|
||||
let guard = configure_test_binary_dispatch("codex-exec-server-tests", |exe_name, argv1| {
|
||||
@@ -22,6 +31,7 @@ pub static TEST_BINARY_DISPATCH_GUARD: Option<TestBinaryDispatchGuard> = {
|
||||
}
|
||||
TestBinaryDispatchMode::InstallAliases
|
||||
});
|
||||
maybe_run_delayed_output_after_exit_from_test_binary();
|
||||
maybe_run_exec_server_from_test_binary(guard.as_ref());
|
||||
guard
|
||||
};
|
||||
@@ -39,6 +49,54 @@ pub(crate) fn current_test_binary_helper_paths() -> anyhow::Result<(PathBuf, Opt
|
||||
Ok((current_exe, codex_linux_sandbox_exe))
|
||||
}
|
||||
|
||||
fn maybe_run_delayed_output_after_exit_from_test_binary() {
|
||||
let mut args = env::args();
|
||||
let _program = args.next();
|
||||
let Some(command) = args.next() else {
|
||||
return;
|
||||
};
|
||||
match command.as_str() {
|
||||
DELAYED_OUTPUT_AFTER_EXIT_PARENT_ARG => run_delayed_output_after_exit_parent(),
|
||||
DELAYED_OUTPUT_AFTER_EXIT_CHILD_ARG => run_delayed_output_after_exit_child(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_delayed_output_after_exit_parent() {
|
||||
let current_exe = match env::current_exe() {
|
||||
Ok(current_exe) => current_exe,
|
||||
Err(error) => {
|
||||
eprintln!("failed to resolve current test binary: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
match Command::new(current_exe)
|
||||
.arg(DELAYED_OUTPUT_AFTER_EXIT_CHILD_ARG)
|
||||
.stdin(Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
Ok(_) => std::process::exit(0),
|
||||
Err(error) => {
|
||||
eprintln!("failed to spawn delayed output child: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_delayed_output_after_exit_child() {
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
let mut stdout = std::io::stdout().lock();
|
||||
if let Err(error) = writeln!(stdout, "late output after exit") {
|
||||
eprintln!("failed to write delayed output: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
if let Err(error) = stdout.flush() {
|
||||
eprintln!("failed to flush delayed output: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
fn maybe_run_exec_server_from_test_binary(guard: Option<&TestBinaryDispatchGuard>) {
|
||||
let mut args = env::args();
|
||||
let _program = args.next();
|
||||
|
||||
Reference in New Issue
Block a user