TestMixedFormatConversation verifies ConvertMessagesWithFiles handles a realistic post-deploy conversation where legacy and new storage formats coexist.
(t *testing.T)
| 1654 | // handles a realistic post-deploy conversation where legacy and new |
| 1655 | // storage formats coexist. |
| 1656 | func TestMixedFormatConversation(t *testing.T) { |
| 1657 | t.Parallel() |
| 1658 | |
| 1659 | fileID := uuid.New() |
| 1660 | resolvedFileData := []byte("resolved-png-bytes") |
| 1661 | |
| 1662 | resolver := func(_ context.Context, ids []uuid.UUID) (map[uuid.UUID]chatprompt.FileData, error) { |
| 1663 | out := make(map[uuid.UUID]chatprompt.FileData) |
| 1664 | for _, id := range ids { |
| 1665 | if id == fileID { |
| 1666 | out[id] = chatprompt.FileData{Data: resolvedFileData, MediaType: "image/png"} |
| 1667 | } |
| 1668 | } |
| 1669 | return out, nil |
| 1670 | } |
| 1671 | |
| 1672 | // 1. System (JSON string). |
| 1673 | systemRaw, err := json.Marshal("You are helpful.") |
| 1674 | require.NoError(t, err) |
| 1675 | |
| 1676 | // 2. Old user (fantasy envelope: text + file with file_id). |
| 1677 | oldUserRaw := mustJSON(t, []json.RawMessage{ |
| 1678 | mustJSON(t, map[string]any{ |
| 1679 | "type": "text", |
| 1680 | "data": map[string]any{"text": "Look at this image."}, |
| 1681 | }), |
| 1682 | mustJSON(t, map[string]any{ |
| 1683 | "type": "file", |
| 1684 | "data": map[string]any{ |
| 1685 | "media_type": "image/png", |
| 1686 | "file_id": fileID.String(), |
| 1687 | }, |
| 1688 | }), |
| 1689 | }) |
| 1690 | |
| 1691 | // 3. Old assistant (fantasy envelope: tool-call). |
| 1692 | oldAssistantRaw, err := chatprompt.MarshalContent([]fantasy.Content{ |
| 1693 | fantasy.ToolCallContent{ |
| 1694 | ToolCallID: "call_1", |
| 1695 | ToolName: "analyze_image", |
| 1696 | Input: `{"detail":"high"}`, |
| 1697 | }, |
| 1698 | }, nil) |
| 1699 | require.NoError(t, err) |
| 1700 | |
| 1701 | // 4. Old tool (legacy result rows). |
| 1702 | oldToolRaw, err := chatprompt.MarshalToolResult( |
| 1703 | "call_1", "analyze_image", |
| 1704 | json.RawMessage(`{"description":"a cat"}`), false, false, |
| 1705 | false, nil, |
| 1706 | ) |
| 1707 | require.NoError(t, err) |
| 1708 | |
| 1709 | // 5. New user (SDK parts: text + file-reference). |
| 1710 | newUserRaw, err := chatprompt.MarshalParts([]codersdk.ChatMessagePart{ |
| 1711 | {Type: codersdk.ChatMessagePartTypeText, Text: "Check this diff."}, |
| 1712 | {Type: codersdk.ChatMessagePartTypeFileReference, FileName: "main.go", StartLine: 5, EndLine: 15, Content: "func main() {}"}, |
| 1713 | }) |
nothing calls this directly
no test coverage detected