Skip to content

fix: preflight.py totals-row label anchored to cell start - #129

Merged
svedbg merged 1 commit into
mainfrom
fix/preflight-totals-label
Sep 6, 2026
Merged

svedbg merged 1 commit into
mainfrom
fix/preflight-totals-label

Conversation

@svedbg

@svedbg svedbg commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

Found auditing a real payroll: TOTALS_LABEL was anchored (^\s*(...)), so a totals row labelled "Report Total in EUR (from 24 records):" - where "Total" isn't the first word - was never recognised. data_range() then included the totals row as a 25th data row, and audit.py raised a nonsensical B4_cap_from_wrong_period on it (the sum of everyone's insurable income, always "over" the per-person cap).

No suite caught this because every generated fixture's totals row starts with the label word - the bug only shows up on real-world label formats, which is exactly why I added a hand-built (not generated) regression case with three label variants, including the real one.

Broadened the pattern to also match English "total" and changed the match to search the whole cell instead of anchoring to its start.

Test plan

  • verified against the real file that caused it: totals row now detected, false B4 gone
  • new hand-built test case in preflight_test.py, proved it fails without the fix and passes with it
  • full free battery (pre-commit hook ran all 5 suites + k_checker + audit checker)

🤖 Generated with Claude Code

https://claude.ai/code/session_01XvbzEbQwxwxxHAtXfPMrno

… cell

Found auditing a real payroll, not by any suite here: its export's
totals row was labelled "Report Total in EUR (from 24 records):" -
"Total" is not the first word, and TOTALS_LABEL was anchored with ^,
so the row was never recognised as the totals row. data_range() then
included it as a 25th data row. The visible symptom was audit.py
raising B4_cap_from_wrong_period on that row: the sum of every real
person's insurable income, compared against the per-person cap and
always "over" it - a nonsensical finding against nobody, not a
crash, so nothing about it demanded attention.

Every generated fixture's totals row starts with the label word
(test/generate_shapes.py, checks_test.py's static fixture), which is
exactly why this went unnoticed by 300-seed runs across five suites:
none of them vary where the label word sits in the cell.

Broadened TOTALS_LABEL to also match English "total" as a whole word,
and changed the match to search the whole cell instead of anchoring
to its start - a label can now say "общо", "total" or "grand total"
anywhere in the cell, not just first. Added a hand-built regression
case (not generated, for the same reason the bug wasn't caught) with
three label variants, including the exact real-world shape. Proved it
fails without the fix and passes with it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvbzEbQwxwxxHAtXfPMrno
@svedbg
svedbg merged commit 07bf2e9 into main Sep 6, 2026
12 checks passed
@svedbg
svedbg deleted the fix/preflight-totals-label branch September 6, 2026 14:41
@svedbg svedbg mentioned this pull request Sep 6, 2026
svedbg added a commit that referenced this pull request Sep 6, 2026
Version bump for PR #129 (already on main): TOTALS_LABEL now matches
"total" anywhere in the cell, not only at its start, fixing a real
false-positive B4 finding on a totals row whose label didn't begin
with the recognised word. Touches shipped code (scripts/preflight.py).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvbzEbQwxwxxHAtXfPMrno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant