Skip to content

Commit 2b9e252

Browse files
committed
fix: make hook regressions portable
Co-authored-by: Codex noreply@openai.com
1 parent 0250389 commit 2b9e252

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

codex-rs/hooks/src/events/pre_tool_use.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,26 @@ mod tests {
488488
async fn higher_precedence_block_skips_lower_precedence_handlers() -> std::io::Result<()> {
489489
let temp = tempfile::tempdir()?;
490490
let marker_path = temp.path().join("project-ran");
491+
let (shell_program, shell_args, blocking_command, project_command) = if cfg!(windows) {
492+
(
493+
"cmd".to_string(),
494+
vec!["/C".to_string()],
495+
"echo blocked by policy 1>&2 && exit /b 2".to_string(),
496+
"type nul > project-ran".to_string(),
497+
)
498+
} else {
499+
(
500+
"/bin/sh".to_string(),
501+
vec!["-c".to_string()],
502+
"printf 'blocked by policy' >&2; exit 2".to_string(),
503+
"touch project-ran".to_string(),
504+
)
505+
};
491506
let handlers = vec![
492507
ConfiguredHandler {
493508
event_name: HookEventName::PreToolUse,
494509
matcher: Some("^Bash$".to_string()),
495-
command: "printf 'blocked by policy' >&2; exit 2".to_string(),
510+
command: blocking_command,
496511
timeout_sec: 5,
497512
status_message: None,
498513
source_path: PathBuf::from("/tmp/home/.codex/hooks.json"),
@@ -502,7 +517,7 @@ mod tests {
502517
ConfiguredHandler {
503518
event_name: HookEventName::PreToolUse,
504519
matcher: Some("^Bash$".to_string()),
505-
command: "touch project-ran".to_string(),
520+
command: project_command,
506521
timeout_sec: 5,
507522
status_message: None,
508523
source_path: PathBuf::from("/tmp/project/.codex/hooks.json"),
@@ -514,8 +529,8 @@ mod tests {
514529
let outcome = super::run(
515530
&handlers,
516531
&CommandShell {
517-
program: "/bin/sh".to_string(),
518-
args: vec!["-c".to_string()],
532+
program: shell_program,
533+
args: shell_args,
519534
},
520535
PreToolUseRequest {
521536
session_id: ThreadId::new(),

0 commit comments

Comments
 (0)