Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(tests): count only the base side of the index gap (#3628)
Swati Ahuja92f365b45514
diff --git a/packages/core/src/repowise/core/analysis/changed_lines.py b/packages/core/src/repowise/core/analysis/changed_lines.pyindex b181a549d..f6185a85f 100644--- a/packages/core/src/repowise/core/analysis/changed_lines.py+++ b/packages/core/src/repowise/core/analysis/changed_lines.py@@ -460,17 +460,19 @@ def is_shallow_root(repo_path: str, rev: str) -> bool:def index_gap(repo_path: str, indexed_commit: str | None, change: ChangeSet) -> list[str] | None:- """Files outside *change* that differ between *indexed_commit* and its base.+ """Files outside *change* that its base changed and *indexed_commit* lacks.- What an index built at another commit cannot see. Empty when the index was- built at either end of the change; ``None`` when that cannot be told (no- recorded commit, no base, or a commit this clone lacks).+ What an index built at another commit cannot see. Only the base's side+ counts (``indexed...base``, from their merge-base), so an index built after+ the base is never said to predate it. Empty when the index was built at+ either end of the change or later; ``None`` when that cannot be told (no+ recorded commit, no base, a commit this clone lacks, or no merge-base)."""if indexed_commit and indexed_commit in (change.base, change.head):return []if not indexed_commit or not change.base:return None- args = ["diff", "--name-only", "-z", "--no-renames", indexed_commit, change.base]+ args = ["diff", "--name-only", "-z", "--no-renames", f"{indexed_commit}...{change.base}"]try:listing = _git(args, repo_path)except (subprocess.SubprocessError, OSError):diff --git a/tests/unit/analysis/test_changed_lines.py b/tests/unit/analysis/test_changed_lines.pyindex 8bad613f6..bceff208d 100644--- a/tests/unit/analysis/test_changed_lines.py+++ b/tests/unit/analysis/test_changed_lines.py@@ -354,3 +354,40 @@ def test_index_gap_names_what_an_older_index_cannot_see(git_repo) -> None:assert index_gap(str(git_repo), _sha(git_repo, "HEAD~1"), change) == []assert index_gap(str(git_repo), None, change) is Noneassert index_gap(str(git_repo), "0" * 40, change) is None+++def test_index_gap_is_empty_when_the_index_is_ahead_of_the_change(git_repo) -> None:+ from repowise.core.analysis.changed_lines import change_set, index_gap+ from repowise.core.analysis.test_selection import TestSelectionConfig, plan_gap++ (git_repo / "mod.py").write_text("a = 9\nb = 2\nc = 3\n", encoding="utf-8")+ _git(git_repo, "commit", "-qam", "reviewed change")+ change = change_set(str(git_repo), "HEAD~1..HEAD")+ (git_repo / "pyproject.toml").write_text("[project]\n", encoding="utf-8")+ (git_repo / "later.py").write_text("x = 1\n", encoding="utf-8")+ _git(git_repo, "add", "-A")+ _git(git_repo, "commit", "-qm", "after the review")++ # Indexed later: what the base lacks is not something the index lacks.+ gap = index_gap(str(git_repo), _sha(git_repo, "HEAD"), change)+ assert gap == []+ assert plan_gap(gap, TestSelectionConfig()).reasons == ()+++def test_index_gap_on_a_sibling_branch_counts_only_the_base_side(git_repo) -> None:+ from repowise.core.analysis.changed_lines import change_set, index_gap++ fork = _sha(git_repo, "HEAD")+ (git_repo / "indexed_only.py").write_text("i = 1\n", encoding="utf-8")+ _git(git_repo, "add", "-A")+ _git(git_repo, "commit", "-qm", "indexed side")+ indexed = _sha(git_repo, "HEAD")+ _git(git_repo, "checkout", "-qb", "review", fork)+ (git_repo / "base_only.py").write_text("b = 1\n", encoding="utf-8")+ _git(git_repo, "add", "-A")+ _git(git_repo, "commit", "-qm", "base side")+ (git_repo / "mod.py").write_text("a = 9\nb = 2\nc = 3\n", encoding="utf-8")+ _git(git_repo, "commit", "-qam", "change")++ change = change_set(str(git_repo), "HEAD~1..HEAD")+ assert index_gap(str(git_repo), indexed, change) == ["base_only.py"]