package aiprompts import "testing" // Regression: A1 categories carry both a legacy HTML formula in categories.prompt // and a stale description_template written by an old migration (seven English // boilerplate sections). Preferring whichever side had MORE sections handed the // stale template to the validation gate while the model was instructed from the // prompt — every reply then failed as "formula mismatch" and enhance fell back to // synth or supplier copy. The tenant's own prompt formula must win. func TestEffectiveDescriptionFormula_promptFormulaBeatsStaleStoredSections(t *testing.T) { t.Parallel() prompt := SectionDescriptionStart + "\n" + `

{Napiši Novo ime izdelka in izpostavi en benefit}

` + `

{Napiši odstavek, ki je dolg 100 besed.}

` + `

{Izpostavi en benefit}

` + `

{Napiši odstavek, ki je dolg 100 besed.}

` + `{Tehnične specifikacije}` + "\n" + SectionDescriptionEnd stale := map[string]any{"sections": []any{ map[string]any{"type": "h1", "instructions": "Write a compelling main title."}, map[string]any{"type": "p", "instructions": "Write a detailed paragraph about specific features."}, map[string]any{"type": "h2", "instructions": "Create a section heading."}, map[string]any{"type": "ul", "instructions": "List key features or specifications."}, map[string]any{"type": "p", "instructions": "Izpostavi eno prednost izdelka."}, map[string]any{"type": "p", "instructions": "Izpostavi eno prednost izdelka."}, map[string]any{"type": "p", "instructions": "Izpostavi eno prednost izdelka."}, }} got := EffectiveDescriptionFormula(stale, prompt) want := []string{"h2", "p", "h2", "p", "ul"} if len(got.Sections) != len(want) { t.Fatalf("got %d sections, want the %d from the prompt formula: %+v", len(got.Sections), len(want), got.Sections) } for i, typ := range want { if got.Sections[i].Type != typ { t.Fatalf("section %d type=%q want %q (%+v)", i, got.Sections[i].Type, typ, got.Sections) } } } // Without a legacy formula in the prompt, the stored template still applies. func TestEffectiveDescriptionFormula_keepsStoredWhenPromptHasNoFormula(t *testing.T) { t.Parallel() stored := map[string]any{"sections": []any{ map[string]any{"type": "h2", "instructions": "Heading"}, map[string]any{"type": "p", "instructions": "Body"}, }} got := EffectiveDescriptionFormula(stored, "") if len(got.Sections) != 2 || got.Sections[0].Type != "h2" { t.Fatalf("stored template must survive an empty prompt: %+v", got.Sections) } }