Phase 1, part 4: promote the company's own products

- Content lists the company first, at /content/own: its products from
  the profile (always there to pick from), its own feeds (a new profile
  field for the blog, news and releases), and new or updated pages from
  its websites' sitemaps, with each page's title and description.
- Drafts from it are kind "product" (utm_campaign=product), filed under
  the company's name, and prompted to promote the company's own work
  without unsupported claims; on Reddit, in the makers' voice, with a
  warning that self-promotion is often restricted.

This completes Phase 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:42:37 -07:00
co-authored by Claude Opus 5.5
parent 0e34f574b7
commit cd24f2a06d
20 changed files with 685 additions and 30 deletions
+79
View File
@@ -0,0 +1,79 @@
package content
import (
"context"
"strings"
"testing"
"supermarket/internal/models"
"supermarket/internal/profile"
)
func TestOwnContent(t *testing.T) {
d := openDB(t)
p := testProfile()
p.Products = append(p.Products, profile.Product{Name: "Acme Mail", Description: "Hosted email.", URL: "https://acme.example/mail", Pricing: "$3/user"})
p.Feeds = []string{"https://acme.example/blog/index.xml"}
p.Websites = []profile.Website{{URL: "https://acme.example"}}
if err := SyncProducts(d, p); err != nil {
t.Fatal(err)
}
items, _ := ListItems(d, OwnName, false, 10)
if len(items) != 2 {
t.Fatalf("items = %+v", items)
}
var mail Item
for _, it := range items {
if it.ID == "product:acme-mail" {
mail = it
}
}
if mail.Source != models.SourceProduct || mail.Title != "Acme Mail" || !strings.Contains(mail.Body, "Pricing: $3/user") {
t.Errorf("product item = %+v", mail)
}
if c, _ := Counts(d); c[OwnName] != 0 {
t.Errorf("products counted as waiting news: %v", c)
}
// Writing about it marks it, and a re-sync keeps the mark; a removed
// product's item goes.
e := OwnEntry(p)
if !IsOwn(e) || e.Relationship != KindProduct || len(e.RSS) != 1 || e.Websites[0] != "https://acme.example" {
t.Errorf("own entry = %+v", e)
}
f := &fakeAI{replies: []string{`{"linkedin": "Try Acme Mail."}`}}
drafts, err := Generate(context.Background(), f, Request{Profile: p, Entry: e, Items: []Item{mail}, Channels: []string{ChannelLinkedIn}})
if err != nil {
t.Fatal(err)
}
if drafts[0].InventoryName != "Acme" || drafts[0].Kind != KindProduct || drafts[0].SourceURL != "https://acme.example/mail" {
t.Errorf("draft = %+v", drafts[0])
}
if !strings.Contains(f.reqs[0].Prompt, "our own work at Acme") || strings.Contains(f.reqs[0].Prompt, "About _own") {
t.Errorf("prompt:\n%s", f.reqs[0].Prompt)
}
if _, err := CreateDrafts(d, drafts); err != nil {
t.Fatal(err)
}
p.Products = p.Products[1:]
p.Products[0].Description = "Hosted email, now with calendars."
if err := SyncProducts(d, p); err != nil {
t.Fatal(err)
}
items, _ = ListItems(d, OwnName, false, 10)
if len(items) != 1 || !items[0].Used || !strings.Contains(items[0].Body, "calendars") {
t.Errorf("after re-sync: %+v", items)
}
// On Reddit, product posts get a warning and a maker's voice.
if w := RedditWarnings(RedditCheck{Target: "selfhosted", Promo: true, Now: mail.FetchedAt}); !strings.Contains(w[0], "promotes your own work") {
t.Errorf("warnings = %q", w)
}
f = &fakeAI{replies: []string{`{"reddit": {"title": "We built a mail host", "body": "I work at Acme."}}`}}
if _, err := Generate(context.Background(), f, Request{Profile: p, Entry: e, Items: items, Channels: []string{ChannelReddit}, Subreddit: "selfhosted"}); err != nil {
t.Fatal(err)
}
if !strings.Contains(f.reqs[0].Prompt, "people who made it") {
t.Errorf("reddit product prompt:\n%s", f.reqs[0].Prompt)
}
}