From: Shane Jaroch Date: Thu, 22 Jan 2026 23:05:35 +0000 (-0500) Subject: wip non-determinism in make test/offline X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=307ba3b31c48897e2b61e3c0b51cca0bc23d4346;p=gamesguru%2Fgetmyancestors.git wip non-determinism in make test/offline --- diff --git a/getmyancestors/mergemyanc.py b/getmyancestors/mergemyanc.py index 0d5b7c2..0db1724 100755 --- a/getmyancestors/mergemyanc.py +++ b/getmyancestors/mergemyanc.py @@ -109,13 +109,28 @@ def main( ged = Gedcom(file, tree) - # Deduplicate names by string representation + # Deduplicate names by string representation (deterministic: first alphabetically wins) def merge_names(target_set, source_set): - existing_names = {str(n) for n in target_set} - for n in source_set: - if str(n) not in existing_names: + # Combine all names and sort deterministically + all_names = list(target_set) + list(source_set) + all_names.sort(key=lambda x: ( + str(x), + x.given or "", + x.surname or "", + x.prefix or "", + x.suffix or "", + x.kind or "", + str(x.alternative) if hasattr(x, 'alternative') else "", + x.note.text if hasattr(x, 'note') and x.note else "", + )) + # Rebuild target_set keeping first occurrence by string + target_set.clear() + seen = set() + for n in all_names: + s = str(n) + if s not in seen: target_set.add(n) - existing_names.add(str(n)) + seen.add(s) # Helper for whitespace normalization in quotes def norm_space(s): diff --git a/tests/fixtures.env b/tests/fixtures.env index a1d4c9b..26b2813 100644 --- a/tests/fixtures.env +++ b/tests/fixtures.env @@ -4,4 +4,4 @@ # and should be updated whenever fixtures are regenerated. export EXPECTED_ADA_LINES=11587 export EXPECTED_MARIE_LINES=3698 -export EXPECTED_MERGED_LINES=14481 +export EXPECTED_MERGED_LINES=14483 diff --git a/tests/offline_test.py b/tests/offline_test.py index f97151b..34e268d 100644 --- a/tests/offline_test.py +++ b/tests/offline_test.py @@ -301,11 +301,15 @@ def test_offline(): else: print(f"✓ Marie Curie (Part 2) lines verified ({l_part2}).") - if l_merged != exp_merged: - print(f"❌ Assertion Failed: Merged line count {l_merged} != {exp_merged}") + # Check merged file with exact diff (no line count tolerance) + diff_result = subprocess.run( + ["git", "diff", "--no-index", "--exit-code", "--color=always", str(merged), str(ARTIFACTS_DIR / "merged_scientists.ged")], + ) + if diff_result.returncode != 0: + print(f"❌ Merged file differs from artifact (see diff above)") failed = True else: - print(f"✓ Merged lines verified ({l_merged}).") + print(f"✓ Merged file matches artifact exactly ({l_merged} lines).") if failed: sys.exit(1)