Fix hook command runner encoded windows tests

This commit is contained in:
starr-openai
2026-05-29 01:29:38 -07:00
parent edd9d1efc8
commit 017466574b
2 changed files with 17 additions and 4 deletions
+1
View File
@@ -32,6 +32,7 @@ uuid = { workspace = true, features = ["v4"] }
[dev-dependencies]
async-trait = { workspace = true }
base64 = { workspace = true }
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
+16 -4
View File
@@ -319,6 +319,8 @@ mod tests {
use std::time::Instant;
use async_trait::async_trait;
use base64::Engine as _;
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
use codex_exec_server::EnvironmentManager;
use codex_exec_server::ExecProcessEventReceiver;
use codex_exec_server::ExecServerError;
@@ -443,7 +445,7 @@ mod tests {
fn print_command(output: &str) -> String {
if cfg!(windows) {
format!("powershell -NoLogo -NoProfile -Command \"[Console]::Out.Write('{output}')\"")
powershell_command(&format!("[Console]::Out.Write('{output}')"))
} else {
format!("printf {output}")
}
@@ -451,14 +453,24 @@ mod tests {
fn echo_stdin_to_stdout_and_stderr_with_exit_code(exit_code: i32) -> String {
if cfg!(windows) {
format!(
"powershell -NoLogo -NoProfile -Command \"$hookInput = [Console]::In.ReadToEnd(); [Console]::Out.Write($hookInput); [Console]::Error.Write('stderr'); exit {exit_code}\""
)
powershell_command(&format!(
"$hookInput = [Console]::In.ReadToEnd(); [Console]::Out.Write($hookInput); [Console]::Error.Write('stderr'); exit {exit_code}"
))
} else {
format!("cat; printf stderr >&2; exit {exit_code}")
}
}
fn powershell_command(script: &str) -> String {
let encoded = BASE64_STANDARD.encode(
script
.encode_utf16()
.flat_map(u16::to_le_bytes)
.collect::<Vec<u8>>(),
);
format!("powershell.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand {encoded}")
}
fn sleep_command(seconds: u64) -> String {
if cfg!(windows) {
format!("ping -n {} 127.0.0.1 >NUL", seconds + 1)