mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix: improve text handling in append_text function and add test for newline preservation
This commit is contained in:
@@ -517,7 +517,7 @@ def _split_web_agent_output(text: str) -> list[dict]:
|
|||||||
|
|
||||||
def append_text(content: str) -> None:
|
def append_text(content: str) -> None:
|
||||||
"""将工具汇总行从普通文本中拆出,便于前端独立展示。"""
|
"""将工具汇总行从普通文本中拆出,便于前端独立展示。"""
|
||||||
if not content or not content.strip():
|
if not content:
|
||||||
return
|
return
|
||||||
lines = content.splitlines(keepends=True)
|
lines = content.splitlines(keepends=True)
|
||||||
buffer = ""
|
buffer = ""
|
||||||
|
|||||||
@@ -37,6 +37,25 @@ def test_split_web_agent_output_extracts_summary_tool_message():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_web_agent_output_preserves_standalone_newline_delta():
|
||||||
|
"""独立换行增量应保留,避免流式 Markdown 列表被拼成同一行。"""
|
||||||
|
chunks = [
|
||||||
|
"可以这样操作:",
|
||||||
|
"\n",
|
||||||
|
"- **搜索资源**:搜索电影",
|
||||||
|
"\n",
|
||||||
|
"- **下载管理**:添加任务",
|
||||||
|
]
|
||||||
|
content = ""
|
||||||
|
|
||||||
|
for chunk in chunks:
|
||||||
|
for event in _split_web_agent_output(chunk):
|
||||||
|
if event["type"] == "delta":
|
||||||
|
content += event["content"]
|
||||||
|
|
||||||
|
assert content == "可以这样操作:\n- **搜索资源**:搜索电影\n- **下载管理**:添加任务"
|
||||||
|
|
||||||
|
|
||||||
def test_build_web_agent_session_id_is_stable_per_user_and_seed():
|
def test_build_web_agent_session_id_is_stable_per_user_and_seed():
|
||||||
"""同一用户和前端会话标识应生成稳定的服务端会话 ID。"""
|
"""同一用户和前端会话标识应生成稳定的服务端会话 ID。"""
|
||||||
user = SimpleNamespace(id=1, name="admin")
|
user = SimpleNamespace(id=1, name="admin")
|
||||||
|
|||||||
Reference in New Issue
Block a user