From 59afb2ed0309777bce448e3d078570fe57a81d45 Mon Sep 17 00:00:00 2001 From: "Wiktor A. Falkowski" Date: Fri, 23 Oct 2026 21:17:55 +0000 Subject: [PATCH] fix(file-manager): preserve upload path correlation --- tests/test_chunked_upload.py | 22 +++++++++++++++++++--- websocket_service.py | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_chunked_upload.py b/tests/test_chunked_upload.py index 5e23592..f1bd273 100644 --- a/tests/test_chunked_upload.py +++ b/tests/test_chunked_upload.py @@ -13,10 +13,12 @@ class ChunkedUploadTests(unittest.TestCase): content: bytes, write_success: bool = True, chunk_data: str | None = None, + normalize_path: bool = False, ) -> tuple[list[dict], bytes]: client_id = "upload-test-client" server_id = "upload-test-server" - file_path = "/data/upload-check.bin" + file_path = "/upload-check.bin" if normalize_path else "/data/upload-check.bin" + server_file_path = f"/data{file_path}" if normalize_path else file_path captured_content = b"" messages: list[dict] = [] @@ -42,7 +44,13 @@ class ChunkedUploadTests(unittest.TestCase): try: with ( patch.object(websocket_service, "send_message", new=AsyncMock(side_effect=capture_message)), - patch.object(websocket_service, "validate_path_for_server", side_effect=lambda _server, path: path), + patch.object( + websocket_service, + "validate_path_for_server", + side_effect=lambda _server, path: ( + path if path.startswith("/data") else f"/data{path}" + ) if normalize_path else path, + ), patch.object( websocket_service, "get_server_access_and_namespace", @@ -71,7 +79,7 @@ class ChunkedUploadTests(unittest.TestCase): client_id, { "serverId": server_id, - "filePath": file_path, + "filePath": server_file_path, "chunkIndex": 0, "chunkData": chunk_data if chunk_data is not None else base64.b64encode(content).decode("ascii"), "totalChunks": 1, @@ -102,6 +110,14 @@ class ChunkedUploadTests(unittest.TestCase): self.assertEqual(uploaded, b"") self.assertEqual(messages[-1]["type"], "file_uploaded") + def test_upload_ack_preserves_client_path_when_server_normalizes_path(self) -> None: + messages, uploaded = self._upload(b"payload", normalize_path=True) + + self.assertEqual(uploaded, b"payload") + self.assertEqual(messages[0]["type"], "upload_started") + self.assertEqual(messages[0]["filePath"], "/data/upload-check.bin") + self.assertEqual(messages[0]["clientFilePath"], "/upload-check.bin") + def test_upload_reports_storage_failure(self) -> None: messages, _uploaded = self._upload(b"payload", write_success=False) diff --git a/websocket_service.py b/websocket_service.py index 5e699ee..42aacb1 100644 --- a/websocket_service.py +++ b/websocket_service.py @@ -2111,6 +2111,7 @@ async def handle_start_chunked_upload(client_id, data): return try: + client_file_path = file_path # Validate path for Minecraft servers file_path = validate_path_for_server(server_id, file_path) @@ -2150,6 +2151,7 @@ async def handle_start_chunked_upload(client_id, data): 'type': 'upload_started', 'serverId': server_id, 'filePath': file_path, + 'clientFilePath': client_file_path, 'uploadId': upload_id }) except Exception as e: