test: make hook precedence tests portable on Windows

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
viyatb-oai
2026-04-17 18:50:40 -07:00
co-authored by Codex
parent 35dfbccf61
commit 5983bd41ec
2 changed files with 38 additions and 4 deletions
+19 -2
View File
@@ -394,11 +394,28 @@ mod tests {
let temp = tempfile::tempdir()?;
let marker_path = temp.path().join("project-ran");
let (shell_program, shell_args, stopping_command, project_command) = if cfg!(windows) {
let stopping_script = temp.path().join("stopping.cmd");
std::fs::write(
&stopping_script,
r#"@echo off
more > nul
echo {"continue":false,"stopReason":"pause","hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"trusted context"}}
"#,
)?;
let project_script = temp.path().join("project.cmd");
std::fs::write(
&project_script,
r#"@echo off
more > nul
type nul > project-ran
echo project context
"#,
)?;
(
"cmd.exe".to_string(),
vec!["/D".to_string(), "/C".to_string()],
r#"more > nul && echo {^"continue^":false,^"stopReason^":^"pause^",^"hookSpecificOutput^":{^"hookEventName^":^"SessionStart^",^"additionalContext^":^"trusted context^"}}"#.to_string(),
"more > nul && type nul > project-ran && echo project context".to_string(),
format!("\"{}\"", stopping_script.display()),
format!("\"{}\"", project_script.display()),
)
} else {
(
@@ -451,11 +451,28 @@ mod tests {
let temp = tempfile::tempdir()?;
let marker_path = temp.path().join("project-ran");
let (shell_program, shell_args, stopping_command, project_command) = if cfg!(windows) {
let stopping_script = temp.path().join("stopping.cmd");
std::fs::write(
&stopping_script,
r#"@echo off
more > nul
echo {"decision":"block","reason":"slow down","hookSpecificOutput":{"hookEventName":"UserPromptSubmit","additionalContext":"trusted context"}}
"#,
)?;
let project_script = temp.path().join("project.cmd");
std::fs::write(
&project_script,
r#"@echo off
more > nul
type nul > project-ran
echo project context
"#,
)?;
(
"cmd.exe".to_string(),
vec!["/D".to_string(), "/C".to_string()],
r#"more > nul && echo {^"decision^":^"block^",^"reason^":^"slow down^",^"hookSpecificOutput^":{^"hookEventName^":^"UserPromptSubmit^",^"additionalContext^":^"trusted context^"}}"#.to_string(),
"more > nul && type nul > project-ran && echo project context".to_string(),
format!("\"{}\"", stopping_script.display()),
format!("\"{}\"", project_script.display()),
)
} else {
(