```
feat: 添加飞书集成和改进安全配置 - 集成 lark-oapi 库以支持飞书功能 - 改进 CORS 配置验证器以支持 JSON 格式输入 - 添加安全凭证检查逻辑以防止跨域安全问题 - 在 DirectLLMAdapter 中增加响应解析异常处理 fix: 增强查询参数验证和分页限制 - 为多个路由添加 Query 参数验证器 - 实现 bounded_limit 和 bounded_offset 辅助函数 - 设置查询限制范围为 1-500 之间 - 使用 secrets.compare_digest 提升令牌验证安全性 refactor: 调整文档忽略规则和测试配置 - 更新 .gitignore 文件中的文档路径配置 - 在 smoke 测试中添加必要的环境变量配置 - 重构配置验证器以提高类型兼容性 ```
This commit is contained in:
@@ -9,6 +9,7 @@ from app.modules.ai_agent.constants import (
|
||||
OPENCLAW_HERMES_PIPELINE,
|
||||
AIChatRole,
|
||||
AIContextKey,
|
||||
AIErrorKey,
|
||||
AIHttpHeader,
|
||||
AIHttpPath,
|
||||
AIHttpPayloadKey,
|
||||
@@ -237,3 +238,30 @@ def test_openclaw_hermes_adapter_fails_when_requested_tool_is_blocked(monkeypatc
|
||||
"http://openclaw.local/healthz",
|
||||
"http://openclaw.local/readyz",
|
||||
]
|
||||
|
||||
|
||||
def test_direct_llm_adapter_wraps_unexpected_chat_response(monkeypatch) -> None:
|
||||
class BadChatClient(DummyClient):
|
||||
def post(
|
||||
self,
|
||||
url: str,
|
||||
json: dict[str, Any],
|
||||
headers: dict[str, str],
|
||||
) -> DummyResponse:
|
||||
self.calls.append({"method": "POST", "url": url, "json": json, "headers": headers})
|
||||
return DummyResponse({AIHttpPayloadKey.CHOICES: []})
|
||||
|
||||
DummyClient.calls = []
|
||||
monkeypatch.setattr(adapters.httpx, "Client", BadChatClient)
|
||||
settings = Settings(
|
||||
direct_llm_base_url="http://llm.local/v1",
|
||||
direct_llm_api_key="direct-key",
|
||||
direct_llm_model="company-model",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
adapters.DirectLLMAdapter(settings).ask("summarize")
|
||||
|
||||
assert exc_info.value.status_code == 502
|
||||
assert exc_info.value.detail[AIErrorKey.DIRECT_LLM] == "Unexpected chat completion response"
|
||||
assert exc_info.value.detail[AIResponseKey.RAW] == {AIHttpPayloadKey.CHOICES: []}
|
||||
|
||||
Reference in New Issue
Block a user