package factories import ( "strings" "testing" ) func TestPromptFactory(t *testing.T) { f := PromptFactory{} for in, want := range map[string]string{ "field_firstName": "First Name", "input_meta-title": "Meta Title", "txt_SEO_title": "Seo Title", "catalog_number": "Catalog Number", } { if got := HumanizeFieldName(in); got != want { t.Errorf("HumanizeFieldName(%q) = %q, want %q", in, got, want) } } cur := "old-slug" p := f.CreateSuggestionForField("post_slug", "slug", &cur, []Pair{{"title", "Hello World"}, {"empty", ""}, {"zero", "0"}}, nil) if !strings.Contains(p.SystemPrompt(), "Generate a URL-friendly slug") { t.Fatalf("system = %q", p.SystemPrompt()) } want := "Generate a value for the 'Post Slug' field.\n\nContext from related fields:\n- Title: Hello World\n\nCurrent value (improve or keep if already good): old-slug\n\nFormat: lowercase letters, numbers, and hyphens only. No spaces or special characters." if got := p.Messages()[0].Text; got != want { t.Fatalf("user message = %q", got) } p = f.CreateSuggestionForField("format", "dropdown", nil, nil, []Pair{{"LP", "Vinyl LP"}, {"CD", "Compact disc"}}) if got := p.Messages()[0].Text; !strings.HasSuffix(got, "Available options:\n- LP: Vinyl LP\n- CD: Compact disc\n\nRespond with ONLY the option key.") { t.Fatalf("dropdown = %q", got) } notes := "Keep it short." p = f.SuggestFieldsValues([]FormField{{Name: "title"}, {Name: "body", Type: "markdown"}}, []Pair{{"topic", "Jazz"}}, ¬es) if got := p.Messages()[0].Text; got != "Fields to generate values for:\n- title (type: text)\n- body (type: markdown)\n\nContext to base the suggestions on:\n- Topic: Jazz\n\nAdditional notes:\nKeep it short.\n" { t.Fatalf("fields = %q", got) } p = f.SuggestCategoriesForItem([]Category{{ID: "1", Name: "Jazz"}, {}}, nil, nil) if got := p.Messages()[0].Text; got != "Existing categories:\n- 1: Jazz\n- unknown: unnamed\n" { t.Fatalf("categories = %q", got) } if p := f.CreateChat(""); p.SystemPrompt() != "" || len(p.Messages()) != 0 { t.Fatal("empty chat") } if p := f.CreateCompletion("hi", "sys"); p.SystemPrompt() != "sys" || p.Messages()[0].Text != "hi" { t.Fatal("completion") } }