chore: make pre-commit resilient when cargo absent

This commit is contained in:
jasonwitty 2025-08-26 00:18:10 -07:00
parent c9ebea92f5
commit 3394beab67
2 changed files with 17 additions and 6 deletions

15
.githooks/pre-commit Normal file → Executable file
View File

@ -1,11 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# This repository uses a custom hooks directory (.githooks). To enable this pre-commit hook run:
# git config core.hooksPath .githooks
# Ensure this file is executable: chmod +x .githooks/pre-commit
set -euo pipefail set -euo pipefail
echo "[pre-commit] Running cargo fmt --all" >&2 echo "[pre-commit] Running cargo fmt --all" >&2
if ! command -v cargo >/dev/null 2>&1; then if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH" >&2 # Try loading rustup environment (common install path)
exit 1 if [ -f "$HOME/.cargo/env" ]; then
# shellcheck source=/dev/null
. "$HOME/.cargo/env"
fi
fi
if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH; skipping fmt (install Rust or adjust PATH)." >&2
exit 0
fi fi
cargo fmt --all cargo fmt --all

View File

@ -476,8 +476,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
} }
}) })
.collect(); .collect();
// Automatic scaling (enabled by default): if sum of per-process CPU exceeds global // Automatic scaling (enabled by default): if sum of per-process CPU exceeds global
// CPU by >5%, scale all process CPU values proportionally so the sum matches global. // CPU by >5%, scale all process CPU values proportionally so the sum matches global.
if std::env::var("SOCKTOP_AGENT_SCALE_PROC_CPU") if std::env::var("SOCKTOP_AGENT_SCALE_PROC_CPU")
.map(|v| v != "0") .map(|v| v != "0")
.unwrap_or(true) .unwrap_or(true)
@ -486,8 +486,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
let global = sys.global_cpu_usage(); let global = sys.global_cpu_usage();
if sum > 0.0 && global > 0.0 { if sum > 0.0 && global > 0.0 {
let scale = global / sum; let scale = global / sum;
if scale < 0.95 { if scale < 0.95 {
// only scale if we're at least 5% over // only scale if we're at least 5% over
for p in &mut list { for p in &mut list {
p.cpu_usage = (p.cpu_usage * scale).clamp(0.0, 100.0); p.cpu_usage = (p.cpu_usage * scale).clamp(0.0, 100.0);
} }