From cf9db7eaf56da6b2cb559c2af43ee5eaf695352a Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Mon, 16 Nov 2026 02:40:15 -0800 Subject: [PATCH 1/2] Relabel the parity rows that 1.4.0 does not read, and keep the check as a tool A cases.py row's classification defaults to "parity", a claim about 1.4.0 that no test checks. tools/differential/parity_check.py reads every default-config parity row with the 1.4.0 wheel, in a worker hardened as compare.py's is, and lists the rows whose fields 1.4.0 does not give; two planted rows make a run against the tree abort. The suffix is compared by its words, 1.4.0 joining them with ", "; the 91 parity rows carrying a policy or a locale are skipped and counted. It listed 72 of 698 rows. Each is relabelled with the change its reading came from, found by running the release wheels and bisecting in a scratch worktree; five notes claiming parity say what 1.4.0 read. The notes saying "through master" say "through 3.0.1", checked under that wheel, and the Thai rank note gives the reading 1.4.0 and 3.0.1 gave. No expected value changes. AGENTS.md's parity gotcha names the tool and a stale-bytecode trap in bisecting; release step 0 runs it; the differential README describes it. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 6 +- tests/v2/cases.py | 134 ++++++++++--- tests/v2/test_parity_check.py | 197 ++++++++++++++++++ tools/differential/README.md | 25 +++ tools/differential/parity_check.py | 307 +++++++++++++++++++++++++++++ 5 files changed, 636 insertions(+), 33 deletions(-) create mode 100644 tests/v2/test_parity_check.py create mode 100644 tools/differential/parity_check.py diff --git a/AGENTS.md b/AGENTS.md index e9e3e7d19..6b24ff911 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -178,6 +178,10 @@ uv run sphinx-build -b html docs dist/docs # last release's wheel and load each in the tree; don't derive it # from a dataclass diff. 2.7's bullet named Lexicon and Parser and # missed the locale packs, which carry a Lexicon +# Then run `uv run python tools/differential/parity_check.py` and +# relabel every case row it lists: `parity` is cases.py's default, and +# no test checks it against 1.4.0 (Gotchas). 3.1's sweep found 72 +# such rows, 32 of them written that cycle. # And check for open Dependabot PRs on uv.lock (namedivider-python) and merge them # first — pyproject floats >=0.4 so fresh installs get the newest namedivider, but # CI's ja-extra job installs from uv.lock and only tests what the lock pins @@ -337,7 +341,7 @@ The 2.0 rewrite landed as underscore-private modules beside the v1 code, which 2 **Suffix words vs the initial veto** — single-letter roman numeral suffixes (`i`, `v`) are suffix words but also initial-shaped, so `_vocab.is_suffix_strict` (v1's `is_suffix`) vetoes them through `_vocab.is_initial`. `_vocab.is_suffix_lenient` accepts suffix words without the veto and is only safe in unambiguous positions, after a comma (#136, #144). **The veto is Latin-only since #320**: `is_initial` ANDs the bare shape test (`is_initial_shaped`) with "not in a script that writes no initials", the rows of `_policy._SCRIPT_PROPERTIES` whose `writes_initials` is false (Han, Hangul, Hiragana, Katakana, and since #1256 the Myanmar and Thai scripts; decisions/script-properties), so the single-character CJK suffix words (씨, 様, 氏, 군, 양, 님, 殿) written with a period read as suffixes: `"김민준 씨."` gives suffix `씨.`. `V.`/`I.` still lose to the veto and still need the lenient test. -**Comparing against v1 needs `PYTHONSAFEPATH=1` AND a directory outside the worktree** — `uv run --isolated --no-project --with 'nameparser==1.4.0'` still puts the checkout's `nameparser/` ahead of the pinned wheel on `sys.path`, so the "v1" side silently imports the branch and every comparison reports parity. Run it as `cd && PYTHONSAFEPATH=1 uv run --isolated --no-project --with 'nameparser==1.4.0' python -c "..."`. This produces false confidence rather than an error, so it invalidates results without ever looking wrong. **A `tests/v2/cases.py` row's `parity` means 1.4.0, and nothing checks it** -- the table runs every row against the tree, so a row labelled `parity` that only matches master passes for good. #614 added eight such rows, compared against master; #620 found them by running the wheel this way and relabelled each with the change its reading came from, found by `git bisect run` in a scratch worktree (`git worktree add --detach`, never this one). Run the wheel before writing `parity`. +**Comparing against v1 needs `PYTHONSAFEPATH=1` AND a directory outside the worktree** — `uv run --isolated --no-project --with 'nameparser==1.4.0'` still puts the checkout's `nameparser/` ahead of the pinned wheel on `sys.path`, so the "v1" side silently imports the branch and every comparison reports parity. Run it as `cd && PYTHONSAFEPATH=1 uv run --isolated --no-project --with 'nameparser==1.4.0' python -c "..."`. This produces false confidence rather than an error, so it invalidates results without ever looking wrong. **A `tests/v2/cases.py` row's `parity` means 1.4.0, and no test checks it** -- the table runs every row against the tree, so a row labelled `parity` that only matches master passes for good, and `parity` is the dataclass default, so a row written with no `classification` claims it. #614 added eight such rows, compared against master; #620 found them by running the wheel this way and relabelled each with the change its reading came from, found by `git bisect run` in a scratch worktree (`git worktree add --detach`, never this one). 3.1's prose sweep found 72 more, 27 of them #1395's `md_*` rows, and the check is a kept tool since: `uv run python tools/differential/parity_check.py` reads every default-config `parity` row with the 1.4.0 wheel, hardened as `compare.py` is, and lists each row 1.4.0 reads otherwise with its fields (`--check` exits 1 on one). It needs the network or uv's cache, so no CI job runs it, and it skips the rows carrying a policy or a locale, whose `parity` stays unchecked. Run it after adding a row on the default, and relabel what it lists the way #620 did. When bisecting, run Python with `-B` and `git clean -fdx` the scratch tree at each step: two checkouts within one second leave a stale `.pyc` whose source has the same mtime and size, and in 3.1's relabel one answered for two rows, naming a commit whose parent already read them. **A group-side reading of a family comma's given part that asks `tail_reading` disagrees with the given part's own walk, and the disagreement is accepted.** `tail_reading` reads the part as the comma-less name reads it, plus the bare salutations rules/H8 adds after a family comma, which a predictor of this part asks for with `salutations=True` (#835); assign's walk over the given part after a family comma reads by its own predicates -- V before a third comma part is read strictly (#144), staying a name word (`Smith, John van der Berg V, Jr.` reads middle 'van der Berg V'), and P6 attaches a period-marked title-particle (`St.`) the comma-less reading takes as a title. So a bound or a decline group computes with `tail_reading` acts where the walk then reads no title: #623's chain bound (`Smith, John Mc Prof. V, Jr.` → suffix 'Mc, Jr.', middle 'Prof. V') and #637's join decline (`Smith, abdul Prof. V, Jr.` → middle 'Prof. V', `Smith, abdul St.` → family 'St. Smith'); a numeral VI to X was a third such shape until #784 read it as a suffix on both sides. Both were recorded rather than narrowed (Derek: garbage input; decisions/H5 and #P5, rules/P5's Accepted clause). Before writing another group-side predictor of the given part, sweep those two shapes and decide, rather than rediscovering the gap in review. And a change to the trailing peel ITSELF reaches the given part through those predictors without touching them: #718's words-to-spare count for a one-letter numeral, asked through `trailing_run_start`, made the chain take the V in `Smith, Freiherr von Berg V` (given 'von Berg V', unreported) while assign's walk, which never counts there (S4: "read without it"), read it as the suffix -- found by review on a grid of family-comma and empty-head shapes behind a title-particle; the predictor now passes `count_numeral=False`. When a change moves what the peel takes, put a family comma with a title-particle head in its grid. diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 938121ab6..82f30ab75 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -963,22 +963,22 @@ def _check_cjk_shape_purity(self) -> None: "Youssef Ait Haddou", {"given": "Youssef", "family": "Ait Haddou"}, classification="fix(#1249)", - notes="1.4.0 through master read middle 'Ait', family 'Haddou'"), + notes="1.4.0 through 3.0.1 read middle 'Ait', family 'Haddou'"), Case("an_amazigh_ait_with_its_diaeresis_starts_the_family_name", "Karim Aït Haddou", {"given": "Karim", "family": "Aït Haddou"}, classification="fix(#1249)", - notes="1.4.0 through master read middle 'Aït'"), + notes="1.4.0 through 3.0.1 read middle 'Aït'"), Case("an_amazigh_nait_starts_the_family_name", "Leila Nait Haddou", {"given": "Leila", "family": "Nait Haddou"}, classification="fix(#1249)", - notes="1.4.0 through master read middle 'Nait'"), + notes="1.4.0 through 3.0.1 read middle 'Nait'"), Case("an_amazigh_ait_ending_the_given_part_joins_the_family", "Haddou, Youssef Ait", {"given": "Youssef", "family": "Ait Haddou"}, classification="fix(#1249)", - notes="rules/P6's trailing attachment; 1.4.0 through master read " + notes="rules/P6's trailing attachment; 1.4.0 through 3.0.1 read " "middle 'Ait'"), Case("an_amazigh_ait_opening_the_name_folds_it_whole", "Ait Haddou Karim", @@ -986,18 +986,18 @@ def _check_cjk_shape_purity(self) -> None: classification="fix(#1249)", notes="rules/P1's default-order reach, its Accepted cost: a " "listing written family first without a comma; 1.4.0 " - "through master read given 'Ait', middle 'Haddou'"), + "through 3.0.1 read given 'Ait', middle 'Haddou'"), Case("a_hassaniya_ould_starts_the_family_name", "Ahmed Ould Haddou", {"given": "Ahmed", "family": "Ould Haddou"}, classification="fix(#1249)", notes="a patronymic (rules/R9's view reads 'Ould Haddou'); 1.4.0 " - "through master read middle 'Ould'"), + "through 3.0.1 read middle 'Ould'"), Case("an_algerian_ouled_starts_the_family_name", "Karim Ouled Haddou", {"given": "Karim", "family": "Ouled Haddou"}, classification="fix(#1249)", - notes="1.4.0 through master read middle 'Ouled'"), + notes="1.4.0 through 3.0.1 read middle 'Ouled'"), Case("ben_stays_a_middle_name_by_default", "Karim Ben Haddad", {"given": "Karim", "middle": "Ben", "family": "Haddad"}, @@ -1009,12 +1009,12 @@ def _check_cjk_shape_purity(self) -> None: "Karim Ben Haddad", {"given": "Karim", "family": "Ben Haddad"}, locale="ar", classification="feat(#1248)", - notes="1.4.0 through master read middle 'Ben'"), + notes="1.4.0 through 3.0.1 read middle 'Ben'"), Case("the_hebrew_pack_reads_ben_as_the_family", "Yael Ben Arieh", {"given": "Yael", "family": "Ben Arieh"}, locale="he", classification="feat(#1248)", - notes="1.4.0 through master read middle 'Ben'"), + notes="1.4.0 through 3.0.1 read middle 'Ben'"), Case("the_arabic_pack_keeps_ben_opening_a_name_given", "Ben Haddad", {"given": "Ben", "family": "Haddad"}, @@ -1027,7 +1027,7 @@ def _check_cjk_shape_purity(self) -> None: {"given": "Sara", "family": "El Haddou"}, classification="fix(#1240)", notes="the article al is spelled in Morocco and Egypt; 1.4.0 " - "through master read middle 'El'"), + "through 3.0.1 read middle 'El'"), Case("a_maghrebi_el_opening_a_name_is_the_given_name", "El Mehdi Haddou", {"given": "El", "middle": "Mehdi", "family": "Haddou"}, @@ -1041,7 +1041,7 @@ def _check_cjk_shape_purity(self) -> None: classification="fix(#1240)", notes="the accepted cost (rules/P2, decisions/vocabulary-" "collisions 2026-11-12 #1257): the given name is 'Nour El " - "Houda'; 1.4.0 through master read middle 'El Houda'"), + "Houda'; 1.4.0 through 3.0.1 read middle 'El Houda'"), Case("hebrew_ben_opening_a_name_is_the_given_name", "בן כהן", {"given": "בן", "family": "כהן"}, @@ -1053,19 +1053,19 @@ def _check_cjk_shape_purity(self) -> None: "יעל בן חיים", {"given": "יעל", "family": "בן חיים"}, classification="fix(#1210)", - notes="what #1210 changes is the view: 2.0.0 through master read " + notes="what #1210 changes is the view: 2.0.0 through 3.0.1 read " "these fields, 3.0 with the patronymic view filled, which it " "no longer is; 1.4.0 read middle 'בן', last 'חיים'"), Case("hebrew_abu_starts_the_family_name", "סאמי אבו חליל", {"given": "סאמי", "family": "אבו חליל"}, classification="fix(#1211)", - notes="1.4.0 through master read middle 'אבו'"), + notes="1.4.0 through 3.0.1 read middle 'אבו'"), Case("hebrew_al_starts_the_family_name", "נאדר אל חלבי", {"given": "נאדר", "family": "אל חלבי"}, classification="fix(#1211)", - notes="1.4.0 through master read middle 'אל'"), + notes="1.4.0 through 3.0.1 read middle 'אל'"), Case("hebrew_al_opening_a_name_is_the_given_name", "אל כהן", {"given": "אל", "family": "כהן"}, @@ -2828,11 +2828,13 @@ def _check_cjk_shape_purity(self) -> None: "only behind a comma or with a period (H5)"), Case("a_joined_connective_is_no_run", "Josep Carod i Rovira", {"given": "Josep", "family": "Carod i Rovira"}, + classification="fix(#397)", notes="'i' is a suffix word and a connective; a connective " "never starts the run"), Case("a_numeral_the_clause_free_name_reads_ends_the_clause", "John née Jones Smith VI", {"family": "John", "suffix": "VI", "maiden": "Jones Smith"}, + classification="fix(#445)", ambiguities=("suffix-or-name",), notes="#601: the take finds a trailing numeral by the numeral " "fork's SHAPE test, which asks no vocabulary -- 'vi' is in " @@ -2844,6 +2846,7 @@ def _check_cjk_shape_purity(self) -> None: "Jane Doe nee Smith VI Prof.", {"title": "Prof.", "given": "Jane", "family": "Doe", "suffix": "VI", "maiden": "Smith"}, + classification="fix(#535)", ambiguities=("suffix-or-name",), notes="#610: the chain takes 'Prof.' first and leaves 'VI' the " "walk's last piece, so the numeral fork reads it, as in " @@ -2855,6 +2858,7 @@ def _check_cjk_shape_purity(self) -> None: "Jane Doe nee Smith VI Ph. D.", {"given": "Jane", "family": "Doe", "suffix": "VI Ph. D.", "maiden": "Smith"}, + classification="fix(#424)", ambiguities=("suffix-or-name",), notes="#610: the merged 'Ph. D.' is group-flagged and outside the " "peel's walk, so 'VI' is the walk's last piece, as in 'Jane " @@ -3653,6 +3657,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_credential_alone_before_a_comma_is_the_family", "Md, PhD", {"family": "Md", "suffix": "PhD"}, + classification="fix(#296)", notes="rules/C3 boundary: no name word follows the credential, " "so the part is the listing form's one word. 1.4.0 read " "title 'PhD', first 'Md'"), @@ -3684,6 +3689,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_title_particle_before_a_comma_is_still_a_title", "Freiherr von Berg, PhD", {"title": "Freiherr", "family": "von Berg", "suffix": "PhD"}, + classification="fix(#410)", ambiguities=("particle-or-given",), notes="#575 boundary: a word of both the title and the particle " "vocabulary is not a particle to the count before the " @@ -3714,6 +3720,7 @@ def _check_cjk_shape_purity(self) -> None: "van Jr. Berg, Mr.", {"title": "Mr.", "given": "van", "middle": "Jr.", "family": "Berg"}, + classification="fix(comma-family)", ambiguities=("particle-or-given",), notes="#575 boundary: the particle reaches no further than a " "suffix word, so 'van' and 'Berg' are two name words and " @@ -3723,6 +3730,7 @@ def _check_cjk_shape_purity(self) -> None: "Dr. van der Berg, PhD", {"title": "Dr.", "given": "van", "family": "der Berg", "suffix": "PhD"}, + classification="fix(#367)", ambiguities=("particle-or-given",), notes="#575 boundary: the count for an unambiguous credential " "counts the title as a word, so the comma reads as a " @@ -3736,6 +3744,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_leading_title_particle_stays_a_title_before_a_title_only_comma", "St John, Dr.", {"title": "St Dr.", "family": "John"}, + classification="fix(#296)", notes="#575 boundary: 'St' opens the part, so it is the title " "it also is and 'John' alone is the name: two words do " "not stand before the comma, the positional read holds. " @@ -4614,6 +4623,7 @@ def _check_cjk_shape_purity(self) -> None: "John Smith, Jr., Freiherr von Richthofen", {"given": "John", "family": "Smith", "title": "Freiherr", "suffix": "Jr., von Richthofen"}, + classification="fix(#603)", ambiguities=("comma-structure",), notes="the row above as a part past the second comma, which " "is consumed as suffixes but for its title words (C2): " @@ -5403,6 +5413,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_joined_credential_settles_a_bare_ambiguous_chunk", "John Smith, MA/PhD", {"given": "John", "family": "Smith", "suffix": "MA/PhD"}, + classification="fix(#1138)", notes="rules/S3 (#1138): a bare member of the ambiguous class is " "a chunk where a credential that is no name stands beside " "it; 1.4.0 through 2.8.2 reversed the name around it"), @@ -5568,7 +5579,7 @@ def _check_cjk_shape_purity(self) -> None: classification="fix(#1319)", notes="พ.ต.อ is a longer rank, but its last chunk is one letter " "and needs its stop, so the name keeps its อ (the docs " - "review of #1319); 1.4.0 through 3.0.1 read given 'พ.ต.'"), + "review of #1319); 1.4.0 through 3.0.1 read given 'พ.ต.อนุชา'"), Case("thai_initial_glued_to_a_name_is_no_dotted_title", "น.สมชาย ใจดี", {"given": "น.สมชาย", "family": "ใจดี"}, @@ -5595,6 +5606,7 @@ def _check_cjk_shape_purity(self) -> None: Case("dotted_latin_degree_glued_to_an_initial_keeps_the_initial", "Dr.C.Meera Nair", {"title": "Dr.", "given": "C.", "middle": "Meera", "family": "Nair"}, + classification="fix(#1230)", notes="the boundary: a cased title listed with its stops (dr.c) is " "no chunk to T8, decisions/T8's #1305 entry keeping the " "initial; #1319's dotted chunk is a caseless script's"), @@ -5725,6 +5737,7 @@ def _check_cjk_shape_purity(self) -> None: Case("thai_title_licenses_the_bound_given_name_join", "นาย abdul rahman", {"title": "นาย", "given": "abdul rahman"}, + classification="fix(#317)", notes="the bound given-name join a given-name title licenses: " "the pair joins and the name has no family (decisions/W6)"), Case("thai_academic_title_and_one_name_word", @@ -5732,7 +5745,7 @@ def _check_cjk_shape_purity(self) -> None: {"title": "ดร.", "given": "สุดา"}, classification="fix(#317)", notes="a Thai title addresses the given name; 1.4.0 through " - "master read family 'สุดา' (decisions/W6)"), + "3.0.1 read family 'สุดา' (decisions/W6)"), Case("thai_shorter_title_where_the_longer_leaves_no_word", "นางสาวิตรี ใจดี", {"title": "นาง", "given": "สาวิตรี", "family": "ใจดี"}, @@ -5754,6 +5767,7 @@ def _check_cjk_shape_purity(self) -> None: Case("thai_glued_title_peels_only_the_first_word", "ใจดี, ดร.สมชาย นายสมศักดิ์", {"title": "ดร.สมชาย", "given": "นายสมศักดิ์", "family": "ใจดี"}, + classification="fix(#1166)", notes="the boundary: the given part's first word holds a name, " "so the walk stops there and the next word keeps its " "salutation; T8 leaves the word whole after a comma"), @@ -6060,6 +6074,7 @@ def _check_cjk_shape_purity(self) -> None: shape=2), Case("a_glued_honorific_chunk_is_not_ascii", "J.씨", {"given": "J.", "suffix": "씨"}, + classification="fix(#308)", notes="the reason the retirement says ASCII and not just " "single-character: '씨' is one character and MUST keep " "its chunk claim, the honorific peel resting on it", @@ -7294,6 +7309,7 @@ def _check_cjk_shape_purity(self) -> None: "LLOYD WEBBER née Smith, ANDREW PhD", {"given": "ANDREW", "family": "LLOYD WEBBER", "suffix": "PhD", "maiden": "Smith"}, + classification="fix(#274)", notes="#564 boundary: the contrast is the name's OWN words " "(own_words): a maiden clause's lowercase is not the " "name's, so the all-caps record keeps its given name. A " @@ -7703,6 +7719,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_period_marked_dual_opening_a_family_comma_stays_family", "Freiherr. von Berg, Ed", {"given": "Ed", "family": "Freiherr. von Berg"}, + classification="fix(comma-precomma-family)", ambiguities=("suffix-or-name",)), Case("a_dual_second_in_a_title_run_before_a_family_comma_peels", "Hon. Ms Smith, Jane", @@ -7846,6 +7863,7 @@ def _check_cjk_shape_purity(self) -> None: Case("the_comma_count_counts_names_not_words_behind_a_suffix", "Smith Jr, Ma", {"given": "Ma", "family": "Smith", "suffix": "Jr"}, + classification="fix(comma-precomma-family)", ambiguities=("suffix-or-name",), notes="the SUFFIX arm of the same count, and the shape " "decisions/S6 names: 'Smith Jr., MA' is two tokens " @@ -9739,6 +9757,7 @@ def _check_cjk_shape_purity(self) -> None: Case("no_title_stop_before_a_family_comma", "Doe nee Smith Prof., Jane", {"given": "Jane", "family": "Doe", "maiden": "Smith Prof."}, + classification="fix(#274)", notes="before a family comma no trailing rule reads these " "words ('Doe Prof., Jane' keeps family 'Doe Prof.'), so " "there is no chain to consult and the clause keeps the " @@ -10505,7 +10524,7 @@ def _check_cjk_shape_purity(self) -> None: Case("delimiters_keep_the_whole_span_whatever_the_last_word_is", "Jane Doe (nee Smith MA)", {"given": "Jane", "family": "Doe", "maiden": "Smith MA"}, - classification="parity", + classification="fix(#335)", ambiguities=(), notes="rules/M2, the delimited clause: the writer drew " "the boundary and it outranks every reading inside it, " @@ -10513,13 +10532,14 @@ def _check_cjk_shape_purity(self) -> None: "inside the pair is what says the span is a maiden " "clause even where the pair is not in " "`maiden_delimiters`. Unchanged by #533 and by every " - "release before it -- a settled position, not one of " - "the silences about un-asked forks", + "release before it back to 2.2.0 (#335) -- a settled " + "position, not one of the silences about un-asked forks. " + "1.4.0 through 2.1.0 read nickname 'nee Smith MA'", shape=2), Case("delimiters_keep_the_whole_span_in_title_case_too", "Jane Doe (nee Smith Ma)", {"given": "Jane", "family": "Doe", "maiden": "Smith Ma"}, - classification="parity", + classification="fix(#335)", ambiguities=(), notes="the pair for the row above: the two spellings differ " "in everything the lean reads and the delimiters make " @@ -10531,7 +10551,7 @@ def _check_cjk_shape_purity(self) -> None: "Jane Doe (nee Smith) MA", {"given": "Jane", "family": "Doe", "suffix": "MA", "maiden": "Smith"}, - classification="parity", + classification="fix(#335)", notes="the boundary cuts both ways: the span is the maiden name " "whole, and a member the writer left OUTSIDE it is an " "ordinary trailing credential that assign peels, settled by " @@ -11141,7 +11161,7 @@ def _check_cjk_shape_purity(self) -> None: "Juan Garcia Lopez, Sr. y Sra.", {"title": "Sr. Sra.", "given": "y", "family": "Juan Garcia Lopez"}, ambiguities=(), - classification="parity", + classification="fix(#316)", notes="the comma decision joins no title across a lone " "single-letter connective, so the part is no titles-alone " "part and the listing form reads it, P3's count keeping " @@ -11161,7 +11181,7 @@ def _check_cjk_shape_purity(self) -> None: "John Smith, Mr. and", {"title": "Mr. and", "given": "John", "family": "Smith"}, ambiguities=(), - classification="parity", + classification="fix(comma-family)", notes="garbage in: the trailing connective takes its kind from " "the title on its left and joins with nothing on its " "right (2.3.0, 83f4e914 and #617 alike)"), @@ -11210,6 +11230,7 @@ def _check_cjk_shape_purity(self) -> None: Case("a_numeral_behind_a_class_member_keeps_the_listing_form", "John Smith, Ma I", {"given": "Ma", "family": "John Smith", "suffix": "I"}, + classification="fix(comma-precomma-family)", ambiguities=("suffix-or-name", "suffix-or-name"), notes="contrast for the row below: C4's run test admits no " "single-letter numeral, which could be an initial, so " @@ -11428,6 +11449,7 @@ def _check_cjk_shape_purity(self) -> None: Case("only_the_first_suffix_word_can_open_the_comma_part", "Smith, MA PhD Jones", {"given": "MA", "family": "Smith", "suffix": "PhD Jones"}, + classification="fix(#602)", ambiguities=("suffix-or-name", "suffix-or-name"), notes="#603's opener is the part's FIRST suffix word with only " "titles in front of it (rules/C13): 'MA', a member of " @@ -11461,6 +11483,7 @@ def _check_cjk_shape_purity(self) -> None: "Eric H. Holder, Jr. Attorney General", {"title": "Attorney General", "given": "Eric", "middle": "H.", "family": "Holder", "suffix": "Jr."}, + classification="fix(comma-family)", notes="the shape #603 generalizes: a part after the comma " "holding no name word fixed no family boundary, so the " "name before it keeps its positional read and the part " @@ -11911,6 +11934,7 @@ def _check_cjk_shape_purity(self) -> None: "John Smith, Ph. D.; MD", {"title": "Ph.", "given": "D.;", "family": "John Smith", "suffix": "MD"}, + classification="fix(phd-merge)", notes="rules/C10's Accepted bullet: 'Ph.' and 'D.' are one " "credential only as a pair written exactly so, and 'D.;' " "is not the second half of one; 'John Smith, Ph. D. MD' " @@ -12255,6 +12279,7 @@ def _check_cjk_shape_purity(self) -> None: Case("paren_joined_member_chunk_is_the_suffix_after_the_name", "John Smith (MA/PhD)", {"given": "John", "family": "Smith", "suffix": "MA/PhD"}, + classification="fix(#1138)", notes="a joined word holding a member is a member (rules/S3, " "#1138), settled after the name (rules/S13)"), Case("paren_joined_member_chunk_stays_the_nickname_inside_the_name", @@ -12569,6 +12594,7 @@ def _check_cjk_shape_purity(self) -> None: "(#694 review)"), Case("bound_given_completed_before_a_suffix_comma", "طارق عبد العزيز, Jr.", {"given": "طارق", "family": "عبد العزيز", "suffix": "Jr."}, + classification="fix(#694)", notes="#694 review"), Case("bound_given_completed_behind_an_empty_head", ", طارق عبد العزيز", {"given": "طارق", "middle": "عبد العزيز"}, @@ -15642,7 +15668,9 @@ def _check_cjk_shape_purity(self) -> None: Case("family_comma_title_led_run_keeps_the_written_comma", "Smith Jr., Mr. Jr.", {"title": "Mr.", "family": "Smith", "suffix": "Jr., Jr."}, - notes="THE #429 REGRESSION GUARD, and unchanged since 1.4.0. " + classification="fix(comma-family)", + notes="THE #429 REGRESSION GUARD, and unchanged since 2.0.0 " + "(1.4.0 read first 'Jr.', suffix 'Jr.'). " "The pre-comma name leaves a suffix, and the segment " "after the comma is title-led. #429's first draft let " "the title piece OPEN the entry, so the following Jr. " @@ -15653,10 +15681,12 @@ def _check_cjk_shape_purity(self) -> None: "continue an entry"), Case("family_comma_written_commas_are_kept", "Smith, MD, PhD", {"family": "Smith", "suffix": "MD, PhD"}, + classification="fix(#325)", notes="the negative control for #429, and the distinction the " "whole change rests on: the parser renders the run as " "the writer spaced it, and never stops emitting a comma " - "the writer typed. Parity at every baseline"), + "the writer typed. The same at every release from 2.2.0; " + "1.4.0 through 2.1.0 read title 'MD', suffix 'PhD'"), Case("family_comma_run_matches_the_full_name_form", "John Smith, MD PhD", {"given": "John", "family": "Smith", "suffix": "MD PhD"}, notes="the full-name twin of family_comma_suffix_run_renders_" @@ -16130,62 +16160,78 @@ def _check_cjk_shape_purity(self) -> None: "the Except reads past it as past any title and reports"), Case("md_alone_behind_a_title_stays_the_credential", "Smith, Dr. Md", {"title": "Dr.", "family": "Smith", "suffix": "Md"}, + classification="fix(comma-family)", notes="boundary: alone behind a title the given part's walk " "would leave the title as the only name word, so the part " "stays the postnominal one, as on 3dadc263 (#1395's second " "review)"), Case("md_alone_behind_a_salutation_stays_the_credential", "Uddin, Mr Md", {"title": "Mr", "family": "Uddin", "suffix": "Md"}, + classification="fix(comma-family)", notes="boundary, as above"), Case("md_dotted_alone_behind_a_title_stays_the_credential", "Rahman, Mr. Md.", {"title": "Mr.", "family": "Rahman", "suffix": "Md."}, + classification="fix(comma-family)", notes="boundary, as above"), Case("md_alone_behind_mrs_stays_the_credential", "Rahman, Mrs Md", {"title": "Mrs", "family": "Rahman", "suffix": "Md"}, + classification="fix(comma-family)", notes="boundary, as above"), Case("md_behind_a_title_before_a_credential_stays_the_credential", "Uddin, Mr Md PhD", {"title": "Mr", "family": "Uddin", "suffix": "Md PhD"}, + classification="fix(#325)", notes="boundary: a credential behind it is no name word"), Case("md_behind_a_title_before_a_generation_stays_the_credential", "Uddin, Mr Md Jr.", {"title": "Mr", "family": "Uddin", "suffix": "Md Jr."}, + classification="fix(#325)", notes="boundary: a generation behind it is no name word"), Case("md_alone_behind_a_dual_stays_the_credential", "Rahman, Sr Md", {"family": "Rahman", "suffix": "Sr Md"}, + classification="fix(#325)", notes="boundary: as behind a title, a dual reading as nothing " "else there"), Case("md_alone_behind_ms_stays_the_credential", "Rahman, Ms Md", - {"family": "Rahman", "suffix": "Ms Md"}, notes="boundary, as above"), + {"family": "Rahman", "suffix": "Ms Md"}, + classification="fix(#325)", notes="boundary, as above"), Case("md_title_case_before_a_credential_stays_the_credential", "Smith, Md PhD", {"family": "Smith", "suffix": "Md PhD"}, + classification="fix(#325)", notes="boundary: its own writing settles it only alone in the " "part; a credential behind it is no name word"), Case("md_title_case_before_a_capitals_word_stays_the_credential", "Smith, Md XYZ", {"family": "Smith", "suffix": "Md XYZ"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="boundary: in mixed case a word in capitals may be a " "credential, so it is no name word"), Case("md_before_a_gated_title_stays_the_credential", "SMITH, MD SHEIKH", {"family": "SMITH", "suffix": "MD SHEIKH"}, + classification="fix(#752)", ambiguities=("suffix-or-name",), notes="boundary: a word with a title reading, a title only " "inside a phrase included, is no name word"), Case("md_before_dean_stays_the_credential", "SMITH, MD DEAN", {"family": "SMITH", "suffix": "MD DEAN"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="boundary, as above"), Case("md_dotted_in_one_case_alone_stays_the_credential", "rahman, md.", {"family": "rahman", "suffix": "md."}, + classification="fix(#296)", notes="boundary: a name in one case writes no case that tells"), Case("md_before_a_word_holding_no_letter_stays_the_credential", "RAHMAN, MD 2", {"family": "RAHMAN", "suffix": "MD 2"}, + classification="fix(#325)", notes="boundary: a word with no letter is no name word"), Case("md_before_a_conjunction_stays_the_credential", "Rahman, Md and Karim", {"family": "Rahman", "suffix": "Md and Karim"}, + classification="fix(#853)", ambiguities=("suffix-or-name", "suffix-or-name"), notes="boundary: a conjunction behind it is no name word, so the " "part reads as on 3dadc263 (#1395's third review)"), Case("md_before_a_gated_title_in_mixed_case_stays_the_credential", "Rahman, Md Sheikh Karim", {"family": "Rahman", "suffix": "Md Sheikh Karim"}, + classification="fix(#752)", ambiguities=("suffix-or-name", "suffix-or-name"), notes="Accepted (rules/C13): a word with a title reading of any " "kind is no name word, a title only inside a phrase " @@ -16193,9 +16239,11 @@ def _check_cjk_shape_purity(self) -> None: "shape (2026-11-14)"), Case("md_before_dean_in_mixed_case_stays_the_credential", "Rahman, Md Dean", {"family": "Rahman", "suffix": "Md Dean"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="Accepted, as above"), Case("md_before_a_name_in_capitals_in_mixed_case_stays_the_credential", "Rahman, Md KARIM", {"family": "Rahman", "suffix": "Md KARIM"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="Accepted (rules/C13): in mixed case a word in capitals " "may be a credential, so it is no name word; read as on " @@ -16203,36 +16251,44 @@ def _check_cjk_shape_purity(self) -> None: "given 'Md', middle 'KARIM' (decisions/C13, 2026-11-14)"), Case("md_before_abdul_in_capitals_in_mixed_case_stays_the_credential", "Rahman, Md ABDUL", {"family": "Rahman", "suffix": "Md ABDUL"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="Accepted, as above"), Case("a_given_name_written_short_that_is_no_credential_reports_nothing", "Smith, Wm Jones", {"given": "Wm", "middle": "Jones", "family": "Smith"}, + classification="fix(#789)", notes="the Except reads a credential only; `wm` spells none, so " "no suffix-or-name report"), Case("md_in_capitals_alone_after_a_family_comma_is_the_credential", "RAHMAN, MD", {"family": "RAHMAN", "suffix": "MD"}, + classification="fix(#296)", notes="boundary: capitals alone are the degree's writing, " "which 107 ClinicalTrials.gov officials write after one " "word ('Novak, MD'), so Muhammad written so is left " "(decisions/indic-honorifics, 2026-11-14)"), Case("md_in_one_case_alone_after_a_family_comma_is_the_credential", "rahman, md", {"family": "rahman", "suffix": "md"}, + classification="fix(#296)", notes="boundary: a name in one case writes no lower-case " "letter that tells"), Case("md_before_a_credential_after_a_family_comma_is_the_credential", "Smith, MD PhD", {"family": "Smith", "suffix": "MD PhD"}, + classification="fix(#325)", notes="boundary: a credential behind it is no name word"), Case("md_before_a_split_credential_is_the_credential", "Smith, MD Ph. D.", {"family": "Smith", "suffix": "MD Ph. D."}, + classification="fix(#325)", notes="boundary: half of a split credential is no name word " "(rules/S12)"), Case("md_before_a_capitals_word_in_mixed_case_is_the_credential", "Smith, MD XYZ", {"family": "Smith", "suffix": "MD XYZ"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="boundary: a word in capitals in a name of mixed case " "may be a credential, so it is no name word"), Case("md_before_an_ambiguous_credential_is_the_credential", "SMITH, MD MBA, JANE", {"family": "SMITH", "suffix": "MD MBA, JANE"}, + classification="fix(#325)", ambiguities=("comma-structure", "suffix-or-name"), notes="boundary: a credential that may be a name ('MBA') is no " "name word behind it; FEC writes the degrees between the " @@ -16248,11 +16304,13 @@ def _check_cjk_shape_purity(self) -> None: "(decisions/indic-honorifics, 2026-11-14)"), Case("md_behind_a_titled_surname_is_the_credential", "Dr. Rahman, Md", {"title": "Dr.", "family": "Rahman", "suffix": "Md"}, + classification="fix(#410)", notes="boundary: a title is a word to the whole-name count " "(rules/C3), so the part is the postnominal one"), Case("md_behind_a_two_word_surname_is_the_credential", "Rahman Khan, Md Abdul", {"given": "Rahman", "family": "Khan", "suffix": "Md Abdul"}, + classification="fix(#853)", ambiguities=("suffix-or-name",), notes="boundary: two words before the comma are a whole name, " "and C13's run stands, as for 'John Smith, PhD Jones'"), @@ -16736,6 +16794,7 @@ def _check_cjk_shape_purity(self) -> None: notes="H9: a style before the word is its partner"), Case("contested_title_after_a_comma_in_capitals", "John Smith, DEAN", {"given": "John", "family": "Smith", "suffix": "DEAN"}, + classification="fix(#564)", ambiguities=("suffix-or-name",), notes="H9: outside a phrase the word reads as the " "unlisted word it was, which rules/C6 reads as a " @@ -16846,6 +16905,7 @@ def _check_cjk_shape_purity(self) -> None: "H6's peel read title 'Wing', family 'Smith'"), Case("modifier_in_a_comma_part", "John Smith, Vice", {"title": "Vice", "given": "John", "family": "Smith"}, + classification="fix(comma-family)", notes="H9: after a comma a modifier reads as any title " "does, the part being the person's role (decision 10 " "measured 247 of 367 ctgov comma-part moves reversing the " @@ -16865,6 +16925,7 @@ def _check_cjk_shape_purity(self) -> None: Case("given_name_modifier_before_its_head_in_a_comma_part", "Lau, Wing Commander", {"title": "Wing Commander", "family": "Lau"}, + classification="fix(comma-family)", notes="H9's boundary: the head title follows, after a comma too"), Case("given_name_modifier_after_a_full_name_and_comma", "John Smith, Wing", {"given": "Wing", "family": "John Smith"}, classification="fix(#752)", @@ -16882,6 +16943,7 @@ def _check_cjk_shape_purity(self) -> None: Case("given_name_modifier_before_a_dotted_suffix", "John Smith Wing. Jr.", {"title": "Wing.", "given": "John", "family": "Smith", "suffix": "Jr."}, + classification="fix(#316)", notes="H9's Accepted clause: H2's shape reads the period-marked " "suffix as a head in the run, as master read it; an " "unmarked 'MD' behind gives family 'Wing.' (#752 phase 2j)"), @@ -17325,11 +17387,13 @@ def _check_cjk_shape_purity(self) -> None: Case("princess_royal_behind_a_style", "Her Royal Highness Princess Royal Anne", {"title": "Her Royal Highness Princess Royal", "given": "Anne"}, + classification="fix(#913)", notes="H9: 'princess' attaches to 'royal', so the modifier behind " "its head is in its phrase (#913); read given 'Royal', " "family 'Anne' 2.7.0"), Case("royal_title_phrase_queen_mother", "Queen Mother Elizabeth", {"title": "Queen Mother", "given": "Elizabeth"}, + classification="fix(#489)", notes="H9: 'queen' attaches to 'mother'; 2.7.0 read it so, #926 " "given 'Queen', middle 'Mother', and 1.4.0 last " "'Elizabeth'"), @@ -17545,11 +17609,13 @@ def _check_cjk_shape_purity(self) -> None: notes="H9: 'saint' attaches to 'pope', a title after it (#913)"), Case("given_name_modifier_after_a_style", "Hon. Wing Lau", {"title": "Hon.", "given": "Wing", "family": "Lau"}, + classification="fix(#752)", notes="H9: the modifier's test, not a contested word's style " "partner, decides 'wing'; 'Hon. Dean Smith' reads the title"), Case("given_name_modifier_before_a_salutation_in_a_comma_part", "LAU, WING MR", {"title": "WING MR", "family": "LAU"}, + classification="fix(comma-family)", notes="H9: the modifier test takes any title after it as its " "head, a salutation too, so 'WING MR' stays a title where " "'DEAN MR' gives given 'DEAN'; no FEC donor writes it " @@ -17568,6 +17634,7 @@ def _check_cjk_shape_purity(self) -> None: "modifier after them has no head (the code review)"), Case("role_word_in_a_comma_part", "John Smith, Resident", {"title": "Resident", "given": "John", "family": "Smith"}, + classification="fix(comma-family)", notes="resident is an occupation since 2026-10-25, not a " "modifier: a part written 'Resident' is the role"), Case("bare_salutation_ending_a_family_comma_given_part", @@ -18833,17 +18900,19 @@ def _check_cjk_shape_purity(self) -> None: Case("ja_combining_voicing_mark_on_hiragana_stays_hiragana", "あ゙い たろう", {"family": "あ゙い", "given": "たろう"}, - notes="parity row: on hiragana the mark's base is hiragana, so " - "the name is wholly hiragana and reads family-first as it " - "always has. Guards the alternative #596 declined -- " + classification="fix(#272)", + notes="on hiragana the mark's base is hiragana, so the name is " + "wholly hiragana and reads family-first as it has since " + "2.1.0 (1.4.0 read first 'あ゙い', last 'たろう'). Guards the alternative #596 declined -- " "taking the marks out of the hiragana range would leave " "あ゙い in no script and the name positional"), Case("ja_combining_voicing_mark_kanji_katakana_licensed", "山田 ア゙イ", {"family": "山田", "given": "ア゙イ"}, - notes="parity row: kanji plus katakana is the kana license " - "whatever the katakana's mark does, so the name stays " - "family-first. Under the declined alternative ア゙イ " + classification="fix(#272)", + notes="kanji plus katakana is the kana license whatever the " + "katakana's mark does, so the name stays family-first, as " + "since 2.1.0 (1.4.0 read first '山田', last 'ア゙イ'). Under the declined alternative ア゙イ " "would have no script, the license would not fire, and " "the name would read family ア゙イ"), Case("ko_voicing_mark_after_hangul_stays_undivided", "김\u3099민준", @@ -20491,6 +20560,7 @@ def _check_cjk_shape_purity(self) -> None: "Willem Jacob 's Gravesande", {"given": "Willem", "middle": "Jacob", "family": "'s Gravesande"}, + classification="fix(#1241)", notes="'s (des) is listed beside 't (nl.toml), so it chains " "into the surname and opens no quote; 1.4.0 through " "3.0.1 read middle \"Jacob 's\", family 'Gravesande', " diff --git a/tests/v2/test_parity_check.py b/tests/v2/test_parity_check.py new file mode 100644 index 000000000..e404d4a06 --- /dev/null +++ b/tests/v2/test_parity_check.py @@ -0,0 +1,197 @@ +"""Unit tests for parity_check.py, the 1.4.0 check of the case table's +`parity` rows. + +Nothing here spawns `uv` or reaches the network: the baseline is a +stub reading each text as a table says, so what is tested is the +mapping from a row to 1.4.0's attributes, the comparison, the report, +and the planted rows that make a run unable to report nothing when its +baseline is not 1.4.0. The run against the real wheel is the tool's +own, and needs the network or uv's cache. +""" +from dataclasses import dataclass, field +from collections.abc import Callable, Mapping, Sequence + +import pytest + +from ._differential_fixtures import load_tool + +parity = load_tool("parity_check") + + +@dataclass(frozen=True) +class _Case: + """The fields of tests/v2/cases.py's Case the tool reads.""" + id: str + text: str + expect: dict[str, str] + classification: str = "parity" + policy: object = None + locale: str | None = None + notes: str = field(default="") + + +def _v1(**fields: str) -> dict[str, str]: + """A 1.4.0 reading keyed by its attribute names, from field names.""" + return {parity.FIELDS[f]: v for f, v in fields.items()} + + +#: 1.4.0's readings by text: the planted rows' text read as 1.4.0 reads it. +_READS = {"John Smith": _v1(given="John", family="Smith")} + + +def _stub(reads: Mapping[str, dict[str, str]] + ) -> Callable[[Sequence[str]], list[dict[str, str]]]: + def read(texts: Sequence[str]) -> list[dict[str, str]]: + return [dict(reads[t]) for t in texts] + return read + + +def test_every_field_maps_to_the_attribute_1_4_0_reads_it_from() -> None: + """given and family are 1.4.0's first and last; the rest keep their + names, maiden included, which 1.4.0's HumanName has.""" + got = parity.from_v1({"title": "Dr.", "first": "Jane", "middle": "Q.", + "last": "Doe", "suffix": "Jr.", "nickname": "J", + "maiden": "Smith"}) + assert got == {"title": "Dr.", "given": "Jane", "middle": "Q.", + "family": "Doe", "suffix": "Jr.", "nickname": "J", + "maiden": "Smith"} + + +def test_a_missing_attribute_reads_empty() -> None: + assert parity.from_v1({"first": "Jane"})["maiden"] == "" + + +def test_selection_skips_a_policy_or_locale_row_and_ignores_other_kinds() -> None: + rows, skipped = parity.select([ + _Case("plain", "John Smith", {"given": "John"}), + _Case("policy", "John Smith", {"given": "John"}, policy=object()), + _Case("locale", "John Smith", {"given": "John"}, locale="ru"), + _Case("fixed", "John Smith", {"given": "John"}, classification="fix(#1)"), + ]) + assert [r.id for r in rows] == ["plain"] + assert skipped == ["policy", "locale"] + assert rows[0].expect == {"title": "", "given": "John", "middle": "", + "family": "", "suffix": "", "nickname": "", + "maiden": ""} + + +@pytest.mark.parametrize("want,have", [ + ("PhD I.", "PhD, I."), + ("Jr., MD", "Jr., MD"), + ("vd Jr", "vd, Jr"), +]) +def test_a_suffix_differing_only_by_its_commas_is_the_same_reading( + want: str, have: str) -> None: + row = parity.Row("r", "x", {**dict.fromkeys(parity.FIELDS, ""), "suffix": want}) + assert parity.differ(row, {**dict.fromkeys(parity.FIELDS, ""), "suffix": have}) == {} + + +@pytest.mark.parametrize("want,have", [ + ("VI Ph. D.", "Ph. D., VI"), # reordered + ("PhD Jones", "PhD"), # a word left out + ("MD, PhD", "PhD"), +]) +def test_a_suffix_with_other_words_or_order_differs(want: str, have: str) -> None: + row = parity.Row("r", "x", {**dict.fromkeys(parity.FIELDS, ""), "suffix": want}) + got = {**dict.fromkeys(parity.FIELDS, ""), "suffix": have} + assert parity.differ(row, got) == {"suffix": (want, have)} + + +def test_commas_count_in_every_other_field() -> None: + row = parity.Row("r", "x", {**dict.fromkeys(parity.FIELDS, ""), "family": "Smith"}) + got = {**dict.fromkeys(parity.FIELDS, ""), "family": "Smith,"} + assert parity.differ(row, got) == {"family": ("Smith", "Smith,")} + + +def test_a_row_1_4_0_reads_otherwise_is_reported_with_its_fields() -> None: + cases = [ + _Case("agrees", "Jane Doe", {"given": "Jane", "family": "Doe"}), + _Case("disagrees", "Doe, Jane MD", {"given": "Jane", "family": "Doe", + "suffix": "MD"}), + _Case("switched", "Doe, Jane MD", {"given": "Jane"}, policy=object()), + ] + reads = {**_READS, + "Jane Doe": _v1(given="Jane", family="Doe"), + "Doe, Jane MD": _v1(given="Jane", middle="MD", family="Doe")} + result = parity.check(cases, _stub(reads)) + assert [m.row.id for m in result.mismatches] == ["disagrees"] + assert result.mismatches[0].fields == {"middle": ("", "MD"), + "suffix": ("MD", "")} + assert result.compared == 2 and result.skipped == ("switched",) + source = 'x\n Case("agrees", ...\n Case("disagrees", ...\n' + assert parity.report(result, source) == [ + "cases.py:3 disagrees 'Doe, Jane MD'", + " middle: expected '', 1.4.0 'MD'", + " suffix: expected 'MD', 1.4.0 ''", + "1 of 2 parity rows read otherwise under 1.4.0", + "1 parity rows carrying a policy or a locale skipped: 1.4.0 has " + "no Policy to read them under", + ] + + +def test_a_baseline_reading_as_the_table_expects_aborts() -> None: + """The harness proof: a baseline answering from the tree reads + every row as the table says, the planted wrong row included, so + the run would report no mismatch at all. The planted row is what + turns that into an abort.""" + cases = [_Case("row", "Jane Doe", {"given": "Jane", "family": "Doe"})] + + def as_expected(texts: Sequence[str]) -> list[dict[str, str]]: + expect = {c.text: c.expect for c in cases} + planted = iter(parity._PLANTED.values()) + return [_v1(**(expect[t] if t in expect else next(planted))) + for t in texts] + with pytest.raises(SystemExit, match="planted rows came back wrong"): + parity.check(cases, as_expected) + + +def test_a_baseline_reading_nothing_aborts() -> None: + """The converse: a baseline returning empty readings reports every + row, the planted match included.""" + with pytest.raises(SystemExit, match="planted rows came back wrong"): + parity.check([], lambda texts: [{} for _ in texts]) + + +def test_a_baseline_returning_too_few_readings_aborts() -> None: + with pytest.raises(SystemExit, match="readings for"): + parity.check([], lambda texts: []) + + +def test_a_planted_wrong_parity_row_in_the_table_is_reported() -> None: + """A row planted into the table, wrongly labelled parity, comes out + of a run against a stub that reads as 1.4.0 does.""" + cases = [_Case("planted", "Smith, John Jr", {"given": "John", + "family": "Smith Jr"})] + reads = {**_READS, + "Smith, John Jr": _v1(given="John", family="Smith", suffix="Jr")} + result = parity.check(cases, _stub(reads)) + assert [m.row.id for m in result.mismatches] == ["planted"] + + +def test_the_worker_pins_the_wheel_and_reads_every_field() -> None: + source = parity.worker_source("1.4.0") + assert 'dependencies = ["nameparser==1.4.0"]' in source + assert repr(tuple(parity.FIELDS.values())) in source + + +def test_the_worker_runs_with_no_import_path_overrides( + monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("PYTHONPATH", "/somewhere") + monkeypatch.setenv("PYTHONHOME", "/elsewhere") + env = parity.worker_env(parity._compare()) + assert "PYTHONPATH" not in env and "PYTHONHOME" not in env + assert env["PYTHONSAFEPATH"] == "1" + + +def test_check_exits_nonzero_only_when_asked( + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None: + """--check turns a mismatch into exit 1; without it the run exits 0.""" + found = parity.Result((parity.Mismatch(parity.Row("r", "x", {}), + {"given": ("a", "b")}),), 1, ()) + monkeypatch.setattr(parity, "check", lambda cases, read: found) + assert parity.main([]) == 0 + assert parity.main(["--check"]) == 1 + monkeypatch.setattr(parity, "check", + lambda cases, read: parity.Result((), 1, ())) + assert parity.main(["--check"]) == 0 + capsys.readouterr() diff --git a/tools/differential/README.md b/tools/differential/README.md index 124e2774d..cb6af67ef 100644 --- a/tools/differential/README.md +++ b/tools/differential/README.md @@ -122,6 +122,31 @@ release *and* the module loaded from outside the repository. package, and strips `PYTHONPATH` from the worker's environment. The traps below are why. +### The case table's parity rows + +``` +uv run python tools/differential/parity_check.py [--check] +``` + +A row of `tests/v2/cases.py` whose `classification` is `parity`, the +default, claims that 1.4.0 read its text as the row expects, and the +suite, which runs every row against the tree, never checks that. +`parity_check.py` reads each such row's text with the 1.4.0 wheel's +`HumanName`, in a worker hardened as `compare.py`'s is (generated into +a temporary folder, `PYTHONPATH` stripped, `PYTHONSAFEPATH=1`, the +version and path tell checked by `compare.py`'s own `_check_tell`), and +lists the rows whose seven fields 1.4.0 does not give, with both values. +The suffix is compared by its words, since 1.4.0 joins a suffix of +several words with ", " where the tree keeps the separators written; +a row carrying a policy or a locale is skipped and counted, 1.4.0 +having no `Policy` to read it under. Every run also reads two planted +rows, one 1.4.0 gives and one it does not, and aborts unless only the +second is reported, so a worker that answered from the tree cannot +report a clean table. It exits 0 unless `--check` is passed and a row is +listed; `--cases PATH` reads another copy of the table. On 2026-11-16 +it listed 72 of 698 rows, which the sweep that followed relabelled with +the change each reading came from, and 0 of 626 after. + ## The three invocation traps None of the three below is hypothetical -- the second was reproduced diff --git a/tools/differential/parity_check.py b/tools/differential/parity_check.py new file mode 100644 index 000000000..e807595af --- /dev/null +++ b/tools/differential/parity_check.py @@ -0,0 +1,307 @@ +"""The case table's `parity` rows against the released 1.4.0 wheel. + + uv run python tools/differential/parity_check.py [--check] [--cases PATH] + +A row of tests/v2/cases.py whose `classification` is "parity" (the +dataclass default) claims that nameparser 1.4.0 read its text as the +row expects. The suite runs every row against the TREE, so nothing +there checks that claim, and a row written against master and left on +the default passes for good (root AGENTS.md, Gotchas). This reads each +such row's text with 1.4.0's `HumanName`, installed fresh from PyPI +into a temporary folder, and lists the rows whose expected fields +1.4.0 does not give, with the field, the expected value and 1.4.0's. + +What it compares, exactly: + +- The seven fields, mapped from 1.4.0's attributes: title, given + (`first`), middle, family (`last`), suffix, nickname and maiden. A + field the row does not list is expected empty, as the suite reads + it. Nothing else: not ambiguities, which 1.4.0 has none of, nor + `initials()` or the case views. +- The suffix by its words, in order, with the commas between them + dropped on both sides. 1.4.0 renders a suffix of several words joined + with ", " (`PhD, I.`) where the tree keeps the separators written in + the name (`PhD I.`); the same words in the same order are the same + reading, and a separator is how it renders. A word moved into or out + of the suffix, or reordered, still counts. +- Only the rows with neither a `policy` nor a `locale`. 1.4.0 has no + `Policy`, so no switch on a row has a counterpart there to translate + into; every such parity row is skipped, and the report gives their + count. Such a row's `parity` stays unchecked here. + +The rows are loaded from the cases file (by path: it is not +importable as a module of a package), and 1.4.0 is read in a child +process, generated into a temporary folder outside the checkout and +run by `uv run --no-project` with PYTHONPATH and PYTHONHOME stripped and +PYTHONSAFEPATH=1, which aborts unless the child reports version 1.4.0 +from a file outside the checkout (compare.py's `_check_tell`). A child +answering from the tree would read every row as the suite does, and the +run would report no mismatch -- the null result a broken harness and a +clean table share. So every run also reads two planted rows: one whose +expectation 1.4.0 gives and one whose expectation it does not, and +aborts unless exactly the second is reported. + +It needs the network or uv's cache for the wheel, so it is no CI test; +tests/v2/test_parity_check.py tests the mapping, the comparison and the +report against a stubbed baseline. It exits 0 whatever it finds, and 1 +on a mismatch with --check. +""" +from __future__ import annotations + +import argparse +import importlib.util +import json +import subprocess +import sys +import tempfile +from collections.abc import Callable, Iterable, Mapping, Sequence +from dataclasses import dataclass +from pathlib import Path +from types import ModuleType +from typing import Any + +HERE = Path(__file__).resolve().parent +REPO_ROOT = HERE.parents[1] +CASES = REPO_ROOT / "tests" / "v2" / "cases.py" +BASELINE = "1.4.0" + +#: The case table's fields, in Role order, each with 1.4.0's attribute. +FIELDS = {"title": "title", "given": "first", "middle": "middle", + "family": "last", "suffix": "suffix", "nickname": "nickname", + "maiden": "maiden"} + +#: The two rows every run reads beside the table's (ids no row can +#: take, being no identifier): 1.4.0 reads `John Smith` given 'John', +#: family 'Smith', so the first must match and the second be reported. +PLANTED_MATCH = "" +PLANTED_WRONG = "" +_PLANTED = {PLANTED_MATCH: {"given": "John", "family": "Smith"}, + PLANTED_WRONG: {"given": "Smith", "family": "John"}} +_PLANTED_TEXT = "John Smith" + + +@dataclass(frozen=True) +class Row: + """A parity row as compared: its id, text and expected fields, the + seven of them, empty where the row lists none.""" + id: str + text: str + expect: Mapping[str, str] + + +@dataclass(frozen=True) +class Mismatch: + row: Row + #: field -> (expected, 1.4.0's), for each field that differs + fields: Mapping[str, tuple[str, str]] + + +@dataclass(frozen=True) +class Result: + mismatches: tuple[Mismatch, ...] + compared: int + #: ids of the parity rows carrying a policy or a locale + skipped: tuple[str, ...] + + +def load_cases(path: Path = CASES) -> ModuleType: + """tests/v2/cases.py, loaded by path. Registered in sys.modules + before it runs, since @dataclass looks its module up there.""" + name = "parity_check_cases" + spec = importlib.util.spec_from_file_location(name, path) + assert spec is not None and spec.loader is not None, path + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + return module + + +def select(cases: Iterable[Any]) -> tuple[list[Row], list[str]]: + """The parity rows 1.4.0 can be asked about, and the ids of those + it cannot: a row with a policy or a locale (the docstring says + why). A row of any other classification is neither.""" + rows: list[Row] = [] + skipped: list[str] = [] + for case in cases: + if case.classification != "parity": + continue + if case.policy is not None or case.locale is not None: + skipped.append(case.id) + continue + rows.append(Row(case.id, case.text, + {f: case.expect.get(f, "") for f in FIELDS})) + return rows, skipped + + +def from_v1(reading: Mapping[str, str]) -> dict[str, str]: + """A 1.4.0 reading, keyed by its attribute names, as the seven + fields; an attribute the reading lacks is empty.""" + return {field: reading.get(attr, "") or "" for field, attr in FIELDS.items()} + + +def suffix_words(text: str) -> tuple[str, ...]: + """A suffix as its words in order, the commas between them dropped: + `PhD, I.` and `PhD I.` are one reading (the docstring says why).""" + return tuple(w for w in (w.strip(",") for w in text.split()) if w) + + +def differ(row: Row, got: Mapping[str, str]) -> dict[str, tuple[str, str]]: + """Each field whose expected value 1.4.0's reading `got` (the seven + fields) does not give, with both values.""" + out = {} + for field in FIELDS: + want, have = row.expect[field], got.get(field, "") + same = (suffix_words(want) == suffix_words(have) if field == "suffix" + else want == have) + if not same: + out[field] = (want, have) + return out + + +#: Reads texts and returns one 1.4.0 reading (keyed by its attribute +#: names) per text, in order: run_baseline, or a test's stub. +Reader = Callable[[Sequence[str]], list[dict[str, str]]] + + +def check(cases: Iterable[Any], read: Reader) -> Result: + """Every parity row of `cases` that 1.4.0 can be asked about, read + by `read`, with the planted rows; aborts unless the planted rows + come back as planted -- the match matching and the wrong one + reported -- since otherwise a run reporting nothing proves nothing.""" + rows, skipped = select(cases) + planted = [Row(i, _PLANTED_TEXT, {f: e.get(f, "") for f in FIELDS}) + for i, e in _PLANTED.items()] + every = rows + planted + readings = read([r.text for r in every]) + if len(readings) != len(every): + raise SystemExit(f"the baseline returned {len(readings)} readings " + f"for {len(every)} texts; aborted") + found = [] + for row, reading in zip(every, readings): + if (fields := differ(row, from_v1(reading))): + found.append(Mismatch(row, fields)) + reported = {m.row.id for m in found} & set(_PLANTED) + if reported != {PLANTED_WRONG}: + raise SystemExit( + f"the planted rows came back wrong (reported: " + f"{sorted(reported) or 'none'}; expected only " + f"{PLANTED_WRONG!r}): the baseline is not reading as 1.4.0 " + f"does, so its answer for the table proves nothing. Aborted.") + return Result(tuple(m for m in found if m.row.id not in _PLANTED), + len(rows), tuple(skipped)) + + +_WORKER = '''\ +# /// script +# requires-python = ">=3.9" +# dependencies = ["nameparser==@@VERSION@@"] +# /// +"""GENERATED by tools/differential/parity_check.py. Prints a version +tell, then one 1.4.0 reading per input line (a JSON string).""" +import json +import sys + +import nameparser +from nameparser import HumanName + +print(json.dumps({"__version__": nameparser.__version__, + "__file__": nameparser.__file__}), flush=True) +ATTRS = @@ATTRS@@ +for line in sys.stdin: + if not line.strip(): + continue + name = HumanName(json.loads(line)) + print(json.dumps({a: getattr(name, a, "") or "" for a in ATTRS}, + ensure_ascii=False), flush=True) +''' + + +def worker_source(version: str = BASELINE) -> str: + return (_WORKER.replace("@@VERSION@@", version) + .replace("@@ATTRS@@", repr(tuple(FIELDS.values())))) + + +def _compare() -> ModuleType: + """compare.py beside this file, loaded by path for its version tell + and its child environment, so the two harnesses hold one check.""" + spec = importlib.util.spec_from_file_location( + "parity_check_compare", HERE / "compare.py") + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def worker_env(compare: ModuleType) -> dict[str, str]: + """compare.py's child environment (PYTHONPATH and PYTHONHOME + stripped), with PYTHONSAFEPATH=1 so the script's own folder is not + on the path either.""" + env: dict[str, str] = compare._worker_env() + env["PYTHONSAFEPATH"] = "1" + return env + + +def run_baseline(texts: Sequence[str], + version: str = BASELINE) -> list[dict[str, str]]: + """Each text read by the released `version`'s HumanName, in a child + run from a temporary folder outside the checkout; aborts unless the + child reports that version from outside the checkout.""" + compare = _compare() + with tempfile.TemporaryDirectory() as tmp: + script = Path(tmp) / "parity_worker.py" + script.write_text(worker_source(version), encoding="utf-8") + proc = subprocess.run( + ["uv", "run", "--no-project", str(script)], + input="".join(json.dumps(t, ensure_ascii=False) + "\n" + for t in texts), + capture_output=True, text=True, cwd=tmp, env=worker_env(compare)) + if proc.returncode != 0: + raise SystemExit(f"the {version} worker exited {proc.returncode}; " + f"aborted\n{proc.stderr}") + lines = proc.stdout.split("\n") + lines = [line for line in lines if line.strip()] + if not lines: + raise SystemExit(f"the {version} worker printed nothing; aborted") + compare._check_tell(json.loads(lines[0]), version) + return [json.loads(line) for line in lines[1:]] + + +def _line_of(row_id: str, source: str) -> int: + """The line of `source` that first names `row_id` in quotes, or 0.""" + at = source.find(f'"{row_id}"') + return source.count("\n", 0, at) + 1 if at >= 0 else 0 + + +def report(result: Result, source: str = "") -> list[str]: + """The run's report: each mismatching row with its line in the cases + file (`source`), text and fields, then the counts.""" + out = [] + for m in result.mismatches: + line = _line_of(m.row.id, source) + where = f"cases.py:{line} " if line else "" + out.append(f"{where}{m.row.id} {m.row.text!r}") + for field, (want, have) in m.fields.items(): + out.append(f" {field}: expected {want!r}, {BASELINE} {have!r}") + out.append(f"{len(result.mismatches)} of {result.compared} parity rows " + f"read otherwise under {BASELINE}") + if result.skipped: + out.append(f"{len(result.skipped)} parity rows carrying a policy or " + f"a locale skipped: {BASELINE} has no Policy to read " + f"them under") + return out + + +def main(argv: Sequence[str] | None = None) -> int: + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument("--check", action="store_true", + help="exit 1 when a parity row reads otherwise") + ap.add_argument("--cases", type=Path, default=CASES, metavar="PATH", + help="the cases file (default tests/v2/cases.py)") + args = ap.parse_args(argv) + result = check(load_cases(args.cases).CASES, run_baseline) + print("\n".join(report(result, args.cases.read_text(encoding="utf-8")))) + return 1 if args.check and result.mismatches else 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From 124dffce0f86b1cb02d29daeb5f181758aedeec9 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Mon, 16 Nov 2026 02:48:44 -0800 Subject: [PATCH 2/2] Absorb only the suffix's ", " join, and say what the delimiter row's label names parity_check's suffix comparison stripped commas from both ends of every word, so a trailing comma in one suffix and not the other went unnoticed; it now reads each ", " join as a space and keeps every other comma in its word, with test rows for a trailing comma and an unspaced one. The tool still reports 0 of 626 and the planted row. suffix_delimiter_core_between_entries_is_a_boundary claimed parity under a fix(#436/#437) label: 1.4.0, with CONSTANTS.suffix_delimiter set to its counterpart, and every release from 2.0.0 read its fields, so the note says the label names the change the row guards. Co-Authored-By: Claude Opus 5.5 --- tests/v2/cases.py | 6 +++++- tests/v2/test_parity_check.py | 3 +++ tools/differential/parity_check.py | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 82f30ab75..2dda28ac2 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -11816,7 +11816,11 @@ def _check_cjk_shape_purity(self) -> None: "and the entry the writer drew ends at each of them. " "The core is gone before the render sees it, so the " "boundary is read off the dropped indices rather than " - "off a surviving token. Parity at every baseline"), + "off a surviving token. The classification names the " + "change this row guards, not a change in its reading: " + "1.4.0, with its counterpart CONSTANTS.suffix_delimiter " + "= ' | ', and every release from 2.0.0 read these " + "fields"), Case("suffix_delimiter_core_parts_a_connective_join", "Doe, John, PhD | and MD", {"given": "John", "family": "Doe", "suffix": "PhD, and MD"}, diff --git a/tests/v2/test_parity_check.py b/tests/v2/test_parity_check.py index e404d4a06..228395179 100644 --- a/tests/v2/test_parity_check.py +++ b/tests/v2/test_parity_check.py @@ -90,6 +90,9 @@ def test_a_suffix_differing_only_by_its_commas_is_the_same_reading( ("VI Ph. D.", "Ph. D., VI"), # reordered ("PhD Jones", "PhD"), # a word left out ("MD, PhD", "PhD"), + ("Jr.,", "Jr."), # a trailing comma is no join + ("Jr.", "Jr.,"), + ("MD,PhD", "MD PhD"), # nor a comma with no space after it ]) def test_a_suffix_with_other_words_or_order_differs(want: str, have: str) -> None: row = parity.Row("r", "x", {**dict.fromkeys(parity.FIELDS, ""), "suffix": want}) diff --git a/tools/differential/parity_check.py b/tools/differential/parity_check.py index e807595af..54264588d 100644 --- a/tools/differential/parity_check.py +++ b/tools/differential/parity_check.py @@ -18,11 +18,13 @@ field the row does not list is expected empty, as the suite reads it. Nothing else: not ambiguities, which 1.4.0 has none of, nor `initials()` or the case views. -- The suffix by its words, in order, with the commas between them - dropped on both sides. 1.4.0 renders a suffix of several words joined - with ", " (`PhD, I.`) where the tree keeps the separators written in - the name (`PhD I.`); the same words in the same order are the same - reading, and a separator is how it renders. A word moved into or out +- The suffix with its ", " joins read as spaces on both sides, and + nothing else of its punctuation dropped. 1.4.0 renders a suffix of + several words joined with ", " (`PhD, I.`) where the tree keeps the + separators written in the name (`PhD I.`); the same words in the same + order are the same reading, and a separator is how it renders. A + comma that ends a word in only one of them (`Jr.,` against `Jr.`) is + no join, and counts. A word moved into or out of the suffix, or reordered, still counts. - Only the rows with neither a `policy` nor a `locale`. 1.4.0 has no `Policy`, so no switch on a row has a counterpart there to translate @@ -140,9 +142,11 @@ def from_v1(reading: Mapping[str, str]) -> dict[str, str]: def suffix_words(text: str) -> tuple[str, ...]: - """A suffix as its words in order, the commas between them dropped: - `PhD, I.` and `PhD I.` are one reading (the docstring says why).""" - return tuple(w for w in (w.strip(",") for w in text.split()) if w) + """A suffix as its words in order, each ", " join read as a space: + `PhD, I.` and `PhD I.` are one reading (the docstring says why), + while a comma ending the suffix, or a word not followed by a space + (`Jr.,`, `MD,PhD`), stays part of its word.""" + return tuple(text.replace(", ", " ").split()) def differ(row: Row, got: Mapping[str, str]) -> dict[str, tuple[str, str]]: