fix: preflight.py totals-row label anchored to cell start - #129
Merged
Merged
Conversation
… 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
Merged
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Found auditing a real payroll:
TOTALS_LABELwas 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, andaudit.pyraised a nonsensicalB4_cap_from_wrong_periodon 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
preflight_test.py, proved it fails without the fix and passes with it🤖 Generated with Claude Code
https://claude.ai/code/session_01XvbzEbQwxwxxHAtXfPMrno