This commit is contained in:
2026-08-23 12:40:59 +02:00
parent bd762d1ccf
commit 5340158228
11 changed files with 342 additions and 51 deletions
+14 -2
View File
@@ -109,11 +109,23 @@ func TestCompleteJSON_returnsRetryError(t *testing.T) {
}
func TestProductEnhanceUser_truncates(t *testing.T) {
long := strings.Repeat("x", 2000)
long := strings.Repeat("x", MaxProductDescRunes+500)
u := ProductEnhanceUser("Cat", "Name", long, map[string]any{"brand": "B"})
if len([]rune(u)) > 900 {
// Category/Name/Attrs overhead + MaxProductDescRunes of description.
if len([]rune(u)) > MaxProductDescRunes+200 {
t.Fatalf("user too long: %d", len([]rune(u)))
}
descIdx := strings.Index(u, "Description: ")
if descIdx < 0 {
t.Fatalf("missing Description: in %q", u)
}
descPart := u[descIdx+len("Description: "):]
if i := strings.Index(descPart, "\n"); i >= 0 {
descPart = descPart[:i]
}
if len([]rune(descPart)) > MaxProductDescRunes {
t.Fatalf("description runes=%d want <= %d", len([]rune(descPart)), MaxProductDescRunes)
}
if !strings.Contains(u, "brand") {
t.Fatalf("%s", u)
}