2026-10-14 18:18:54 +02:00
package aiprompts
import (
"strings"
"testing"
)
func TestDedupeA1DescriptionBlocks ( t * testing . T ) {
input := `--- Title ---
Napiši ime v slovenščini
--- End Title ---
--- Description ---
<H2>{Benefit one}</H2><p>{No title}</p>
<H2>{Benefit two}</H2><p>{Include title}</p>
<H2>{Benefit one}</H2><p>{No title}</p>
<H2>{Benefit two}</H2><p>{Exclude title}</p>
<H2>{Benefit two}</H2><p>{Include title}</p>
<b>{Tehnične specifikacije}</b><ul><li>{3-10}</li></ul>
--- End Description ---
--- Meta ---
140 znakov
--- End Meta ---`
got , n := DedupeA1DescriptionBlocks ( input )
if n != 2 {
t . Fatalf ( "removed=%d want 2" , n )
}
if strings . Count ( got , "<H2>" ) != 3 {
t . Fatalf ( "H2 count changed incorrectly: %s" , got )
}
for _ , want := range [] string { "Napiši ime" , "140 znakov" , "Tehnične specifikacije" , "Exclude title" } {
if ! strings . Contains ( got , want ) {
t . Fatalf ( "lost %q" , want )
}
}
again , n := DedupeA1DescriptionBlocks ( got )
if n != 0 || again != got {
t . Fatal ( "cleanup not idempotent" )
}
}
2026-10-14 18:47:00 +02:00
func TestDedupeA1RealRepeatingTemplate ( t * testing . T ) {
headingA := `<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>`
headingB := `<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>`
paragraphA := `<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>`
paragraphB := `<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>`
original := headingA + "\n" + paragraphA + "\n" + headingB + "\n" + paragraphB + "\n" +
headingA + "\n" + paragraphA + "\n" + headingB + "\n" + paragraphB + "\n" +
headingB + "\n" + paragraphA + `<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>`
cleaned , removed := DedupeA1DescriptionBlocks ( original )
if removed != 2 {
t . Fatalf ( "expected 2 duplicate pairs, got %d" , removed )
}
if strings . Count ( cleaned , "<H2>" ) != 3 {
t . Fatalf ( "expected 3 distinct pairs: %s" , cleaned )
}
if ! strings . Contains ( cleaned , "Tehnične specifikacije" ) {
t . Fatal ( "lost specs" )
}
twice , removedAgain := DedupeA1DescriptionBlocks ( cleaned )
if removedAgain != 0 || twice != cleaned {
t . Fatal ( "A1 cleanup must be idempotent" )
}
}
func TestDedupeStructuredA1Descriptions ( t * testing . T ) {
raw := `{"sections":[{"type":"h2","instructions":"A"},{"type":"p","instructions":"X"},{"type":"h2","instructions":"B"},{"type":"p","instructions":"Y"},{"type":"h2","instructions":"A"},{"type":"p","instructions":"X"},{"type":"ul","instructions":"Specifications"}],"metaDescription":"140 znakov"}`
cleaned , removed , err := DedupeA1DescriptionTemplate ( raw )
if err != nil || removed != 1 {
t . Fatalf ( "removed=%d err=%v" , removed , err )
}
if strings . Count ( cleaned , `"type":"h2"` ) != 2 || ! strings . Contains ( cleaned , `140 znakov` ) || ! strings . Contains ( cleaned , `Specifications` ) {
t . Fatalf ( "invalid result: %s" , cleaned )
}
again , n , err := DedupeA1DescriptionTemplate ( cleaned )
if n != 0 || err != nil || again != cleaned {
t . Fatal ( "structured cleanup not idempotent" )
}
}
2026-10-14 19:23:16 +02:00
func TestNormalizeA1LegacySEOHTML ( t * testing . T ) {
source := `--- Title ---
Napiši Novo ime izdelka
--- End Title ---
--- Description ---
<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
2026-10-14 18:47:00 +02:00
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
<H2>{Napiši Novo ime izdelka brez barve in izpostavi en benefit}</H2>
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p>
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
<p>{Napiši odstavek, ki je dolg 100 besed in VKLJUČI tudi Novo ime izdelka.}</p>
<H2>{Izpostavi en benefit, in NE napiši Novo ime izdelka}</H2>
2026-10-14 19:23:16 +02:00
<p>{Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka.}</p><b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>
--- End Description ---
--- Meta ---
Najprej Novo ime izdelka
--- End Meta ---`
result , changed := NormalizeA1RepeatedBenefits ( source )
if changed != 5 {
t . Fatalf ( "expected five legacy boilerplate pairs, got %d" , changed )
2026-10-14 18:47:00 +02:00
}
2026-10-14 19:23:16 +02:00
for _ , want := range [] string { "--- Title ---" , "Napiši Novo ime izdelka" , "--- Meta ---" , "Najprej Novo ime izdelka" , "<p>{" , "<h2>{" , "<ul><li>{" } {
if ! strings . Contains ( result , want ) {
t . Fatalf ( "missing %q: %s" , want , result )
}
2026-10-14 18:47:00 +02:00
}
2026-10-14 19:23:16 +02:00
if strings . Count ( result , "<h2>" ) != 2 || strings . Contains ( result , "100 besed" ) {
t . Fatalf ( "still repetitive: %s" , result )
2026-10-14 18:47:00 +02:00
}
again , n := NormalizeA1RepeatedBenefits ( result )
if n != 0 || again != result {
2026-10-14 19:23:16 +02:00
t . Fatal ( "SEO upgrade must be idempotent" )
2026-10-14 18:47:00 +02:00
}
}
func TestNormalizeA1StructuredKeepsSections ( t * testing . T ) {
source := `{"sections":[{"type":"h2","instructions":"Benefit A"},{"type":"p","instructions":"NE vsebuje Novo ime izdelka"},{"type":"h2","instructions":"Benefit B"},{"type":"p","instructions":"VKLJUČI Novo ime izdelka"},{"type":"h2","instructions":"Benefit A"},{"type":"p","instructions":"NE vsebuje Novo ime izdelka"}],"metaDescription":"140 znakov"}`
result , changed , err := NormalizeA1DescriptionTemplate ( source )
if err != nil || changed != 1 {
t . Fatalf ( "changed=%d err=%v" , changed , err )
}
if strings . Count ( result , `"type":"h2"` ) != 3 || ! strings . Contains ( result , "3. drugačno" ) || ! strings . Contains ( result , "140 znakov" ) {
t . Fatalf ( "invalid: %s" , result )
}
again , n , err := NormalizeA1DescriptionTemplate ( result )
if n != 0 || err != nil || again != result {
t . Fatal ( "not idempotent" )
}
}
2026-10-14 19:23:16 +02:00
func TestNormalizeA1LegacyStructuredSEO ( t * testing . T ) {
raw := `{"sections":[{"type":"h2","instructions":"Napiši Novo ime izdelka brez barve in izpostavi en benefit"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed, ki NE vsebuje Novo ime izdelka"},{"type":"h2","instructions":"Izpostavi en benefit"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed in VKLJUČI Novo ime izdelka"},{"type":"h2","instructions":"Napiši Novo ime izdelka"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed"},{"type":"h2","instructions":"Benefit"},{"type":"p","instructions":"Napiši odstavek, ki je dolg 100 besed"},{"type":"ul","instructions":"Tehnične specifikacije"}],"metaDescription":"140 znakov"}`
clean , n , err := NormalizeA1DescriptionTemplate ( raw )
if err != nil || n != 4 {
t . Fatalf ( "changed=%d err=%v" , n , err )
}
if ! strings . Contains ( clean , `"type":"ul"` ) || ! strings . Contains ( clean , `140 znakov` ) || strings . Contains ( clean , "100 besed" ) {
t . Fatal ( clean )
}
twice , n , err := NormalizeA1DescriptionTemplate ( clean )
if err != nil || n != 0 || twice != clean {
t . Fatal ( "not repeatable" )
}
}