mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 20:34:45 +08:00
fix: issue 1138 windows encoding (#1139)
* fix(windows): use utf-8 for text file operations * fix(windows): normalize sandbox path masking * fix(windows): preserve utf-8 handling after backend split
This commit is contained in:
27
backend/tests/test_artifacts_router.py
Normal file
27
backend/tests/test_artifacts_router.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from starlette.requests import Request
|
||||
|
||||
import app.gateway.routers.artifacts as artifacts_router
|
||||
|
||||
|
||||
def test_get_artifact_reads_utf8_text_file_on_windows_locale(tmp_path, monkeypatch) -> None:
|
||||
artifact_path = tmp_path / "note.txt"
|
||||
text = "Curly quotes: \u201cutf8\u201d"
|
||||
artifact_path.write_text(text, encoding="utf-8")
|
||||
|
||||
original_read_text = Path.read_text
|
||||
|
||||
def read_text_with_gbk_default(self, *args, **kwargs):
|
||||
kwargs.setdefault("encoding", "gbk")
|
||||
return original_read_text(self, *args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(Path, "read_text", read_text_with_gbk_default)
|
||||
monkeypatch.setattr(artifacts_router, "resolve_thread_virtual_path", lambda _thread_id, _path: artifact_path)
|
||||
|
||||
request = Request({"type": "http", "method": "GET", "path": "/", "headers": [], "query_string": b""})
|
||||
response = asyncio.run(artifacts_router.get_artifact("thread-1", "mnt/user-data/outputs/note.txt", request))
|
||||
|
||||
assert bytes(response.body).decode("utf-8") == text
|
||||
assert response.media_type == "text/plain"
|
||||
Reference in New Issue
Block a user