From e57a911052730c435269c747043ad8e527b8edc0 Mon Sep 17 00:00:00 2001 From: Ethan Zhang Date: Mon, 13 Apr 2026 14:23:42 -0500 Subject: [PATCH 1/3] Apply suggested fix to .githooks/pre-commit from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- .githooks/pre-commit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 1188e31c..c9ba7e9a 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -40,7 +40,8 @@ echo "Checking coverage..." go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s COVERAGE=$(go tool cover -func=coverage.out 2>/dev/null | grep total | awk '{print $3}' | sed 's/%//') if [ -n "$COVERAGE" ]; then - if (( $(echo "$COVERAGE < 50" | bc -l) )); then + COVERAGE_INT=$(awk -v c="$COVERAGE" 'BEGIN { printf "%d", c * 100 }') + if [ "$COVERAGE_INT" -lt 5000 ]; then echo "Coverage ${COVERAGE}% is below 50% threshold" FAILED=1 else From 6154056a259341e02fc596a32abac2d3d7cfd63b Mon Sep 17 00:00:00 2001 From: Ethan Zhang Date: Mon, 13 Apr 2026 14:23:43 -0500 Subject: [PATCH 2/3] Apply suggested fix to .githooks/pre-commit from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- .githooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c9ba7e9a..bde1cc95 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -35,7 +35,7 @@ if ! go test ./... -race -count=1 -timeout 120s; then FAILED=1 fi -# Coverage threshold (80%) +# Coverage threshold (50%) echo "Checking coverage..." go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s COVERAGE=$(go tool cover -func=coverage.out 2>/dev/null | grep total | awk '{print $3}' | sed 's/%//') From 1fc50e8a45923025c7731f443a27bb6134947d8f Mon Sep 17 00:00:00 2001 From: "Yiqun (Ethan) Zhang" Date: Mon, 13 Apr 2026 14:37:50 -0500 Subject: [PATCH 3/3] fix: combine race+coverage test runs, fail on coverage collection error Two improvements to the pre-commit hook: 1. Merge the two 'go test ./...' invocations into one with -race and -coverprofile together. The test suite was running twice on every commit; combining roughly halves hook runtime. -race mandates -covermode=atomic, which the coverage run already used. 2. Treat empty COVERAGE as a failure rather than silently passing. Previously, if 'go tool cover -func' emitted nothing (e.g. the test run above had already aborted), the outer -n guard skipped the threshold check entirely, so a broken coverage profile looked like a clean run. --- .githooks/pre-commit | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index bde1cc95..37f3c1dc 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -29,15 +29,14 @@ if command -v staticcheck &>/dev/null; then fi fi -# Tests with race detection +# Tests with race detection and coverage (combined; -race requires -covermode=atomic) echo "Running tests..." -if ! go test ./... -race -count=1 -timeout 120s; then +if ! go test ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s; then FAILED=1 fi # Coverage threshold (50%) echo "Checking coverage..." -go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s COVERAGE=$(go tool cover -func=coverage.out 2>/dev/null | grep total | awk '{print $3}' | sed 's/%//') if [ -n "$COVERAGE" ]; then COVERAGE_INT=$(awk -v c="$COVERAGE" 'BEGIN { printf "%d", c * 100 }') @@ -47,6 +46,9 @@ if [ -n "$COVERAGE" ]; then else echo "Coverage: ${COVERAGE}%" fi +else + echo "Coverage collection failed (no total in coverage.out)" + FAILED=1 fi rm -f coverage.out