fix(tree): derive common directory root from file parents in build_tree
This commit is contained in:
1 parent
6c8002eca4
commit
96fcb3b54e
2 files changed
+9
-1
No files matched your search
@@ -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]
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in new issue
Block a user