Base: codex-main originale (prima del fork aKode)

This commit is contained in:
Andrea
2026-11-09 10:37:42 +01:00
commit 7874033c81
10166 changed files with 2728937 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "process",
crate_name = "codex_utils_process",
)

View File

@@ -0,0 +1,15 @@
[package]
name = "codex-utils-process"
version.workspace = true
edition.workspace = true
license.workspace = true
[lints]
workspace = true
[dev-dependencies]
pretty_assertions = { workspace = true }
tokio = { workspace = true, features = ["macros", "process", "rt-multi-thread"] }
[lib]
doctest = false

View File

@@ -0,0 +1,54 @@
//! Verifies detached background children stay console-free through std and Tokio launches.
use super::background_command;
use pretty_assertions::assert_eq;
use std::os::windows::process::CommandExt;
use std::process::Command;
#[tokio::test]
async fn background_commands_have_no_console_under_detached_parent() {
const TEST_NAME: &str = "tests::background_commands_have_no_console_under_detached_parent";
const PHASE: &str = "CODEX_TEST_BACKGROUND_COMMAND_PHASE";
let executable = std::env::current_exe().expect("test executable");
match std::env::var(PHASE).as_deref() {
Ok("probe") => {
#[link(name = "kernel32")]
unsafe extern "system" {
#[link_name = "GetConsoleWindow"]
fn get_console_window() -> isize;
}
assert_eq!(unsafe { get_console_window() }, 0);
println!("background stdout");
eprintln!("background stderr");
}
Ok("detached") => {
for asynchronous in [false, true] {
let mut command = background_command(&executable);
command
.args(["--exact", TEST_NAME, "--nocapture"])
.env(PHASE, "probe");
let output = if asynchronous {
tokio::process::Command::from(command).output().await
} else {
command.output()
}
.expect("run background command");
assert!(output.status.success(), "probe failed: {output:?}");
assert!(String::from_utf8_lossy(&output.stdout).contains("background stdout"));
assert!(String::from_utf8_lossy(&output.stderr).contains("background stderr"));
}
}
_ => {
let output = Command::new(executable)
.args(["--exact", TEST_NAME, "--nocapture"])
.env(PHASE, "detached")
.creation_flags(/*flags*/ 0x0000_0008) // DETACHED_PROCESS
.output()
.expect("spawn detached parent");
assert!(
output.status.success(),
"detached parent failed: {output:?}"
);
}
}
}

View File

@@ -0,0 +1,26 @@
//! Command construction for background processes that must not allocate a Windows console.
//! Callers retain control of environment, stdio, and process lifetime. Interactive,
//! detached, and private-desktop launches must select their own console policy.
use std::ffi::OsStr;
use std::process::Command;
/// Construct a background command, suppressing console allocation on Windows.
/// Convert with `tokio::process::Command::from` for asynchronous execution.
/// Subsequent Windows `creation_flags` calls must retain `CREATE_NO_WINDOW`.
pub fn background_command(program: impl AsRef<OsStr>) -> Command {
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
let mut command = Command::new(program);
command.creation_flags(/*flags*/ 0x0800_0000); // CREATE_NO_WINDOW
command
}
#[cfg(not(windows))]
Command::new(program)
}
#[cfg(all(test, windows))]
#[path = "background_command_tests.rs"]
mod tests;