Skip to content

Commit 33ef870

Browse files
committed
use awk instead of bc
1 parent 4edbd47 commit 33ef870

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

scripts/aitest.sh

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
set -euo pipefail
44

5+
# shellcheck source=scripts/lib.sh
6+
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7+
8+
# Check required dependencies
9+
dependencies claude gotestsum awk go
10+
511
# Default timeout in seconds (10 minutes)
612
TIMEOUT=${1:-600}
713
MAX_ITERATIONS=10
@@ -47,12 +53,6 @@ warn() {
4753
echo -e "${YELLOW}[aitest WARN]${NC} $1" >&2
4854
}
4955

50-
# Check if claude command is available
51-
if ! command -v claude >/dev/null 2>&1; then
52-
error "claude command not found. Please install Claude CLI."
53-
exit 1
54-
fi
55-
5656
# Read prompt from stdin
5757
log "Reading prompt from stdin..."
5858
prompt=$(cat)
@@ -69,7 +69,7 @@ log "Logging Claude output to: $LOG_FILE"
6969
get_coverage() {
7070
local output_file="$1"
7171
log "Getting test coverage profile..."
72-
if ! GOMAXPROCS=4 gotestsum --packages="./..." --rerun-fails=1 -- --coverprofile="$output_file" >/dev/null 2>&1; then
72+
if ! GOMAXPROCS=4 gotestsum --packages="./..." --rerun-fails=1 -- --covermode=atomic --coverprofile="$output_file" >/dev/null 2>&1; then
7373
return 1
7474
fi
7575
return 0
@@ -109,17 +109,15 @@ check_coverage_change() {
109109

110110
log "Coverage: baseline ${baseline_pct}%, current ${current_pct}%"
111111

112-
# Compare coverage (using bc for floating point comparison)
113-
if command -v bc >/dev/null 2>&1; then
114-
local decreased
115-
decreased=$(echo "$current_pct < $baseline_pct" | bc -l)
116-
if [[ "$decreased" == "1" ]]; then
117-
warn "Coverage decreased from ${baseline_pct}% to ${current_pct}%"
112+
# Compare coverage using awk for floating point comparison
113+
local decreased
114+
decreased=$(awk -v current="$current_pct" -v baseline="$baseline_pct" 'BEGIN { print (current < baseline) ? 1 : 0 }')
115+
if [[ "$decreased" == "1" ]]; then
116+
warn "Coverage decreased from ${baseline_pct}% to ${current_pct}%"
118117

119-
# Generate coverage diff
120-
local diff_output=""
121-
if command -v go >/dev/null 2>&1; then
122-
diff_output="Coverage decreased from ${baseline_pct}% to ${current_pct}%
118+
# Generate coverage diff
119+
local diff_output
120+
diff_output="Coverage decreased from ${baseline_pct}% to ${current_pct}%
123121
124122
=== BASELINE COVERAGE ===
125123
$(go tool cover -func="$baseline_file")
@@ -128,15 +126,9 @@ $(go tool cover -func="$baseline_file")
128126
$(go tool cover -func="$current_file")
129127
130128
Please fix the code to maintain or improve test coverage."
131-
else
132-
diff_output="Coverage decreased from ${baseline_pct}% to ${current_pct}%. Please fix the code to maintain or improve test coverage."
133-
fi
134129

135-
echo "$diff_output"
136-
return 1
137-
fi
138-
else
139-
warn "bc command not available, skipping precise coverage comparison"
130+
echo "$diff_output"
131+
return 1
140132
fi
141133

142134
return 0

0 commit comments

Comments
 (0)