fix(bf-632yt): fix arithmetic operations causing premature script exit
Fixed critical bug where validation script exited prematurely under set -euo pipefail due to arithmetic operations returning non-zero exit codes when evaluating to 0. Changes: - Replaced ((var++)) with var=$((var + 1)) - Replaced ((var += value)) with var=$((var + value)) - Restructured progress indicator to avoid modulo 0 result Verification: - Script now successfully validates all 1,260 corpus files - Correctly reports 603 valid files with complete license info - Detects 657 files with missing licenses (expected - PDFium test files) - Exits with code 1 when validation fails (as designed) Closes bf-632yt
This commit is contained in:
parent
1a356039f9
commit
789db9d41c
2 changed files with 32 additions and 12 deletions
|
|
@ -47,7 +47,26 @@ Default corpus directory: `tests/fixtures/grep-corpus`
|
|||
- ✅ Returns 0 on success, non-zero on validation failure
|
||||
- ✅ Outputs summary: total files, total pages, total size, validation status
|
||||
|
||||
## Commit
|
||||
## Bug Fix (2026-07-05)
|
||||
|
||||
- Commit: `c189bfd2`
|
||||
- Files changed: `scripts/validate-corpus.sh` (1 file, 114 insertions, 147 deletions)
|
||||
Fixed critical issue where script exited prematurely under `set -euo pipefail` due to arithmetic operations returning non-zero exit codes when evaluating to 0.
|
||||
|
||||
### Changes made:
|
||||
- Replaced all `((var++))` with `var=$((var + 1))`
|
||||
- Replaced all `((var += value))` with `var=$((var + value))`
|
||||
- Restructured progress indicator to avoid modulo 0 result
|
||||
|
||||
### Root cause:
|
||||
The `set -e` flag causes scripts to exit when any command returns non-zero. Arithmetic operations like `((x++))` return the result of the expression (0 when x becomes 0 after increment), which triggers `set -e` to exit.
|
||||
|
||||
### Verification:
|
||||
After fix, script successfully validates all 1,260 files:
|
||||
- Total files: 1,260
|
||||
- Valid files: 603 (with complete license info)
|
||||
- Missing licenses: 657 (expected - PDFium test files)
|
||||
- Exit code: 1 (correctly fails when validation errors found)
|
||||
|
||||
## Commits
|
||||
|
||||
- Initial: `c189bfd2` - Created validation script
|
||||
- Fix: `<pending>` - Fixed arithmetic operation exits under set -e
|
||||
|
|
|
|||
|
|
@ -82,14 +82,14 @@ while IFS=',' read -r filename source_url page_count file_size checksum license;
|
|||
continue
|
||||
fi
|
||||
|
||||
((total_files++))
|
||||
total_files=$((total_files + 1))
|
||||
|
||||
file_path="${CORPUS_SUBDIR}/${filename}"
|
||||
|
||||
# Check 1: File existence
|
||||
if [[ ! -f "$file_path" ]]; then
|
||||
log_error "MISSING: $filename"
|
||||
((missing_files++))
|
||||
missing_files=$((missing_files + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ while IFS=',' read -r filename source_url page_count file_size checksum license;
|
|||
if [[ "$actual_size" != "$file_size" ]]; then
|
||||
log_warn "SIZE MISMATCH: $filename"
|
||||
echo " Expected: $file_size bytes, Got: $actual_size bytes"
|
||||
((size_mismatches++))
|
||||
size_mismatches=$((size_mismatches + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
|
|
@ -110,26 +110,27 @@ while IFS=',' read -r filename source_url page_count file_size checksum license;
|
|||
log_warn "CHECKSUM MISMATCH: $filename"
|
||||
echo " Expected: $checksum"
|
||||
echo " Got: $actual_checksum"
|
||||
((checksum_mismatches++))
|
||||
checksum_mismatches=$((checksum_mismatches + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check 4: License information
|
||||
if [[ -z "$license" || "$license" == "null" || "$license" == "unknown" ]]; then
|
||||
log_warn "MISSING LICENSE: $filename"
|
||||
((missing_licenses++))
|
||||
missing_licenses=$((missing_licenses + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
# All checks passed
|
||||
((valid_files++))
|
||||
valid_files=$((valid_files + 1))
|
||||
|
||||
# Accumulate totals
|
||||
((total_pages += page_count))
|
||||
((total_size += file_size))
|
||||
total_pages=$((total_pages + page_count))
|
||||
total_size=$((total_size + file_size))
|
||||
|
||||
# Progress indicator
|
||||
if [[ $((valid_files % 200)) -eq 0 && $valid_files -gt 0 ]]; then
|
||||
remainder=$((valid_files % 200))
|
||||
if [[ $valid_files -gt 0 ]] && [[ $remainder -eq 0 ]]; then
|
||||
log_info "Validated $valid_files files..."
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue