Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/windows-sandbox-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ chrono = { version = "0.4.42", default-features = false, features = [
"std",
] }
codex-utils-absolute-path = { workspace = true }
codex-utils-string = { workspace = true }
dunce = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
20 changes: 19 additions & 1 deletion codex-rs/windows-sandbox-rs/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::OnceLock;

use codex_utils_string::take_bytes_at_char_boundary;

const LOG_COMMAND_PREVIEW_LIMIT: usize = 200;
pub const LOG_FILE_NAME: &str = "sandbox.log";

Expand All @@ -22,7 +24,7 @@ fn preview(command: &[String]) -> String {
if joined.len() <= LOG_COMMAND_PREVIEW_LIMIT {
joined
} else {
joined[..LOG_COMMAND_PREVIEW_LIMIT].to_string()
take_bytes_at_char_boundary(&joined, LOG_COMMAND_PREVIEW_LIMIT).to_string()
}
}

Expand Down Expand Up @@ -72,3 +74,19 @@ pub fn log_note(msg: &str, base_dir: Option<&Path>) {
let ts = chrono::Local::now().format("%Y-%m-%d %H:%M:%S%.3f");
append_line(&format!("[{ts} {}] {}", exe_label(), msg), base_dir);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn preview_does_not_panic_on_utf8_boundary() {
// Place a 4-byte emoji such that naive (byte-based) truncation would split it.
let prefix = "x".repeat(LOG_COMMAND_PREVIEW_LIMIT - 1);
let command = vec![format!("{prefix}😀")];
let result = std::panic::catch_unwind(|| preview(&command));
assert!(result.is_ok());
let previewed = result.unwrap();
assert!(previewed.len() <= LOG_COMMAND_PREVIEW_LIMIT);
}
}
Loading