mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 08:26:53 +08:00
refactor: remove unused result handling and related test for empty task results
This commit is contained in:
+2
-13
@@ -2145,7 +2145,7 @@ class AgentManager:
|
|||||||
f"也不要重复创建同一个定时任务。\n\n"
|
f"也不要重复创建同一个定时任务。\n\n"
|
||||||
f"任务名称:{task.name}\n"
|
f"任务名称:{task.name}\n"
|
||||||
f"任务内容:{task.content}\n\n"
|
f"任务内容:{task.content}\n\n"
|
||||||
"完成后请直接向用户报告本次执行结果;如果无法完成,请说明原因。"
|
"完成后请直接向用户发送消息报告本次执行结果;如果无法完成,也需发送消息说明原因。"
|
||||||
)
|
)
|
||||||
success = True
|
success = True
|
||||||
result = ""
|
result = ""
|
||||||
@@ -2164,20 +2164,9 @@ class AgentManager:
|
|||||||
wait_for_completion=True,
|
wait_for_completion=True,
|
||||||
)
|
)
|
||||||
result_text = str(result or "").strip()
|
result_text = str(result or "").strip()
|
||||||
success = bool(result_text) and not result_text.startswith(
|
success = not result_text.startswith(
|
||||||
(AGENT_EXECUTION_ERROR_PREFIX, "处理消息时发生错误")
|
(AGENT_EXECUTION_ERROR_PREFIX, "处理消息时发生错误")
|
||||||
)
|
)
|
||||||
if not result_text:
|
|
||||||
result = "定时任务已执行,但 Agent 未返回结果"
|
|
||||||
await AgentChain().async_post_message(
|
|
||||||
Notification(
|
|
||||||
mtype=NotificationType.Agent,
|
|
||||||
username=notification_username,
|
|
||||||
title=f"定时任务:{task.name}",
|
|
||||||
text=result,
|
|
||||||
save_history=False,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
success = False
|
success = False
|
||||||
result = f"Agent 定时任务执行失败:{str(err)}"
|
result = f"Agent 定时任务执行失败:{str(err)}"
|
||||||
|
|||||||
@@ -591,40 +591,6 @@ async def test_agent_manager_runs_contextless_task_in_broadcast_mode(
|
|||||||
post_message.assert_not_awaited()
|
post_message.assert_not_awaited()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_agent_manager_broadcasts_empty_task_result(monkeypatch) -> None:
|
|
||||||
"""Agent 未返回内容时,调度器应广播一次兜底消息。"""
|
|
||||||
user_id = f"empty-{uuid4().hex}"
|
|
||||||
task = AgentTaskOper().add(
|
|
||||||
name="空结果检查",
|
|
||||||
content="执行检查",
|
|
||||||
trigger_type="cron",
|
|
||||||
cron_expression="0 * * * *",
|
|
||||||
run_at=None,
|
|
||||||
user_id=user_id,
|
|
||||||
username="admin",
|
|
||||||
session_id=f"session-{user_id}",
|
|
||||||
channel="Telegram",
|
|
||||||
source="telegram-test",
|
|
||||||
original_chat_id="chat-123",
|
|
||||||
)
|
|
||||||
manager = AgentManager()
|
|
||||||
manager.process_message = AsyncMock(return_value="")
|
|
||||||
post_message = AsyncMock()
|
|
||||||
monkeypatch.setattr(AgentChain, "async_post_message", post_message)
|
|
||||||
|
|
||||||
success, result = await manager.execute_scheduled_task(task.id)
|
|
||||||
|
|
||||||
assert success is False
|
|
||||||
assert result == "定时任务已执行,但 Agent 未返回结果"
|
|
||||||
notification = post_message.await_args.args[0]
|
|
||||||
assert notification.channel is None
|
|
||||||
assert notification.source is None
|
|
||||||
assert notification.userid is None
|
|
||||||
assert notification.original_chat_id is None
|
|
||||||
assert notification.username == "admin"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_cached_agent_clears_channel_for_background_task() -> None:
|
async def test_cached_agent_clears_channel_for_background_task() -> None:
|
||||||
"""复用会话 Agent 时,后台任务必须覆盖上一轮保留的渠道信息。"""
|
"""复用会话 Agent 时,后台任务必须覆盖上一轮保留的渠道信息。"""
|
||||||
|
|||||||
Reference in New Issue
Block a user