(t *testing.T)
| 167 | } |
| 168 | |
| 169 | func TestChatMessagePart_StripInternal(t *testing.T) { |
| 170 | t.Parallel() |
| 171 | |
| 172 | t.Run("StripsProviderMetadata", func(t *testing.T) { |
| 173 | t.Parallel() |
| 174 | part := codersdk.ChatMessagePart{ |
| 175 | Type: codersdk.ChatMessagePartTypeToolCall, |
| 176 | ToolCallID: "call-1", |
| 177 | ToolName: "some_tool", |
| 178 | Args: json.RawMessage(`{"key":"value"}`), |
| 179 | ProviderMetadata: json.RawMessage(`{"type":"ephemeral"}`), |
| 180 | } |
| 181 | part.StripInternal() |
| 182 | assert.Nil(t, part.ProviderMetadata) |
| 183 | // Public fields preserved. |
| 184 | assert.Equal(t, codersdk.ChatMessagePartTypeToolCall, part.Type) |
| 185 | assert.Equal(t, "call-1", part.ToolCallID) |
| 186 | assert.Equal(t, "some_tool", part.ToolName) |
| 187 | assert.JSONEq(t, `{"key":"value"}`, string(part.Args)) |
| 188 | }) |
| 189 | |
| 190 | t.Run("StripsFileDataWhenFileIDSet", func(t *testing.T) { |
| 191 | t.Parallel() |
| 192 | id := uuid.New() |
| 193 | part := codersdk.ChatMessagePart{ |
| 194 | Type: codersdk.ChatMessagePartTypeFile, |
| 195 | FileID: uuid.NullUUID{UUID: id, Valid: true}, |
| 196 | MediaType: "image/png", |
| 197 | Data: []byte("binary-payload"), |
| 198 | } |
| 199 | part.StripInternal() |
| 200 | assert.Nil(t, part.Data) |
| 201 | assert.Equal(t, id, part.FileID.UUID) |
| 202 | assert.Equal(t, "image/png", part.MediaType) |
| 203 | }) |
| 204 | |
| 205 | t.Run("PreservesDataWhenNoFileID", func(t *testing.T) { |
| 206 | t.Parallel() |
| 207 | part := codersdk.ChatMessagePart{ |
| 208 | Type: codersdk.ChatMessagePartTypeFile, |
| 209 | MediaType: "image/png", |
| 210 | Data: []byte("inline-data"), |
| 211 | } |
| 212 | part.StripInternal() |
| 213 | assert.Equal(t, []byte("inline-data"), part.Data) |
| 214 | }) |
| 215 | |
| 216 | t.Run("StripsContextFileContent", func(t *testing.T) { |
| 217 | t.Parallel() |
| 218 | agentID := uuid.New() |
| 219 | part := codersdk.ChatMessagePart{ |
| 220 | Type: codersdk.ChatMessagePartTypeContextFile, |
| 221 | ContextFilePath: "/home/coder/AGENTS.md", |
| 222 | ContextFileContent: "large content", |
| 223 | ContextFileAgentID: uuid.NullUUID{UUID: agentID, Valid: true}, |
| 224 | ContextFileOS: "linux", |
| 225 | ContextFileDirectory: "/home/coder/project", |
| 226 | ContextFileSkillMetaFile: "CUSTOM.md", |
nothing calls this directly
no test coverage detected