Reddit: posted by hand, with the rules pasted

Reddit's API isn't open to apps like this one, so Supermarket no longer
signs in to Reddit, publishes or schedules there, or reads subreddits and
the account's posts. The internal/api/reddit client, Reddit's OAuth, its
keys and its Social accounts card are gone.

Supermarket still writes the post. Each Reddit draft in Posts has a box
for its subreddit's rules, with a link to them on Reddit: pasted once,
they're kept (subreddits.data, as pasted_rules) and given to the model
for later drafts. Open in Reddit saves the edits and opens the submit
page filled in; Copy title and Copy text (with the tagged source link)
cover a box that comes up empty; Mark as posted records it. Warnings come
from the pasted rules and the posts marked as posted. Fill's subreddit
suggestions are kept unchecked, and say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 11:48:54 -07:00
co-authored by Claude Opus 5.5
parent bae468e01c
commit 5451fe6d63
33 changed files with 382 additions and 1107 deletions
+9 -38
View File
@@ -3,7 +3,6 @@ package inventory
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/httptest"
@@ -11,7 +10,6 @@ import (
"testing"
"supermarket/internal/ai"
"supermarket/internal/api/reddit"
"supermarket/internal/profile"
)
@@ -52,7 +50,7 @@ func TestFillKeepsWhatWasTyped(t *testing.T) {
}}
e := &Entry{Name: "Rival", Relationship: Competitor, TwitterHandle: "typed"}
ours := &profile.Profile{Name: "Acme", Description: "Self-hosted widgets."}
res, err := Fill(context.Background(), fake, e, srv.URL, ours, nil)
res, err := Fill(context.Background(), fake, e, srv.URL, ours)
if err != nil {
t.Fatal(err)
}
@@ -83,7 +81,7 @@ func TestFillSkipsTheModelWhenNothingIsLeft(t *testing.T) {
fake := &fakeAI{}
e := &Entry{Name: "Rival", Relationship: Partner, Description: "d", TalkingPoints: "t",
Keywords: []string{"k"}, Hashtags: []string{"#h"}, Subreddits: []string{"selfhosted"}}
if _, err := Fill(context.Background(), fake, e, srv.URL, nil, nil); err != nil {
if _, err := Fill(context.Background(), fake, e, srv.URL, nil); err != nil {
t.Fatal(err)
}
if fake.calls != 0 {
@@ -94,58 +92,31 @@ func TestFillSkipsTheModelWhenNothingIsLeft(t *testing.T) {
}
}
func TestFillChecksSuggestedSubreddits(t *testing.T) {
func TestFillSuggestsSubreddits(t *testing.T) {
srv := rivalSite(t)
fake := &fakeAI{reply: map[string]any{
"name": "", "description": "", "talking_points": "", "keywords": []string{}, "hashtags": []string{},
"subreddits": []map[string]string{
{"name": "r/selfhosted", "why": "self-hosters"},
{"name": "SelfHosted", "why": "again"},
{"name": "madeupwidgets", "why": "invented"},
{"name": "secretclub", "why": "private"},
{"name": "announcements", "why": "restricted"},
{"name": "homelab", "why": "home servers"},
{"name": "slowreddit", "why": "rate limited"},
{"name": "not a name!", "why": "junk"},
{"name": "https://www.reddit.com/r/homelab/", "why": "home servers"},
{"name": "one", "why": ""}, {"name": "two", "why": ""}, {"name": "three", "why": ""}, {"name": "four", "why": ""},
},
}}
check := func(_ context.Context, name string) (*reddit.Subreddit, error) {
switch name {
case "selfhosted":
return &reddit.Subreddit{Name: "selfhosted", Type: "public", Subscribers: 500000}, nil
case "homelab":
return &reddit.Subreddit{Name: "homelab", Type: "public"}, nil
case "secretclub":
return nil, reddit.ErrForbidden
case "announcements":
return &reddit.Subreddit{Name: "announcements", Type: "restricted"}, nil
case "slowreddit":
return nil, errors.New("rate limited")
}
return nil, reddit.ErrNotFound
}
e := &Entry{Name: "Rival", Relationship: Partner}
res, err := Fill(context.Background(), fake, e, srv.URL, nil, check)
res, err := Fill(context.Background(), fake, e, srv.URL, nil)
if err != nil {
t.Fatal(err)
}
if got := strings.Join(e.Subreddits, ","); got != "selfhosted,homelab,slowreddit" {
if got := strings.Join(e.Subreddits, ","); got != "selfhosted,homelab,one,two,three" {
t.Errorf("subreddits = %q", got)
}
var notes []string
for _, sg := range res.Suggestions {
notes = append(notes, fmt.Sprintf("%s:%v", sg.Name, sg.Kept))
}
if got := strings.Join(notes, " "); got != "selfhosted:true madeupwidgets:false secretclub:false announcements:false homelab:true slowreddit:true" {
if got := strings.Join(notes, " "); got != "selfhosted:true homelab:true one:true two:true three:true four:false" {
t.Errorf("suggestions = %s", got)
}
if res.Suggestions[5].Problem == "" || res.Suggestions[0].Info == nil {
t.Errorf("unchecked one should say so, checked one should carry its info: %+v", res.Suggestions)
}
// Without a check, suggestions are kept, marked unchecked.
e = &Entry{Name: "Rival", Relationship: Partner}
res, _ = Fill(context.Background(), fake, e, srv.URL, nil, nil)
if len(e.Subreddits) != 5 || !strings.Contains(res.Suggestions[0].Problem, "not checked") {
t.Errorf("unchecked: %q %+v", e.Subreddits, res.Suggestions)
}
}