2
2
3
3
set -euo pipefail
4
4
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
+
5
11
# Default timeout in seconds (10 minutes)
6
12
TIMEOUT=${1:- 600}
7
13
MAX_ITERATIONS=10
@@ -47,12 +53,6 @@ warn() {
47
53
echo -e " ${YELLOW} [aitest WARN]${NC} $1 " >&2
48
54
}
49
55
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
-
56
56
# Read prompt from stdin
57
57
log " Reading prompt from stdin..."
58
58
prompt=$( cat)
@@ -69,7 +69,7 @@ log "Logging Claude output to: $LOG_FILE"
69
69
get_coverage () {
70
70
local output_file=" $1 "
71
71
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
73
73
return 1
74
74
fi
75
75
return 0
@@ -109,17 +109,15 @@ check_coverage_change() {
109
109
110
110
log " Coverage: baseline ${baseline_pct} %, current ${current_pct} %"
111
111
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} %"
118
117
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} %
123
121
124
122
=== BASELINE COVERAGE ===
125
123
$( go tool cover -func=" $baseline_file " )
@@ -128,15 +126,9 @@ $(go tool cover -func="$baseline_file")
128
126
$( go tool cover -func=" $current_file " )
129
127
130
128
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
134
129
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
140
132
fi
141
133
142
134
return 0
0 commit comments