feat: US-011 - Add MessageTool tests
- Added comprehensive test suite for MessageTool (message_test.go) - 10 test cases covering all acceptance criteria: - Success returns SilentResult with proper ForLLM status - ForUser is empty (user receives message directly) - Failure returns ErrorResult with IsError=true - Custom channel/chat_id parameter handling - Error scenarios (missing content, no target, not configured) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ Tool 返回值结构化重构 - 将 Tool 接口返回值从 (string, error) 改
|
||||
|
||||
## Progress
|
||||
|
||||
### Completed (9/21)
|
||||
### Completed (10/21)
|
||||
|
||||
- US-001: Add ToolResult struct and helper functions
|
||||
- US-002: Modify Tool interface to return *ToolResult
|
||||
@@ -17,6 +17,7 @@ Tool 返回值结构化重构 - 将 Tool 接口返回值从 (string, error) 改
|
||||
- US-008: Inject callback into async tools in AgentLoop
|
||||
- US-009: State save atomicity - SetLastChannel
|
||||
- US-010: Update RecordLastChannel to use atomic save
|
||||
- US-011: Refactor MessageTool to use ToolResult
|
||||
|
||||
### In Progress
|
||||
|
||||
@@ -34,7 +35,7 @@ Tool 返回值结构化重构 - 将 Tool 接口返回值从 (string, error) 改
|
||||
| US-008 | Inject callback into async tools in AgentLoop | Completed | |
|
||||
| US-009 | State save atomicity - SetLastChannel | Completed | |
|
||||
| US-010 | Update RecordLastChannel to use atomic save | Completed | |
|
||||
| US-011 | Refactor MessageTool to use ToolResult | Completed | |
|
||||
| US-011 | Refactor MessageTool to use ToolResult | Completed | Added test file message_test.go |
|
||||
| US-012 | Refactor ShellTool to use ToolResult | Completed | |
|
||||
| US-013 | Refactor FilesystemTool to use ToolResult | Completed | |
|
||||
| US-014 | Refactor WebTool to use ToolResult | Completed | |
|
||||
@@ -196,4 +197,26 @@ Tool 返回值结构化重构 - 将 Tool 接口返回值从 (string, error) 改
|
||||
- **Gotchas encountered:** 测试中的 mock Provider 需要实现完整的 `LLMProvider` 接口,包括 `GetDefaultModel()` 方法。
|
||||
- **Useful context:** `RecordLastChannel` 方法现在可以用于跟踪用户最后一次活跃的频道,这对于跨会话的上下文恢复很有用。
|
||||
|
||||
---
|
||||
|
||||
## [2026-02-12] - US-011
|
||||
- What was implemented:
|
||||
- MessageTool 已经完全使用 ToolResult 返回值(无需修改实现)
|
||||
- 添加了完整的测试文件 `pkg/tools/message_test.go`,包含 10 个测试用例
|
||||
- 测试覆盖了所有验收标准:
|
||||
- 发送成功返回 SilentResult(Silent=true)
|
||||
- ForLLM 包含发送状态描述
|
||||
- ForUser 为空(用户已直接收到消息)
|
||||
- 发送失败返回 ErrorResult(IsError=true)
|
||||
- 支持自定义 channel/chat_id 参数
|
||||
- 支持错误场景(缺少 content、无目标 channel、未配置回调)
|
||||
|
||||
- Files changed:
|
||||
- `pkg/tools/message_test.go` (新增)
|
||||
|
||||
- **Learnings for future iterations:**
|
||||
- **Patterns discovered:** MessageTool 实现已经符合 ToolResult 规范,只需要添加测试覆盖即可。
|
||||
- **Gotchas encountered:** 测试文件使用 `map[string]interface{}` 作为 args 参数类型,与 Tool.Execute 签名一致。
|
||||
- **Useful context:** MessageTool 的设计模式是"用户已直接收到消息,所以 ForUser 为空且 Silent=true",避免重复发送。
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user