docs: 修正 API 文档响应结构描述 + 添加缺失测试

- 修正 PROCESS_MESSAGE 响应数据访问路径 (result['content'] -> result['data']['content'])
- 添加 CLEAR_HISTORY 文档说明 (基于 SAVE_HISTORY 空消息实现)
- 添加 test_clear_history 和 test_send_message_is_alias 测试用例
- 优化 BackendClient 历史相关方法的返回值处理
This commit is contained in:
root
2026-04-15 12:09:48 +08:00
parent a8dc24e7f3
commit 09a45c52e7
4 changed files with 58 additions and 7 deletions

View File

@ -235,6 +235,46 @@ class TestBackendClientAPI:
server.shutdown()
def test_clear_history(self):
from core import BackendServer, BackendClient
server = BackendServer(db_path=":memory:", use_embedded_db=True)
server.start(api_key="")
client = BackendClient(server)
# 先保存一些历史
client.save_history([
{"role": "user", "content": "test message 1"},
{"role": "assistant", "content": "test response 1"}
])
# 验证历史已保存
history = client.get_history()
assert len(history) >= 2
# 清空历史
result = client.clear_history()
assert result.get("status") == "history_cleared"
# 验证历史已清空
history = client.get_history()
assert len(history) == 0
server.shutdown()
def test_send_message_is_alias(self):
"""测试 send 方法是 process_message 的别名"""
from core import BackendServer, BackendClient
server = BackendServer(db_path=":memory:", use_embedded_db=True)
server.start(api_key="")
client = BackendClient(server)
# send 方法应该等同于 process_message
# 由于没有真实 API key应该返回失败
result = client.send("test")
assert result.get("success") is False
server.shutdown()
class TestToolLimiter:
"""测试工具限制器"""