Skip to content

test(experts): pin every entry of the number-word and month-name tables - #504

Merged
kevincostner17 merged 1 commit into
mainfrom
test/lookup-tables
Sep 28, 2026
Merged

kevincostner17 merged 1 commit into
mainfrom
test/lookup-tables

Conversation

@kevincostner17

Copy link
Copy Markdown
Contributor

Why

Mutation testing of semantic/experts.py left 98 numeric-constant survivors. Classified by syntactic context, only 7 are operands of a comparison — the thresholds a mutation brief usually cares about. 45 are dict values, and they are two lookup tables:

  • the spelled-number map (_ONES / _TENS / _BIG), used by parse_number_words
  • the month-name map (_MONTHS), used by _resolve_date

Only 10 of the 30 number words appeared anywhere in tests/, and no month name did, so changing "seven": 7 to 8 or "march": 3 to 4 broke nothing.

Neither table is wrong today. The gap is that a typo in either would ship as a wrong value, silently: spelled numbers converting to the wrong integers, or "14 March 2021" written as April 14th and reported as an unambiguous, low-risk, auto-appliable repair.

What

tests/test_lookup_tables.py — 91 tests, test-only:

  • every number word → its own value; every scale word, bare and with a count
  • every tens word composed with every unit, spaced and hyphenated
  • every month name, in both orderings the pattern accepts, and upper-case
  • a month-name date is never reported ambiguous and ignores dayfirst
  • an unknown token or month name still makes the whole phrase a non-match

Every expectation is written out literally. Deriving it from the table under test would make the test agree with any table, including a broken one.

Verification

  • 91 passed on py3.12 / pandas 2.3.3 and py3.9 / pandas 1.5.3
  • 238 passed on each of 5 pytest-randomly seeds together with test_experts_date_mutants.py and test_semantic_cleaning.py
  • Five table entries corrupted by hand (seven, march, ninety, thousand, dec) — each is caught
  • Rebased onto Add synthetic financial ledger fixture with accounting negatives (#496) #503, which changed experts.py but not the tables; re-verified there

Mutation testing of semantic/experts.py left 98 numeric survivors. Sorted by
syntactic context, only 7 are comparison operands; 45 are dict values, and
those are two lookup tables -- the spelled-number map (_ONES/_TENS/_BIG) and
the month-name map (_MONTHS). Only 10 of the 30 number words appeared
anywhere in tests/, and the month names not at all, so "seven": 7 -> 8 or
"march": 3 -> 4 broke nothing.

Neither table is wrong today. The gap is that a typo in either would ship as
a wrong value, silently: spelled numbers converting to the wrong integers,
or "14 March 2021" written as April 14th and reported as a low-risk,
auto-appliable repair.

Every expectation is written out literally; deriving it from the table under
test would make the test agree with any table, including a broken one.
Verified by corrupting five entries by hand ("seven", "march", "ninety",
"thousand", "dec"): each is caught.
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 28c0863f-daca-4966-8a4f-bd90be7970da


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kevincostner17
kevincostner17 merged commit 65a954a into main Sep 28, 2026
19 checks passed
kevincostner17 added a commit that referenced this pull request Sep 28, 2026
…509)

A fresh mutation measurement of semantic/experts.py (267 sites, rebuilt and
re-validated harness) left 95 subset survivors. All 95 were re-run against
the full suite: 47 were killed (every one a number/month table entry pinned
by #504), 48 survived. Each survivor was then checked for observability --
original and mutant run on the same input -- before any test was written.

13 are real gaps, now each killed only by its dedicated test here:
- an unbalanced "(1,200" read as the accounting negative -1.2
- a one-unit debit "($1.00)" read as 0.0; "($0.00)" as -0.0 or 0.05
- malformed grouping accepted: "$1,2,345" -> 12345, "$,123" -> 123
- a bare "hundred" defaulting to 200
- leading-zero identifier veto checking the wrong character: "05" and
  "0123" lost protection, "10" gained it (tests only ever used "007")
- valid ISO dates rewritten to timestamps beside an unresolvable value
- the partial-date review guess becoming year 0003
- resolver and expert base confidences above 1.0 (hidden by the
  downstream 0.999 clamp), pinned as a [0, 1] invariant, not a literal

10 are equivalent and carry exhaustive executable proofs (three reuse the
existing date-branch proof). 22 are in-range confidence/evidence literals,
deliberately not pinned: pinning a literal is change-detection, and a
decision/risk fingerprint found no change on them (on a corpus whose low
sensitivity was measured, so this is not claimed as equivalence).

Every mutant classified equivalent was run against this file and leaves it
passing: no false kills. No source-text tripwires: the harness writes mutants
through ast.unparse, which reformats the file, so such tests fail on every
mutant and would corrupt future mutation scores.

53 tests; py3.12 and py3.9; 334 passed under each of 5 random orderings with
the neighbouring experts tests; full suite green on both interpreters.
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