fix(14.2): WR-08 request record check reads the whole log tail

tail | grep -q under pipefail refused a long go.log that had records: grep
stopped at the first match and tail died of SIGPIPE. Count the matches
instead. New self-test case: a 20000-line log after an early record.
This commit is contained in:
2026-10-12 12:05:07 +02:00
parent f70a0a59d6
commit a082a0583d

View File

@@ -200,7 +200,9 @@ scan_go_log() {
echo "refuse: Go log $file not found" >&2
return 1
}
if ! tail -c "+$((offset + 1))" "$file" | grep -q 'msg="http request"'; then
# grep reads the whole tail (-c, not -q): an early exit would end tail
# with SIGPIPE, which pipefail turns into a false refusal.
if [[ "$(tail -c "+$((offset + 1))" "$file" | grep -c 'msg="http request"' || true)" == 0 ]]; then
echo "refuse: $file has no http request record from this run; set SUMMER_HTTP__ACCESS_LOG=true in the env file" >&2
return 1
fi
@@ -388,6 +390,11 @@ run_self_test() {
expect_status go-log-old-records 1 scan_go_log "$dir/old-records.log" "$(stat -c '%s' "$dir/clean.log")"
cat "$dir/no-records.log" "$dir/clean.log" >"$dir/new-records.log"
expect_status go-log-new-records 0 scan_go_log "$dir/new-records.log" "$(stat -c '%s' "$dir/no-records.log")"
# A long log after an early record: the search for it must not fail when
# it stops reading early (SIGPIPE under pipefail).
cp "$dir/clean.log" "$dir/long.log"
python3 -c 'import sys; sys.stdout.write("[go] level=INFO msg=\"http request\" method=GET pattern=\"GET /a\" status=200 duration_ms=1\n" * 20000)' >>"$dir/long.log"
expect_status go-log-long 0 scan_go_log "$dir/long.log"
printf '# tests 9\n# pass 9\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n' >"$dir/tap-clean"
printf '# tests 9\n# pass 8\n# fail 1\n# cancelled 0\n# skipped 0\n# todo 0\n' >"$dir/tap-fail"
printf '# tests 9\n# pass 8\n# fail 0\n# cancelled 0\n# skipped 1\n# todo 0\n' >"$dir/tap-skip"