mod common;
use common::Fixture;
use serde_json::json;
#[cfg(unix)]
#[test]
fn early_closed_stdout_pipe_kills_with_sigpipe_instead_of_panicking() {
use std::os::unix::process::ExitStatusExt;
use std::process::{Command, Stdio};
const SIGPIPE: i32 = 13;
let fx = Fixture::new();
let mut projects = serde_json::Map::new();
for i in 0..5000 {
projects.insert(format!("/no/such/dir/entry-{i:04}"), json!({}));
}
fx.write_config(json!(projects), json!({}));
let mut child = Command::new(assert_cmd::cargo::cargo_bin("midden"))
.arg("--color")
.arg("never")
.arg("--config")
.arg(&fx.config)
.arg("--claude-home")
.arg(&fx.claude_home)
.arg("--codex-home")
.arg(&fx.codex_home)
.arg("prune")
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
.expect("spawn midden");
drop(child.stdout.take());
let status = child.wait().expect("wait for midden");
assert_ne!(
status.code(),
Some(101),
"a closed stdout pipe must not panic"
);
assert_eq!(
status.signal(),
Some(SIGPIPE),
"expected death by SIGPIPE, got {status:?}"
);
}