Files
ledger cd3b285a66 spark: repair Q125 line-counter verifier and land its graders
verify_line_counter.sh pinned the pre-Q125 tool at a host path
(/root/.hermes/wizard-outputs/spark/line_counter.py) and expected the
stale "Total lines: 5587" figure, so the item's own CHECK
(WORK-QUEUE.md:13377) reddened: usage-line output, rc 1.

Repair (confined to wizard-work/spark):
- verify_line_counter.sh resolves line_counter.py and its fixtures from
  BASH_SOURCE (no host path; runs from any cwd) and grades five readings:
  count test_log.txt == wc -l == 10; csv test_data.csv == csv-module
  field count == 5; count test_blank.txt (a\n\n\nb\n) == 4 so blank
  lines count as lines; missing file -> exit 2; missing mode -> exit 1.
- test_line_counter.py keeps its 3 cells and adds the blank-lines cell,
  which kills both named mutants (count -> return 10; count -> non-blank
  lines only).
- test_blank.txt: new fixture, exactly printf 'a\n\n\nb\n' (4 lines).
- README.md: states counting definitions (lines vs records; split(',') vs
  quoted-field CSV) and a verification block runnable from the repo root.
- VERIFICATION.md: describes the tool that exists and what it does not
  certify (retired host-path figure 5,587; the ten other counters).

Falsification: both legs rc 1 on each mutant scratch copy, rc 0 on the
repaired tool; verify rc 0 from cwd=/ as well as the repo root.
Q125's own CHECK exits 0 at this HEAD.
2026-10-31 17:55:11 +00:00

65 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Final verification test for line_counter.py (Q125 repair).
# Returns 0 if correct, non-zero if wrong.
#
# Grades the tool that ships in this lane: line_counter.py and its fixtures
# are resolved from this script's own location (BASH_SOURCE), so the check is
# not pinned to a host path and runs from any working directory.
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOOL="$HERE/line_counter.py"
fail=0
note() { echo "ok: $*"; }
err() { echo "BAD: $*" >&2; fail=1; }
# Reading 1 — count mode on a known fixture equals wc -l
expect=$(wc -l < "$HERE/test_log.txt"); expect=${expect// /}
got=$(python3 "$TOOL" "$HERE/test_log.txt" count 2>&1); rc=$?
if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ] 2>/dev/null; then
note "count test_log.txt = $got (wc -l = $expect)"
else
err "count test_log.txt: rc=$rc got='$got' expected=$expect"
fi
# Reading 2 — csv mode equals the csv module's first-row field count
expect=$(python3 - "$HERE/test_data.csv" <<'PY'
import csv, sys
with open(sys.argv[1], newline='') as f:
print(len(next(csv.reader(f))))
PY
)
got=$(python3 "$TOOL" "$HERE/test_data.csv" csv 2>&1); rc=$?
if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ] 2>/dev/null; then
note "csv test_data.csv = $got (csv module = $expect)"
else
err "csv test_data.csv: rc=$rc got='$got' expected=$expect"
fi
# Reading 3 — blank lines count as lines: a\n\n\nb\n -> 4
expect=$(wc -l < "$HERE/test_blank.txt"); expect=${expect// /}
got=$(python3 "$TOOL" "$HERE/test_blank.txt" count 2>&1); rc=$?
if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ] 2>/dev/null; then
note "count test_blank.txt = $got (wc -l = $expect)"
else
err "count test_blank.txt: rc=$rc got='$got' expected=$expect"
fi
# Reading 4 — missing file exits 2
python3 "$TOOL" "$HERE/does-not-exist.txt" count >/dev/null 2>&1; rc=$?
[ "$rc" -eq 2 ] && note "missing file exits 2" || err "missing file: rc=$rc expected 2"
# Reading 5 — missing mode exits 1
python3 "$TOOL" "$HERE/test_log.txt" >/dev/null 2>&1; rc=$?
[ "$rc" -eq 1 ] && note "missing mode exits 1" || err "missing mode: rc=$rc expected 1"
if [ "$fail" -eq 0 ]; then
echo "VERIFIED: $((5)) reading(s) correct"
exit 0
else
echo "FAILED: line_counter readings incorrect"
exit 1
fi