(t *testing.T)
| 1133 | } |
| 1134 | |
| 1135 | func TestParseContent_BackwardCompat(t *testing.T) { |
| 1136 | t.Parallel() |
| 1137 | |
| 1138 | fileID := uuid.New() |
| 1139 | |
| 1140 | // Build legacy fantasy assistant content using MarshalContent. |
| 1141 | legacyAssistantReasoning, err := chatprompt.MarshalContent([]fantasy.Content{ |
| 1142 | fantasy.ReasoningContent{ |
| 1143 | Text: "let me think...", |
| 1144 | ProviderMetadata: fantasy.ProviderMetadata{ |
| 1145 | "anthropic": &fantasyanthropic.ProviderCacheControlOptions{ |
| 1146 | CacheControl: fantasyanthropic.CacheControl{Type: "ephemeral"}, |
| 1147 | }, |
| 1148 | }, |
| 1149 | }, |
| 1150 | }, nil) |
| 1151 | require.NoError(t, err) |
| 1152 | |
| 1153 | legacyAssistantSource, err := chatprompt.MarshalContent([]fantasy.Content{ |
| 1154 | fantasy.SourceContent{ |
| 1155 | ID: "src_001", |
| 1156 | URL: "https://example.com/doc", |
| 1157 | Title: "Example Doc", |
| 1158 | }, |
| 1159 | }, nil) |
| 1160 | require.NoError(t, err) |
| 1161 | |
| 1162 | legacyAssistantToolCall, err := chatprompt.MarshalContent([]fantasy.Content{ |
| 1163 | fantasy.ToolCallContent{ |
| 1164 | ToolCallID: "call_123", |
| 1165 | ToolName: "read_file", |
| 1166 | Input: `{"path":"main.go"}`, |
| 1167 | }, |
| 1168 | }, nil) |
| 1169 | require.NoError(t, err) |
| 1170 | |
| 1171 | // Build new SDK format using MarshalParts. |
| 1172 | sdkMetadata := json.RawMessage(`{"anthropic":{"type":"anthropic.cache_control_options","data":{"cache_control":{"type":"ephemeral"}}}}`) |
| 1173 | |
| 1174 | newAssistantWithMeta, err := chatprompt.MarshalParts([]codersdk.ChatMessagePart{{ |
| 1175 | Type: codersdk.ChatMessagePartTypeText, |
| 1176 | Text: "here is my answer", |
| 1177 | ProviderMetadata: sdkMetadata, |
| 1178 | }}) |
| 1179 | require.NoError(t, err) |
| 1180 | |
| 1181 | newAssistantToolCall, err := chatprompt.MarshalParts([]codersdk.ChatMessagePart{{ |
| 1182 | Type: codersdk.ChatMessagePartTypeToolCall, |
| 1183 | ToolCallID: "call_456", |
| 1184 | ToolName: "execute", |
| 1185 | Args: json.RawMessage(`{"cmd":"ls"}`), |
| 1186 | }}) |
| 1187 | require.NoError(t, err) |
| 1188 | |
| 1189 | newToolResult, err := chatprompt.MarshalParts([]codersdk.ChatMessagePart{{ |
| 1190 | Type: codersdk.ChatMessagePartTypeToolResult, |
| 1191 | ToolCallID: "call_456", |
| 1192 | ToolName: "execute", |
nothing calls this directly
no test coverage detected