From 34f27f568c39ef5ac9029c6212a7fc78c874aa28 Mon Sep 17 00:00:00 2001 From: starr-openai Date: Fri, 29 May 2026 05:54:11 -0700 Subject: [PATCH] Avoid hooks Bazel test dependency --- codex-rs/hooks/Cargo.toml | 1 - codex-rs/hooks/src/engine/command_runner.rs | 32 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/codex-rs/hooks/Cargo.toml b/codex-rs/hooks/Cargo.toml index eade1217b6..874df2d2d9 100644 --- a/codex-rs/hooks/Cargo.toml +++ b/codex-rs/hooks/Cargo.toml @@ -14,7 +14,6 @@ workspace = true [dependencies] anyhow = { workspace = true } -base64 = { workspace = true } chrono = { workspace = true, features = ["serde"] } codex-config = { workspace = true } codex-exec-server = { workspace = true } diff --git a/codex-rs/hooks/src/engine/command_runner.rs b/codex-rs/hooks/src/engine/command_runner.rs index aa18220613..b5ecda65d7 100644 --- a/codex-rs/hooks/src/engine/command_runner.rs +++ b/codex-rs/hooks/src/engine/command_runner.rs @@ -319,8 +319,6 @@ 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; @@ -462,8 +460,8 @@ mod tests { } fn powershell_command(script: &str) -> String { - let encoded = BASE64_STANDARD.encode( - script + let encoded = base64_standard_encode( + &script .encode_utf16() .flat_map(u16::to_le_bytes) .collect::>(), @@ -471,6 +469,32 @@ mod tests { format!("powershell.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand {encoded}") } + fn base64_standard_encode(bytes: &[u8]) -> String { + const BASE64_STANDARD_ALPHABET: &[u8; 64] = + b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + let mut encoded = String::with_capacity(bytes.len().div_ceil(3) * 4); + for chunk in bytes.chunks(3) { + let block = chunk + .iter() + .fold(0_u32, |block, byte| (block << 8) | u32::from(*byte)) + << ((3 - chunk.len()) * 8); + encoded.push(BASE64_STANDARD_ALPHABET[((block >> 18) & 0x3f) as usize] as char); + encoded.push(BASE64_STANDARD_ALPHABET[((block >> 12) & 0x3f) as usize] as char); + encoded.push(if chunk.len() > 1 { + BASE64_STANDARD_ALPHABET[((block >> 6) & 0x3f) as usize] as char + } else { + '=' + }); + encoded.push(if chunk.len() > 2 { + BASE64_STANDARD_ALPHABET[(block & 0x3f) as usize] as char + } else { + '=' + }); + } + encoded + } + fn sleep_command(seconds: u64) -> String { if cfg!(windows) { format!("ping -n {} 127.0.0.1 >NUL", seconds + 1)