mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
## Why Debug executables can be hundreds of megabytes. Computing their identity previously loaded the entire file into memory and hashed it on an async runtime thread. ## What changed Stream executable contents into the BLAKE3 hasher using `tokio::task::spawn_blocking`, preserving the existing digest format while avoiding whole-file allocation and moving hashing off the async runtime. ## Testing Expand the executable identity test to verify compatibility with whole-file hashing for a file spanning multiple reads with a partial final buffer and for an empty file, and to confirm that changing a byte changes the identity. GitOrigin-RevId: 528103397395313d170ec720fefc8c5ab3676956
47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
use pretty_assertions::assert_eq;
|
|
|
|
use super::ExecutableIdentity;
|
|
use super::executable_identity;
|
|
use super::parse_codex_version;
|
|
|
|
#[test]
|
|
fn parses_codex_cli_version_output() {
|
|
assert_eq!(
|
|
parse_codex_version("codex 1.2.3\n").expect("version"),
|
|
"1.2.3"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_malformed_codex_cli_version_output() {
|
|
assert!(parse_codex_version("codex\n").is_err());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn executable_identity_uses_binary_contents() {
|
|
let directory = tempfile::tempdir().expect("temporary directory");
|
|
let executable = directory.path().join("codex");
|
|
// Span multiple reads, including a partial final buffer, and preserve the
|
|
// digest stored by older clients that hashed the complete file in memory.
|
|
let mut bytes: Vec<u8> = (0..200_003).map(|index| (index % 251) as u8).collect();
|
|
for contents in [&bytes[..], &[][..]] {
|
|
std::fs::write(&executable, contents).expect("write executable");
|
|
assert_eq!(
|
|
executable_identity(&executable).await.expect("identity"),
|
|
ExecutableIdentity {
|
|
digest: *blake3::hash(contents).as_bytes(),
|
|
}
|
|
);
|
|
}
|
|
std::fs::write(&executable, &bytes).expect("write executable");
|
|
let old = executable_identity(&executable).await.expect("identity");
|
|
bytes[100_000] ^= 1;
|
|
std::fs::write(&executable, bytes).expect("replace executable");
|
|
assert_ne!(
|
|
executable_identity(&executable)
|
|
.await
|
|
.expect("new identity"),
|
|
old
|
|
);
|
|
}
|