@@ -166,8 +166,8 @@ if [ -f /tmp/gh-aw/data/cloc_output.json ] && [ -s /tmp/gh-aw/data/cloc_output.j
166166 lines_of_code_total=$( jq ' .SUM.code' /tmp/gh-aw/data/cloc_output.json)
167167
168168 # Test LOC (find test files and measure)
169- # Scope: Files matching test patterns
170- test_files=$( find . -name " *_test.go" -o -name " *.test.js" -o -name " test_*.py" -o -name " *_test.py" 2> /dev/null)
169+ # Scope: Files matching test patterns (*_test.go, *.test.js, *.test.cjs, test_*.py, *_test.py)
170+ test_files=$( find . -name " *_test.go" -o -name " *.test.js" -o -name " *.test.cjs " -o -name " test_*.py" -o -name " *_test.py" 2> /dev/null)
171171
172172 if [ -n " $test_files " ]; then
173173 echo " $test_files " | xargs cloc --json --quiet > /tmp/gh-aw/data/test_cloc.json
@@ -176,16 +176,23 @@ if [ -f /tmp/gh-aw/data/cloc_output.json ] && [ -s /tmp/gh-aw/data/cloc_output.j
176176 test_lines_of_code=0
177177 fi
178178
179+ # Calculate source LOC (excluding tests)
180+ # Scope: All source files excluding test files
181+ # This is needed for the correct test-to-source ratio calculation
182+ source_lines_of_code=$(( lines_of_code_total - test_lines_of_code))
183+
179184 # Calculate test-to-source ratio
180- # Scope: test_lines_of_code / lines_of_code_total
181- if [ " $lines_of_code_total " -gt 0 ]; then
182- test_to_source_ratio=$( echo " scale=3; $test_lines_of_code / $lines_of_code_total " | bc)
185+ # Scope: test_lines_of_code / source_lines_of_code (excludes test files from source LOC)
186+ # Per specs/metrics-glossary.md: "Excludes test files from source LOC calculation"
187+ if [ " $source_lines_of_code " -gt 0 ]; then
188+ test_to_source_ratio=$( echo " scale=3; $test_lines_of_code / $source_lines_of_code " | bc)
183189 else
184190 test_to_source_ratio=" 0"
185191 fi
186192
187193 echo " Total LOC: $lines_of_code_total "
188194 echo " Test LOC: $test_lines_of_code "
195+ echo " Source LOC (excluding tests): $source_lines_of_code "
189196 echo " Test-to-Source Ratio: $test_to_source_ratio "
190197else
191198 echo " Error: cloc did not produce valid output"
0 commit comments