Phase 3 part 4: changes approved one at a time, as Gitea pull requests
Proposals (at most 3 waiting) for pages on page one without clicks and for the audit's title and description issues: the AI writes the title (without the site's suffix, within the pixel budget) and description from the live page and its searches. A yes syncs a working copy of the site's Gitea repository (token as a header only), finds the page's Hugo content file, sets title and description in its front matter, builds with Hugo to check the page comes out as proposed, pushes a branch and opens a pull request; it never merges. Merged changes are checked on the live site, then compared before and after from Search Console. Hugo is in the image. Schema 15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/secrets"
|
||||
"supermarket/internal/seo"
|
||||
)
|
||||
|
||||
func TestChangesPage(t *testing.T) {
|
||||
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) {
|
||||
return cannedAI{`{"title":"Plans and prices","description":"Every plan, what it costs, and what's included, per month."}`}, nil
|
||||
}
|
||||
defer func() { newAIClient = ai.New }()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprint(w, `<html><head><title>Pricing · Us</title></head><body><h1>Pricing</h1><p>Plans and prices.</p></body></html>`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: srv.URL}}})
|
||||
|
||||
body := do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String()
|
||||
for _, want := range []string{"Nothing waiting", "save a Gitea token", "set this website's Hugo repository"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("empty page lacks %q", want)
|
||||
}
|
||||
}
|
||||
rec := postForm(h, "/seo/changes/page?site=0", url.Values{"page": {srv.URL + "/pricing/"}, "why": {"Title too long."}})
|
||||
if rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("propose: %d %s", rec.Code, rec.Body)
|
||||
}
|
||||
body = do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String()
|
||||
for _, want := range []string{`value="Plans and prices · Us"`, "now: “Pricing · Us”", "Title too long.", "Yes: open a pull request"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("proposal lacks %q", want)
|
||||
}
|
||||
}
|
||||
cs, _ := seo.Changes(s.DB, srv.URL, 10)
|
||||
id := fmt.Sprint(cs[0].ID)
|
||||
postForm(h, "/seo/changes/"+id+"/save", url.Values{"new_title": {"Plans and prices from $5 · Us"}, "new_description": {"Edited."}})
|
||||
if c, _ := seo.GetChange(s.DB, cs[0].ID); c.NewTitle != "Plans and prices from $5 · Us" || c.NewDescription != "Edited." {
|
||||
t.Errorf("edit: %+v", c)
|
||||
}
|
||||
if rec := postForm(h, "/seo/changes/"+id+"/yes", nil); !strings.Contains(rec.Body.String(), "Save a Gitea token") {
|
||||
t.Errorf("yes without Gitea: %d", rec.Code)
|
||||
}
|
||||
postForm(h, "/seo/changes/"+id+"/no", nil)
|
||||
if c, _ := seo.GetChange(s.DB, cs[0].ID); c.Status != seo.ChangeDeclined {
|
||||
t.Errorf("no: %+v", c.Status)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String(); !strings.Contains(body, "You said no") {
|
||||
t.Error("declined change isn't listed")
|
||||
}
|
||||
// Gitea settings.
|
||||
postForm(h, "/settings/search", url.Values{"gitea_url": {"https://gitea.example.com/"}, secrets.GiteaToken: {"tok"}})
|
||||
if s.giteaURL() != "https://gitea.example.com" || s.gitea() == nil {
|
||||
t.Errorf("gitea settings: %q", s.giteaURL())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user