refactor(build): reformat code and add tonic health dependency

- Reformatted build script with proper indentation and line breaks
- Added tonic-health dependency to Cargo.toml and updated lock file
- Improved error handling in disk cache with concurrent deletion checks
- Refactored conditional chains using && and let expressions
- Reformatted struct initialization and function parameter lists
- Added proper spacing and alignment in language stats processing
- Improved assertion formatting in test cases
- Reorganized import statements and code layout in multiple files
- Updated metrics functions with better parameter handling and formatting
This commit is contained in:
zhenyi
2026-06-11 13:56:15 +08:00
parent c32a7cad2f
commit a40da90ef9
31 changed files with 696 additions and 417 deletions
+12 -16
View File
@@ -128,10 +128,14 @@ pub fn run_hook_dir(
/// Run a single hook script with stdin data and timeout.
fn run_single_script(script_path: &Path, stdin_data: &[u8], timeout: Duration) -> HookResult {
// Use Stdio::null() for stdout/stderr to prevent pipe-buffer deadlock.
// With Stdio::piped() + never reading, a hook that writes >64KB of output
// would block the child on write(), and the parent's try_wait() would
// loop until timeout before killing it.
let child = std::process::Command::new(script_path)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn();
match child {
@@ -143,17 +147,12 @@ fn run_single_script(script_path: &Path, stdin_data: &[u8], timeout: Duration) -
let wait_result = c.wait_timeout(timeout);
match wait_result {
Ok(Some(status)) => {
// Process exited within timeout, get its output
// Note: We already have the status, so we need to construct output differently
// Since wait_with_output would fail after try_wait, we return status-only output
HookResult {
accepted: status.success(),
exit_code: status.code().unwrap_or(-1),
stdout: String::new(), // stdout was consumed by the process
stderr: String::new(), // stderr was consumed by the process
}
}
Ok(Some(status)) => HookResult {
accepted: status.success(),
exit_code: status.code().unwrap_or(-1),
stdout: String::new(),
stderr: String::new(),
},
Ok(None) => {
tracing::warn!(
script = %script_path.display(),
@@ -161,7 +160,6 @@ fn run_single_script(script_path: &Path, stdin_data: &[u8], timeout: Duration) -
"hook script timed out, killing"
);
let _ = c.kill();
// Explicitly wait to reap the zombie process
let _ = c.wait();
HookResult::rejected(format!(
"hook script timed out after {}s: {}",
@@ -171,7 +169,6 @@ fn run_single_script(script_path: &Path, stdin_data: &[u8], timeout: Duration) -
}
Err(e) => {
let _ = c.kill();
// Explicitly wait to reap the zombie process
let _ = c.wait();
HookResult::rejected(format!("hook script wait error: {e}"))
}
@@ -183,7 +180,6 @@ fn run_single_script(script_path: &Path, stdin_data: &[u8], timeout: Duration) -
error = %e,
"failed to spawn hook script"
);
// If the script can't be executed, treat as rejection
HookResult::rejected(format!("failed to spawn hook script: {e}"))
}
}