diff --git a/src/github_repo_auditor/portfolio_truth_reconcile.py b/src/github_repo_auditor/portfolio_truth_reconcile.py index 78b266f..9c7cd61 100644 --- a/src/github_repo_auditor/portfolio_truth_reconcile.py +++ b/src/github_repo_auditor/portfolio_truth_reconcile.py @@ -155,7 +155,7 @@ def _derive_readme_char_count(project_path: Path | None, has_git: bool) -> int: if candidate.is_file(): return len(candidate.read_text(errors="replace")) # Case-insensitive fallback - for candidate in project_path.iterdir(): + for candidate in sorted(project_path.iterdir(), key=lambda item: item.name): if candidate.is_file() and candidate.name.lower().startswith("readme"): return len(candidate.read_text(errors="replace")) return 0 diff --git a/tests/test_fallback_readme_order.py b/tests/test_fallback_readme_order.py new file mode 100644 index 0000000..60bad43 --- /dev/null +++ b/tests/test_fallback_readme_order.py @@ -0,0 +1,12 @@ +from github_repo_auditor.portfolio_truth_reconcile import _derive_readme_char_count + + +def test_fallback_readme_selection_is_independent_of_directory_order( + tmp_path, monkeypatch +): + first, second = tmp_path / "README.en", tmp_path / "README.fr" + first.write_text("first") + second.write_text("second") + for order in ([first, second], [second, first]): + monkeypatch.setattr(type(tmp_path), "iterdir", lambda self: iter(order)) + assert _derive_readme_char_count(tmp_path, has_git=True) == len("first")