Files
social-app/backend/tests/unit/v1/agent/test_utils.py
T
qzl aa30fe0ce6 refactor: 重构 Tool Result 契约,移除 ui_hints 统一使用 result 字段
- ToolAgentOutput 移除 result_summary 和 ui_hints,统一使用 result 字段
- 日历/用户查找工具移除 ui_hints 输出,改为机器可读的结构化结果
- Agent History 移除 tool 消息的 ui_hints 处理逻辑
- App 版本检查改为 manifest.json 方式,支持多渠道发布
- 更新 settings 配置和测试用例适配新结构
2026-03-17 12:18:09 +08:00

71 lines
2.1 KiB
Python

from __future__ import annotations
from datetime import datetime, timezone
from uuid import uuid4
from v1.agent.utils import convert_message_to_history
class _FakeMessage:
def __init__(self, *, role: str, metadata: dict[str, object] | None) -> None:
self.id = uuid4()
self.seq = 1
self.role = role
self.content = "content"
self.metadata = metadata
self.timestamp = datetime.now(timezone.utc)
def test_convert_message_to_history_does_not_attach_ui_schema_for_tool_message() -> (
None
):
message = _FakeMessage(
role="tool",
metadata={"tool_agent_output": {"result": "done"}},
)
result = convert_message_to_history(message) # type: ignore[arg-type]
assert "ui_schema" not in result
assert "uiSchema" not in result
def test_convert_message_to_history_uses_ui_schema_key_for_assistant_message() -> None:
message = _FakeMessage(
role="assistant",
metadata={
"worker_agent_output": {
"ui_schema": {"version": "2.0", "root": {"type": "stack"}}
}
},
)
result = convert_message_to_history(message) # type: ignore[arg-type]
assert "ui_schema" in result
assert "uiSchema" not in result
assert result["ui_schema"] == {"version": "2.0", "root": {"type": "stack"}}
def test_convert_message_to_history_returns_multiple_user_attachments() -> None:
message = _FakeMessage(
role="user",
metadata={
"user_message_attachments": [
{"bucket": "bucket-a", "path": "path/a.png", "mime_type": "image/png"},
{"bucket": "bucket-a", "path": "path/b.jpg", "mime_type": "image/jpeg"},
]
},
)
def _signed(payload: dict[str, str]) -> str:
return f"https://signed.example/{payload['bucket']}/{payload['path']}"
result = convert_message_to_history(message, _signed) # type: ignore[arg-type]
attachments = result.get("attachments")
assert isinstance(attachments, list)
assert len(attachments) == 2
assert attachments[0]["mimeType"] == "image/png"
assert attachments[1]["mimeType"] == "image/jpeg"