Enhance AIClient with skill document processing capabilities
Added a new method to run a skill document pipeline, allowing for enhanced processing of user messages based on specified skill documents. Implemented logic to extract relevant text from user messages and improved error handling during processing. Updated message handling to strip URLs from responses to prevent issues with message delivery. Added tests to validate the new processing functionality and ensure robustness.
This commit is contained in:
35
tests/test_message_handler_text_sanitize.py
Normal file
35
tests/test_message_handler_text_sanitize.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Tests for QQ-safe text sanitization in MessageHandler."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("botpy")
|
||||
|
||||
from src.handlers.message_handler_ai import MessageHandler
|
||||
|
||||
|
||||
def _handler() -> MessageHandler:
|
||||
fake_bot = SimpleNamespace(robot=SimpleNamespace(id="test_bot"))
|
||||
return MessageHandler(fake_bot)
|
||||
|
||||
|
||||
def test_plain_text_removes_markdown_link_url():
|
||||
handler = _handler()
|
||||
text = "参考 [Wikipedia](https://en.wikipedia.org/wiki/Wikipedia) 获取详情。"
|
||||
|
||||
result = handler._plain_text(text)
|
||||
|
||||
assert "Wikipedia" in result
|
||||
assert "http" not in result.lower()
|
||||
|
||||
|
||||
def test_plain_text_removes_bare_url():
|
||||
handler = _handler()
|
||||
text = "访问 https://example.com/path?a=1 或 www.example.org 查看。"
|
||||
|
||||
result = handler._plain_text(text)
|
||||
|
||||
assert "http" not in result.lower()
|
||||
assert "www." not in result.lower()
|
||||
assert "[链接已省略]" in result
|
||||
Reference in New Issue
Block a user