mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: complete runtime configuration migration
This commit is contained in:
@@ -3,6 +3,7 @@ import base64
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
@@ -199,6 +200,11 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
|
||||
def test_image_message_routes_to_agent_even_when_global_agent_is_disabled(self):
|
||||
chain = MessageChain()
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
ai_agent_enable=True,
|
||||
ai_agent_global=False,
|
||||
)
|
||||
|
||||
with patch.object(chain, "load_cache", return_value={}), patch.object(
|
||||
chain.messagehelper, "put"
|
||||
@@ -222,6 +228,11 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
|
||||
def test_audio_message_routes_to_agent_without_forcing_voice_reply(self):
|
||||
chain = MessageChain()
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
ai_agent_enable=True,
|
||||
ai_agent_global=False,
|
||||
)
|
||||
|
||||
with patch.object(chain, "load_cache", return_value={}), patch.object(
|
||||
chain, "_transcribe_audio_refs", return_value="帮我推荐一部电影"
|
||||
@@ -247,6 +258,11 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
|
||||
def test_file_message_routes_to_agent_even_when_global_agent_is_disabled(self):
|
||||
chain = MessageChain()
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
ai_agent_enable=True,
|
||||
ai_agent_global=False,
|
||||
)
|
||||
|
||||
with patch.object(chain, "load_cache", return_value={}), patch.object(
|
||||
chain.messagehelper, "put"
|
||||
@@ -433,6 +449,10 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
|
||||
def test_handle_ai_message_routes_images_to_files_when_image_input_disabled(self):
|
||||
chain = MessageChain()
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
ai_agent_enable=True,
|
||||
)
|
||||
|
||||
with patch.object(settings, "AI_AGENT_ENABLE", True), patch.object(
|
||||
settings, "LLM_SUPPORT_IMAGE_INPUT", False
|
||||
@@ -483,6 +503,10 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
def test_handle_ai_message_forwards_voice_input_to_agent_manager(self):
|
||||
"""AI消息入队时应保留语音输入标记。"""
|
||||
chain = MessageChain()
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
ai_agent_enable=True,
|
||||
)
|
||||
|
||||
with patch.object(settings, "AI_AGENT_ENABLE", True), patch.object(
|
||||
chain, "_get_or_create_session_id", return_value="session-1"
|
||||
@@ -1330,29 +1354,31 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
|
||||
def test_prepare_agent_files_saves_local_file(self):
|
||||
chain = MessageChain()
|
||||
with tempfile.TemporaryDirectory() as tempdir, patch(
|
||||
"app.chain.message.settings",
|
||||
SimpleNamespace(TEMP_PATH=Path(tempdir)),
|
||||
), patch.object(
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
chain.runtime_config = replace(
|
||||
chain.runtime_config,
|
||||
temporary_path=Path(tempdir),
|
||||
)
|
||||
with patch.object(
|
||||
chain,
|
||||
"_download_message_file_bytes",
|
||||
return_value="你好,MoviePilot".encode("utf-8"),
|
||||
):
|
||||
prepared = chain._prepare_agent_files(
|
||||
session_id="session-1",
|
||||
files=[
|
||||
IncomingMessage.MessageAttachment(
|
||||
ref="tg://document_file_id/doc-1",
|
||||
name="note.txt",
|
||||
mime_type="text/plain",
|
||||
)
|
||||
],
|
||||
channel=NotificationChannel.Telegram,
|
||||
source="telegram-test",
|
||||
)
|
||||
):
|
||||
prepared = chain._prepare_agent_files(
|
||||
session_id="session-1",
|
||||
files=[
|
||||
IncomingMessage.MessageAttachment(
|
||||
ref="tg://document_file_id/doc-1",
|
||||
name="note.txt",
|
||||
mime_type="text/plain",
|
||||
)
|
||||
],
|
||||
channel=NotificationChannel.Telegram,
|
||||
source="telegram-test",
|
||||
)
|
||||
|
||||
self.assertEqual(prepared[0]["status"], "ready")
|
||||
self.assertTrue(Path(prepared[0]["local_path"]).exists())
|
||||
self.assertEqual(prepared[0]["status"], "ready")
|
||||
self.assertTrue(Path(prepared[0]["local_path"]).exists())
|
||||
|
||||
def test_telegram_post_message_passes_file_to_client(self):
|
||||
module = TelegramModule()
|
||||
|
||||
Reference in New Issue
Block a user