Agent Zero AI framework
fix(files): name single-folder downloads after the folder
GreifMax17f06bfcdcf5
diff --git a/helpers/file_browser.py b/helpers/file_browser.pyindex 6ad3d5c43..914b5e5cd 100644--- a/helpers/file_browser.py+++ b/helpers/file_browser.py@@ -532,7 +532,9 @@ def prepare_files_download(paths, current_path=""):except BaseException:Path(path).unlink(missing_ok=True)raise- name = posixpath.basename(paths[0]) if single else selected_archive_name(len(paths))+ name = posixpath.basename(paths[0]) if single else (+ f"{posixpath.basename(paths[0])}.zip" if len(paths) == 1 else selected_archive_name(len(paths))+ )temporary = Trueelif len(paths) == 1 and Path(paths[0]).is_file():import stat@@ -557,7 +559,10 @@ def prepare_files_download(paths, current_path=""):temporary = Trueelse:path = create_selected_zip(paths, current_path, limit, FileBrowser.max_archive_entries())- name = selected_archive_name(len(paths))+ name = (+ f"{Path(paths[0]).name}.zip" if len(paths) == 1+ else selected_archive_name(len(paths))+ )temporary = Truereturn {"file_source": path, "download_name": name, "max_bytes": limit, "delete_after": temporary}diff --git a/helpers/file_browser.py.dox.md b/helpers/file_browser.py.dox.mdindex f7f954a58..99cdc4041 100644--- a/helpers/file_browser.py.dox.md+++ b/helpers/file_browser.py.dox.md@@ -58,7 +58,7 @@No child DOX files.-`read_text` owns bounded local Editor reads. `encode_upload` bounds the development RFC adapter. `prepare_files_download` owns Files routing and policy; `register_files_download` rechecks remote permission at delivery. API handlers do not select byte limits. Generic attachment/Connector downloads remain separate.+`read_text` owns bounded local Editor reads. `encode_upload` bounds the development RFC adapter. `prepare_files_download` owns Files routing and policy; a single selected directory downloads as `<folder>.zip` while true multi-selections keep the timestamped `agent-zero-selected-<count>-<stamp>.zip` archive name. `register_files_download` rechecks remote permission at delivery. API handlers do not select byte limits. Generic attachment/Connector downloads remain separate.Destructive entry operations resolve parent directories while preserving the final symlink. Delete/Rename operate on the link itself; empty/root targets are rejected in the shared helper. Local Files downloads stage a bounded snapshot and reject in-place source changes during preparation. Cancelled preparation closes late responses and their temporary descriptors.diff --git a/tests/test_download_folder_naming.py b/tests/test_download_folder_naming.pynew file mode 100644index 000000000..c09053901--- /dev/null+++ b/tests/test_download_folder_naming.py@@ -0,0 +1,34 @@+from pathlib import Path+import zipfile++from helpers.file_browser import prepare_files_download+++def test_single_folder_download_is_named_after_the_folder(tmp_path: Path) -> None:+ folder = tmp_path / "my-folder"+ folder.mkdir()+ (folder / "file.txt").write_text("content", encoding="utf-8")++ # A single selected folder downloads as <folder>.zip, not the generic+ # agent-zero-selected-<count>-<stamp>.zip archive name.+ download = prepare_files_download([str(folder)], current_path=str(tmp_path))+ try:+ assert download["download_name"] == "my-folder.zip"+ assert zipfile.is_zipfile(download["file_source"])+ finally:+ Path(download["file_source"]).unlink(missing_ok=True)+++def test_multi_selection_download_keeps_generic_archive_name(tmp_path: Path) -> None:+ one = tmp_path / "one.txt"+ two = tmp_path / "two.txt"+ one.write_text("1", encoding="utf-8")+ two.write_text("2", encoding="utf-8")++ download = prepare_files_download([str(one), str(two)], current_path=str(tmp_path))+ try:+ # True multi-selections keep the timestamped generic archive name.+ assert download["download_name"].startswith("agent-zero-selected-2-")+ assert download["download_name"].endswith(".zip")+ finally:+ Path(download["file_source"]).unlink(missing_ok=True)