Agent Zero AI framework
fix(api): align downloads with file browser root
Alessandrod541a942b089
diff --git a/api/download_work_dir_file.py b/api/download_work_dir_file.pyindex 034156389..69980abc1 100644--- a/api/download_work_dir_file.py+++ b/api/download_work_dir_file.py@@ -87,8 +87,8 @@ def make_disposition(download_name: str) -> str:def resolve_download_path(path: str) -> str:- """Resolve a requested download path and keep it within the runtime base dir."""- base_dir = Path(files.get_base_dir()).resolve()+ """Resolve a requested download path from the File Browser root."""+ base_dir = Path("/")candidate = Path(path)if candidate.is_absolute():diff --git a/api/download_work_dir_file.py.dox.md b/api/download_work_dir_file.py.dox.mdindex 87085765a..f92c584cf 100644--- a/api/download_work_dir_file.py.dox.md+++ b/api/download_work_dir_file.py.dox.md@@ -17,7 +17,7 @@- Top-level functions:- `stream_file_download(file_source, download_name, chunk_size=...)`: Create a streaming response for file downloads that shows progress in browser.- `make_disposition(download_name: str) -> str`-- `resolve_download_path(path: str) -> str`: Resolve a requested download path and keep it within the runtime base dir.+- `resolve_download_path(path: str) -> str`: Resolve a requested download path from the File Browser root.- `async fetch_file(path)`## Runtime Contracts@@ -27,6 +27,8 @@- `DownloadFile` is an `ApiHandler`.- `DownloadFile` defines `process(...)`.- `DownloadFile` defines `get_methods(...)`.+- The endpoint retains the default authenticated and CSRF-protected browser contract.+- Download paths use `/` as their root, matching the authenticated File Browser and editor filesystem scope.- Observed side-effect areas: filesystem reads, network calls.- Imported dependency areas include: `api`, `base64`, `flask`, `helpers`, `helpers.api`, `io`, `mimetypes`, `os`, `pathlib`, `urllib.parse`.diff --git a/api/download_work_dir_files.py b/api/download_work_dir_files.pyindex 74b668706..f11b522e3 100644--- a/api/download_work_dir_files.py+++ b/api/download_work_dir_files.py@@ -8,7 +8,7 @@ import zipfilefrom flask import Responsefrom helpers.api import ApiHandler, Input, Output, Request-from helpers import files, runtime+from helpers import runtimefrom helpers.localization import Localizationfrom api.download_work_dir_file import fetch_file, stream_file_download@@ -70,7 +70,7 @@ def selected_archive_name(count: int) -> str:def create_selected_zip(paths: list[str], current_path: str = "") -> str:- base_dir = Path(files.get_base_dir()).resolve()+ base_dir = Path("/")current_dir = resolve_download_path(current_path, base_dir) if current_path else Noneif current_dir and current_dir.is_file():current_dir = current_dir.parentdiff --git a/api/download_work_dir_files.py.dox.md b/api/download_work_dir_files.py.dox.mdindex 478669fa8..c0596b943 100644--- a/api/download_work_dir_files.py.dox.md+++ b/api/download_work_dir_files.py.dox.md@@ -29,6 +29,8 @@- Update this file whenever request payloads, authentication or CSRF requirements, response shapes, route side effects, or WebSocket event contracts change.- `DownloadFiles` is an `ApiHandler`.- `DownloadFiles` defines `process(...)`.+- The endpoint retains the default authenticated and CSRF-protected browser contract.+- Selected paths use `/` as their root, matching the authenticated File Browser and editor filesystem scope.- Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion.- Imported dependency areas include: `api.download_work_dir_file`, `base64`, `flask`, `helpers`, `helpers.api`, `helpers.localization`, `io`, `os`, `pathlib`, `tempfile`, `zipfile`.diff --git a/tests/test_download_work_dir_paths.py b/tests/test_download_work_dir_paths.pynew file mode 100644index 000000000..a4c5ec296--- /dev/null+++ b/tests/test_download_work_dir_paths.py@@ -0,0 +1,21 @@+from pathlib import Path+import zipfile++from api.download_work_dir_file import resolve_download_path+from api.download_work_dir_files import create_selected_zip+++def test_download_resolvers_match_file_browser_root(tmp_path: Path) -> None:+ file_path = tmp_path / "outside-a0.txt"+ file_path.write_text("downloadable", encoding="utf-8")++ assert resolve_download_path(str(file_path)) == str(file_path.resolve())++ archive_path = Path(create_selected_zip([str(file_path)], "/"))+ try:+ with zipfile.ZipFile(archive_path) as archive:+ name = str(file_path).lstrip("/")+ assert archive.namelist() == [name]+ assert archive.read(name) == b"downloadable"+ finally:+ archive_path.unlink(missing_ok=True)