Skip to content

Commit c672910

Browse files
committed
[gobby-cli-#1013] fix: tolerate closed stdin pipe in ghook contract tests
1 parent f23d801 commit c672910

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

crates/ghook/tests/contract.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,20 @@ fn run_ghook_with_dirs(
804804

805805
let mut child = command.spawn()?;
806806
if let Some(mut child_stdin) = child.stdin.take() {
807-
child_stdin.write_all(stdin.as_bytes())?;
807+
write_stdin_allow_broken_pipe(&mut child_stdin, stdin.as_bytes())?;
808808
}
809809
Ok(child.wait_with_output()?)
810810
}
811811

812+
fn write_stdin_allow_broken_pipe(stdin: &mut impl Write, bytes: &[u8]) -> io::Result<()> {
813+
// Invalid-arg paths can exit before stdin is read; CI can win that race.
814+
match stdin.write_all(bytes) {
815+
Ok(()) => Ok(()),
816+
Err(error) if error.kind() == io::ErrorKind::BrokenPipe => Ok(()),
817+
Err(error) => Err(error),
818+
}
819+
}
820+
812821
fn assert_json_stdout(output: &Output, expected: Value) -> TestResult {
813822
let actual: Value = serde_json::from_slice(&output.stdout)?;
814823
assert_eq!(actual, expected);

0 commit comments

Comments
 (0)