feat(attachments): implement normalization and limits for temporary attachment IDs

Add functionality to normalize temporary attachment IDs, ensuring deduplication and enforcing a maximum limit of 5 attachments per message. Update related handlers and tests to support this new behavior, enhancing the robustness of attachment management in chat sessions.
This commit is contained in:
wizardchen
2026-07-16 17:18:08 +08:00
committed by lyingbug
parent 9ae17be43c
commit 85d10d99e3
7 changed files with 725 additions and 7 deletions
@@ -105,3 +105,24 @@ func TestPersistResolvedAttachmentContent_GuardsEmptyInput(t *testing.T) {
assert.Equal(t, 0, stub.updateCalls)
}
func TestNormalizeTemporaryAttachmentIDs(t *testing.T) {
t.Run("rejects over limit before lookup", func(t *testing.T) {
ids := []string{"a", "b", "c", "d", "e", "f"}
_, err := normalizeTemporaryAttachmentIDs(ids)
require.Error(t, err)
assert.Contains(t, err.Error(), "at most 5")
})
t.Run("dedupes and drops empty", func(t *testing.T) {
got, err := normalizeTemporaryAttachmentIDs([]string{" a ", "", "b", "a", "c"})
require.NoError(t, err)
assert.Equal(t, []string{"a", "b", "c"}, got)
})
t.Run("allows max unique ids", func(t *testing.T) {
got, err := normalizeTemporaryAttachmentIDs([]string{"1", "2", "3", "4", "5"})
require.NoError(t, err)
assert.Equal(t, []string{"1", "2", "3", "4", "5"}, got)
})
}