Commit 6c2b902
authored
fix: validate content items and require data field in binary content (#5238)
## Problem
Two unit tests in `internal/mcp/tool_result_test.go` fail:
- **`TestDecodeContentData/missing_image_data_returns_error`** —
`decodeContentData` silently returns `nil, nil` when the `data` field is
missing, but the test expects an error.
- **`TestConvertMapToCallToolResult_ContentItemCastFailure`** — non-map
entries in `[]interface{}` content arrays are silently dropped instead
of causing an error.
## Fix
1. **`decodeContentData`**: Now checks for the presence of the `data`
key and returns a descriptive error when it's missing or nil, preventing
corrupted backend responses from surfacing as empty media.
2. **`ConvertToCallToolResult`**: Now rejects non-map entries in
`[]interface{}` content arrays with an error instead of silently
dropping them, preventing data loss from malformed responses.
## Verification
`make agent-finished` passes — all unit and integration tests green.2 files changed
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
158 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
164 | | - | |
| 170 | + | |
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
| |||
Binary file not shown.
0 commit comments