From 8ae94ade19fa35fc36104d37e2324816d0fbb0d9 Mon Sep 17 00:00:00 2001 From: BukeLy Date: Tue, 26 May 2026 16:21:57 +0800 Subject: [PATCH] fix(filesystem): render root folder path correctly --- pageindex/filesystem/commands.py | 8 ++++++-- tests/test_pifs_find_maxdepth.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pageindex/filesystem/commands.py b/pageindex/filesystem/commands.py index d56df79..6615da2 100644 --- a/pageindex/filesystem/commands.py +++ b/pageindex/filesystem/commands.py @@ -817,16 +817,20 @@ class PIFSCommandExecutor: if data and isinstance(data[0], dict) and "path" in data[0] and "file_ref" not in data[0]: return "\n".join( ( - f"{item['path']}/ matched_files={item['matched_files']} " + f"{self._folder_row_path(item['path'])} matched_files={item['matched_files']} " f"files={item.get('file_count', 0)}" if item.get("matched_files") - else f"{item['path']}/ folders={item.get('children_count', 0)} " + else f"{self._folder_row_path(item['path'])} folders={item.get('children_count', 0)} " f"files={item.get('file_count', 0)}" ) for item in data ) return "\n".join(self._file_row_text(item) for item in data) + def _folder_row_path(self, path: str) -> str: + normalized = self._normalize_folder_path(path) + return "/" if normalized == "/" else f"{normalized}/" + def _render_stat(self, data: Any) -> str: if not isinstance(data, dict): return str(data) diff --git a/tests/test_pifs_find_maxdepth.py b/tests/test_pifs_find_maxdepth.py index 580633e..8a7fe50 100644 --- a/tests/test_pifs_find_maxdepth.py +++ b/tests/test_pifs_find_maxdepth.py @@ -106,6 +106,17 @@ def test_find_maxdepth_zero_type_directory_returns_start_folder(tmp_path): assert [row["path"] for row in rows] == ["/documents"] +def test_find_directory_output_renders_root_without_double_slash(tmp_path): + executor = _register_find_fixture(tmp_path) + executor.json_output = False + + output = executor.execute("find / -maxdepth 1 -type d") + + assert output.splitlines()[0] == "/ folders=1 files=0" + assert "//" not in output + assert "/documents/ folders=1 files=1" in output + + def test_find_maxdepth_combines_with_where_and_limit(tmp_path): executor = _register_find_fixture(tmp_path)