fix(tree): derive common directory root from file parents in build_tree

(cherry picked from commit 96fcb3b54e)
This commit is contained in:
Aditya kumar singh authored and safishamsi committed 2026-11-09 14:09:25 +00:00
1 parent d63d41165b
commit 8a5756266a
2 files changed
+9 -1

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ DEFAULT_MAX_CHILDREN = 200
def _common_root(paths: List[str]) -> str:
if not paths:
return ""
parts = [Path(p).parts for p in paths if p]
parts = [Path(p).parent.parts for p in paths if p]
if not parts:
return ""
common = parts[0]
+8
View File
@@ -94,6 +94,14 @@ def test_build_tree_default_root_keeps_hierarchy():
assert "a.py" in names and "sub" in names
def test_build_tree_single_file_common_root_is_directory():
graph = _graph({"pkg/a.py": "func_a"})
tree = build_tree(graph)
assert tree["name"] == "pkg"
assert [c["name"] for c in tree["children"]] == ["a.py"]
assert [c["name"] for c in tree["children"][0]["children"]] == ["func_a"]
def _merged_graph(per_repo: dict[str, dict[str, str]]) -> dict:
"""Node-link graph shaped like a merge-graphs result: every node is
repo-tagged and keeps its repo-relative source_file."""