Add 10-minute timeout to test commands and disable e2e in merge pipeline
Test commands in run_project_tests now use wait-timeout to enforce a 600-second ceiling, preventing hung processes (e.g. Playwright with no server) from blocking the merge pipeline indefinitely. Also disables e2e tests in script/test until the merge workspace can run them safely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ pulldown-cmark = { workspace = true }
|
||||
|
||||
# Force bundled SQLite so static musl builds don't need a system libsqlite3
|
||||
libsqlite3-sys = { version = "0.35.0", features = ["bundled"] }
|
||||
wait-timeout = "0.2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = { workspace = true }
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use wait_timeout::ChildExt;
|
||||
|
||||
/// Maximum time any single test command is allowed to run before being killed.
|
||||
const TEST_TIMEOUT: Duration = Duration::from_secs(600); // 10 minutes
|
||||
|
||||
/// Detect whether the base branch in a worktree is `master` or `main`.
|
||||
/// Falls back to `"master"` if neither is found.
|
||||
@@ -65,48 +70,20 @@ pub(crate) fn run_project_tests(path: &Path) -> Result<(bool, String), String> {
|
||||
let script_test = path.join("script").join("test");
|
||||
if script_test.exists() {
|
||||
let mut output = String::from("=== script/test ===\n");
|
||||
let result = Command::new(&script_test)
|
||||
.current_dir(path)
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to run script/test: {e}"))?;
|
||||
let out = format!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&result.stdout),
|
||||
String::from_utf8_lossy(&result.stderr)
|
||||
);
|
||||
let (success, out) = run_command_with_timeout(&script_test, &[], path)?;
|
||||
output.push_str(&out);
|
||||
output.push('\n');
|
||||
return Ok((result.status.success(), output));
|
||||
return Ok((success, output));
|
||||
}
|
||||
|
||||
// Fallback: cargo nextest run / cargo test
|
||||
let mut output = String::from("=== tests ===\n");
|
||||
let (success, test_out) = match Command::new("cargo")
|
||||
.args(["nextest", "run"])
|
||||
.current_dir(path)
|
||||
.output()
|
||||
{
|
||||
Ok(o) => {
|
||||
let combined = format!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&o.stdout),
|
||||
String::from_utf8_lossy(&o.stderr)
|
||||
);
|
||||
(o.status.success(), combined)
|
||||
}
|
||||
let (success, test_out) = match run_command_with_timeout("cargo", &["nextest", "run"], path) {
|
||||
Ok(result) => result,
|
||||
Err(_) => {
|
||||
// nextest not available — fall back to cargo test
|
||||
let o = Command::new("cargo")
|
||||
.args(["test"])
|
||||
.current_dir(path)
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to run cargo test: {e}"))?;
|
||||
let combined = format!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&o.stdout),
|
||||
String::from_utf8_lossy(&o.stderr)
|
||||
);
|
||||
(o.status.success(), combined)
|
||||
run_command_with_timeout("cargo", &["test"], path)
|
||||
.map_err(|e| format!("Failed to run cargo test: {e}"))?
|
||||
}
|
||||
};
|
||||
output.push_str(&test_out);
|
||||
@@ -114,6 +91,49 @@ pub(crate) fn run_project_tests(path: &Path) -> Result<(bool, String), String> {
|
||||
Ok((success, output))
|
||||
}
|
||||
|
||||
/// Run a command with a timeout. Returns `(success, combined_output)`.
|
||||
/// Kills the child process if it exceeds `TEST_TIMEOUT`.
|
||||
fn run_command_with_timeout(
|
||||
program: impl AsRef<std::ffi::OsStr>,
|
||||
args: &[&str],
|
||||
dir: &Path,
|
||||
) -> Result<(bool, String), String> {
|
||||
let mut child = Command::new(program)
|
||||
.args(args)
|
||||
.current_dir(dir)
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to spawn command: {e}"))?;
|
||||
|
||||
match child.wait_timeout(TEST_TIMEOUT) {
|
||||
Ok(Some(status)) => {
|
||||
// Process exited within the timeout — collect output.
|
||||
let stdout = child.stdout.take().map(|mut r| {
|
||||
let mut s = String::new();
|
||||
std::io::Read::read_to_string(&mut r, &mut s).ok();
|
||||
s
|
||||
}).unwrap_or_default();
|
||||
let stderr = child.stderr.take().map(|mut r| {
|
||||
let mut s = String::new();
|
||||
std::io::Read::read_to_string(&mut r, &mut s).ok();
|
||||
s
|
||||
}).unwrap_or_default();
|
||||
Ok((status.success(), format!("{stdout}{stderr}")))
|
||||
}
|
||||
Ok(None) => {
|
||||
// Timed out — kill the child.
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
Err(format!(
|
||||
"Command timed out after {} seconds",
|
||||
TEST_TIMEOUT.as_secs()
|
||||
))
|
||||
}
|
||||
Err(e) => Err(format!("Failed to wait for command: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run `cargo clippy` and the project test suite (via `script/test` if present,
|
||||
/// otherwise `cargo nextest run` / `cargo test`) in the given directory.
|
||||
/// Returns `(gates_passed, combined_output)`.
|
||||
|
||||
Reference in New Issue
Block a user