From 31150d1307071d897f6542daaef708dd560dd291 Mon Sep 17 00:00:00 2001 From: Vasily Ilin Date: Thu, 28 May 2026 06:03:08 -0700 Subject: [PATCH] Handle empty files in partial port audit --- python/lean_pool/partial_port_audit.py | 2 ++ python/tests/test_partial_port_audit.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/python/lean_pool/partial_port_audit.py b/python/lean_pool/partial_port_audit.py index 428fa8f0cb..81ea0e9b9c 100644 --- a/python/lean_pool/partial_port_audit.py +++ b/python/lean_pool/partial_port_audit.py @@ -334,6 +334,8 @@ def evaluate_stats( imported_by_path.setdefault(normalize_relative_path(file.path), []).append(file) truncated_files = [] for file in sorted(upstream.files, key=lambda item: item.loc, reverse=True): + if file.loc == 0: + continue matching_imports = imported_by_path.get(normalize_relative_path(file.path), []) if not matching_imports: continue diff --git a/python/tests/test_partial_port_audit.py b/python/tests/test_partial_port_audit.py index b209a0517b..3a30b8ba60 100644 --- a/python/tests/test_partial_port_audit.py +++ b/python/tests/test_partial_port_audit.py @@ -184,6 +184,24 @@ def test_evaluate_stats_flags_truncated_matched_file() -> None: ) +def test_evaluate_stats_ignores_zero_loc_files_for_truncation() -> None: + """Empty upstream files do not cause a divide-by-zero during comparison.""" + imported = LeanStats( + ( + LeanFile("LeanPool/Foo/Empty.lean", 0, "empty"), + LeanFile("LeanPool/Foo/Main.lean", 1000, "main"), + ) + ) + upstream = LeanStats( + ( + LeanFile("Foo/Empty.lean", 0, "empty"), + LeanFile("Foo/Main.lean", 1000, "main"), + ) + ) + + assert evaluate_stats("LeanPool.Foo", "owner/foo", imported, upstream) is None + + def test_evaluate_stats_accepts_close_import() -> None: """A near-complete import passes the tolerance check.""" imported = LeanStats((LeanFile("LeanPool/Foo/Main.lean", 920, "main"),))