2026-08-09 22:47:43 +02:00
|
|
|
package processing
|
|
|
|
|
|
|
|
|
|
import (
|
2026-08-16 16:57:36 +02:00
|
|
|
"strings"
|
2026-08-09 22:47:43 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestResolvePromptFallbackChain(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
// Category override for language wins over company user template.
|
2026-08-16 16:57:36 +02:00
|
|
|
// Overrides without {{attrs}} get standard context placeholders injected.
|
2026-08-09 22:47:43 +02:00
|
|
|
sys, user := resolveProductPromptTemplates(ProductInput{
|
|
|
|
|
EnhanceSystemTemplate: "sys",
|
|
|
|
|
EnhanceUserTemplate: "company-en",
|
|
|
|
|
CategoryEnhancePrompt: "cat-sl",
|
|
|
|
|
Language: "sl",
|
|
|
|
|
})
|
2026-08-16 23:42:00 +02:00
|
|
|
if !strings.Contains(sys, "sys") {
|
|
|
|
|
t.Fatalf("sys=%q want company system kept", sys)
|
2026-08-16 16:57:36 +02:00
|
|
|
}
|
2026-08-16 23:42:00 +02:00
|
|
|
if !strings.Contains(sys, `apply it to "name", "description", and "attrs"`) {
|
|
|
|
|
t.Fatalf("sys=%q want category overlay for title+description+attrs", sys)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(user, "cat-sl") || !strings.Contains(user, "{{attrs}}") {
|
2026-08-16 16:57:36 +02:00
|
|
|
t.Fatalf("sys=%q user=%q want cat-sl + attrs", sys, user)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
2026-08-16 23:42:00 +02:00
|
|
|
if !strings.Contains(user, "applies to name, description, and attrs") {
|
|
|
|
|
t.Fatalf("user=%q want title framing", user)
|
|
|
|
|
}
|
2026-08-09 22:47:43 +02:00
|
|
|
|
|
|
|
|
// Empty category → company template.
|
|
|
|
|
_, user = resolveProductPromptTemplates(ProductInput{
|
|
|
|
|
EnhanceUserTemplate: "company-de",
|
|
|
|
|
Language: "de",
|
|
|
|
|
})
|
|
|
|
|
if user != "company-de" {
|
|
|
|
|
t.Fatalf("user=%q", user)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 16:57:36 +02:00
|
|
|
// sl-only category prompt: exact for sl; en falls back to primary=sl.
|
2026-08-09 22:47:43 +02:00
|
|
|
m := map[string]company.LangPromptMap{"audio": {"sl": "slo-prompt"}}
|
2026-08-16 16:57:36 +02:00
|
|
|
if got := categoryEnhancePromptFor(m, "audio", "sl", "sl"); got != "slo-prompt" {
|
|
|
|
|
t.Fatalf("sl exact: got %q", got)
|
|
|
|
|
}
|
|
|
|
|
if got := categoryEnhancePromptFor(m, "audio", "en", "sl"); got != "slo-prompt" {
|
|
|
|
|
t.Fatalf("en→primary sl: got %q", got)
|
|
|
|
|
}
|
|
|
|
|
if got := categoryEnhancePromptFor(m, "audio", "en", "en"); got != "" {
|
|
|
|
|
t.Fatalf("en with primary=en and no en/* prompt should be empty, got %q", got)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
2026-08-16 16:57:36 +02:00
|
|
|
// wildcard shared overlay
|
|
|
|
|
m2 := map[string]company.LangPromptMap{"audio": {"*": "shared-overlay"}}
|
|
|
|
|
if got := categoryEnhancePromptFor(m2, "audio", "en", "sl"); got != "shared-overlay" {
|
|
|
|
|
t.Fatalf("wildcard: got %q", got)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
|
|
|
|
}
|