diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-21 10:57:15 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-21 10:57:15 +0300 |
| commit | a28cce50b9ae53253ad79d1b72f28d83bad3a9d7 (patch) | |
| tree | 85f1215352c6030db32f6f7078af021fa76318c4 | |
| parent | ac9ffca2ab33e59c42b17988f90811c36b84d272 (diff) | |
p7: strengthen scene truncation regression
| -rw-r--r-- | internal/image/prompt_test.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/internal/image/prompt_test.go b/internal/image/prompt_test.go index 957c84c..a587c65 100644 --- a/internal/image/prompt_test.go +++ b/internal/image/prompt_test.go @@ -66,20 +66,29 @@ func TestBuildEducationalPromptTruncatesLongSceneWithoutBreakingUTF8(t *testing. style := "Photorealism" subject := "ябълка" - for { + var maxSceneLen int + for i := 0; i < 3; i++ { + candidateSubject := subject + strings.Repeat("x", i) template := fmt.Sprintf( "Generate a %s flashcard image illustrating \"%s\". Scene: "+ "The image should be educational and suitable for language learning flashcards. "+ "Requirements: The main subject or concept must be clearly visible, centered, well lit, and easy to identify.", - style, subject, + style, candidateSubject, ) - if (maxImagePromptChars-len(template))%2 == 1 { + maxSceneLen = maxImagePromptChars - len(template) + if maxSceneLen%3 != 0 { + subject = candidateSubject break } - subject += "x" } - scene := strings.Repeat("Ярка сцена с ябълки и хора, ", 80) + scene := "abc" + strings.Repeat("界", maxSceneLen+32) + if len(scene) <= maxSceneLen { + t.Fatalf("test setup failed: scene length = %d, want > %d", len(scene), maxSceneLen) + } + if utf8.ValidString(scene[:maxSceneLen]) { + t.Fatalf("test setup failed: raw byte slice unexpectedly remained valid UTF-8 at cut position %d", maxSceneLen) + } got := buildEducationalPrompt(style, scene, subject) if !utf8.ValidString(got) { @@ -91,4 +100,7 @@ func TestBuildEducationalPromptTruncatesLongSceneWithoutBreakingUTF8(t *testing. if !strings.Contains(got, "...") { t.Fatalf("buildEducationalPrompt() = %q, want truncated scene marker", got) } + if !strings.Contains(got, "abc") { + t.Fatalf("buildEducationalPrompt() = %q, want ASCII scene prefix to survive truncation", got) + } } |
