Phase 3 part 6: briefs and pages

A brief for a search (a new page) or a page (a rewrite) starts from what
Search Console shows the page for, reads the live top 5 with Claude's web
search (unread results marked, never guessed), and gives the title,
description, H1, angle, sections, questions, internal links to pages we
have, and the questions only the owner can answer. The page is drafted
around those answers, with no invented tests, prices or customers; every
sentence claiming an experience must be confirmed before a pull request
adds or rewrites the page, checked with a Hugo build. Merged pages are
followed to the live site. Schema 17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 08:18:49 -07:00
co-authored by Claude Opus 5.5
parent c0a5ddf77f
commit 68c224f51b
19 changed files with 1440 additions and 22 deletions
+76
View File
@@ -0,0 +1,76 @@
package web
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"supermarket/internal/ai"
"supermarket/internal/profile"
"supermarket/internal/secrets"
"supermarket/internal/seo"
)
type briefWriter struct{}
func (briefWriter) Generate(context.Context, ai.Request) (string, error) {
return "## Prices\n\nWe tested it with 12 users. Plans are flat.", nil
}
func (briefWriter) Research(context.Context, ai.ResearchRequest) (*ai.ResearchResult, error) {
return &ai.ResearchResult{Searches: 3, Text: `{"finding":"Nobody shows prices.","top":[{"url":"https://a.example","title":"A","promises":"a list","lacks":"prices","read":true}],
"plan":{"title":"Flat-price workspace","description":"Plans.","h1":"Workspace","angle":"Prices","sections":["Prices","Moving"],
"questions":["How much?"],"links":[],"ask":["Have you moved a team?"],"needs":[]}}`}, nil
}
func TestBriefPages(t *testing.T) {
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) { return briefWriter{}, nil }
defer func() { newAIClient = ai.New }()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, `<urlset></urlset>`) }))
defer srv.Close()
s, h := newTestServer(t, nil)
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: srv.URL}}})
if body := do(h, http.MethodGet, "/seo/briefs", nil, nil).Body.String(); !strings.Contains(body, "Write a brief") {
t.Fatal("no form")
}
rec := postForm(h, "/seo/briefs?site=0", url.Values{"keyword": {"workspace alternative"}})
if rec.Code != http.StatusSeeOther || !strings.HasPrefix(rec.Header().Get("Location"), "/seo/briefs/1") {
t.Fatalf("new: %d %s %s", rec.Code, rec.Header().Get("Location"), rec.Body)
}
body := do(h, http.MethodGet, "/seo/briefs/1", nil, nil).Body.String()
for _, want := range []string{"Nobody shows prices.", `value="Flat-price workspace"`, "Have you moved a team?", "/workspace-alternative/", "Write the page"} {
if !strings.Contains(body, want) {
t.Errorf("brief lacks %q", want)
}
}
form := url.Values{"title": {"Flat-price workspace"}, "description": {"Plans."}, "h1": {"Workspace"}, "angle": {"Prices"},
"sections": {"Prices\nMoving\nFAQ"}, "questions": {"How much?"}, "answer": {"Yes, 12 users."}, "path": {"/workspace/"}}
if rec := postForm(h, "/seo/briefs/1/write", form); rec.Code != http.StatusSeeOther {
t.Fatalf("write: %d %s", rec.Code, rec.Body)
}
b, _ := seo.GetBrief(s.DB, 1)
if len(b.Plan.Sections) != 3 || b.Path != "/workspace/" || b.Answers[0] != "Yes, 12 users." || b.Status != seo.BriefPage {
t.Errorf("saved: %+v", b)
}
body = do(h, http.MethodGet, "/seo/briefs/1", nil, nil).Body.String()
if !strings.Contains(body, "We tested it with 12 users.") || !strings.Contains(body, `name="claim" value="We tested it with 12 users."`) {
t.Error("the draft or its claim isn't shown")
}
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{}); !strings.Contains(rec.Body.String(), "save a Gitea token") {
t.Errorf("pr without Gitea: %d", rec.Code)
}
s.Secrets.Set(map[string]string{secrets.GiteaToken: "tok"})
s.DB.PutJSON(giteaURLKey, "https://gitea.example.com")
if rec := postForm(h, "/seo/briefs/1/pr", url.Values{"draft": {b.Draft}}); !strings.Contains(rec.Body.String(), "Tick each sentence") {
t.Errorf("pr with an unconfirmed claim: %d", rec.Code)
}
postForm(h, "/seo/briefs/1/drop", nil)
if body := do(h, http.MethodGet, "/seo/briefs", nil, nil).Body.String(); strings.Contains(body, "workspace alternative</a>") {
t.Error("a dropped brief is listed")
}
}