mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-05 01:48:44 +00:00
The File Browser's selected-files download flow zips any selection that is not a single file and always applies the generic agent-zero-selected-<count>-<stamp>.zip archive name, so downloading one folder produced agent-zero-selected-1-<date>-<time>.zip instead of <folder>.zip. Name single-directory downloads after the folder in both the local and remote branches of prepare_files_download; true multi-selections keep the timestamped generic name. Add regression tests for both cases.
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
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)
|