Phase 5 part 5: check the live site after a merge
Merged Sites pages are checked on the live site until they answer with their own words and title; removed ones until they're gone. The SEO loop, the page, the signal's page and Sites → Publishing check (or Check now); two hours without the page points at the deploy hook. Pages going live or away go to IndexNow. Sites → Publishing lists what's waiting, open pull requests and recent merges. Schema 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/signals"
|
||||
@@ -219,8 +220,16 @@ func TestSitePageBuilder(t *testing.T) {
|
||||
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) { return cannedAI{string(composed)}, nil }
|
||||
defer func() { newAIClient = ai.New }()
|
||||
|
||||
live := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/for-churches/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, `<html><head><title>For churches · Us</title></head><body><h1>For churches</h1><h2>Run your church on one bill</h2></body></html>`)
|
||||
}))
|
||||
defer live.Close()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Description: "Widgets.", Websites: []profile.Website{{URL: "https://us.example/", Repo: "Us/site"}}})
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Description: "Widgets.", Websites: []profile.Website{{URL: live.URL + "/", Repo: "Us/site"}}})
|
||||
sig := &signals.Signal{Name: "Churches", Slug: "churches", Status: "testing"}
|
||||
if err := signals.Save(s.DB, sig); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -296,7 +305,8 @@ func TestSitePageBuilder(t *testing.T) {
|
||||
|
||||
// Gitea says it's merged: the page shows it, and can't be edited.
|
||||
body = do(h, http.MethodGet, "/sites/pages/1", nil, nil).Body.String()
|
||||
if !strings.Contains(body, ">merged<") || strings.Contains(body, `name="sections"`) {
|
||||
if !strings.Contains(body, ">live<") || !strings.Contains(body, "On the live site since") || !strings.Contains(body, "Live: the title and the words match.") ||
|
||||
strings.Contains(body, `name="sections"`) {
|
||||
t.Errorf("merged: %s", body)
|
||||
}
|
||||
if body := postForm(h, "/sites/pages/1/save", form(good)).Body.String(); !strings.Contains(body, "can't be changed") {
|
||||
@@ -358,8 +368,17 @@ func TestSignalLandingPages(t *testing.T) {
|
||||
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) { return cannedAI{string(composed)}, nil }
|
||||
defer func() { newAIClient = ai.New }()
|
||||
|
||||
gone := false
|
||||
live := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/for-churches/" || gone {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, `<html><head><title>For churches</title></head><body><h2>One bill</h2></body></html>`)
|
||||
}))
|
||||
defer live.Close()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Description: "Widgets.", Websites: []profile.Website{{URL: "https://us.example/", Repo: "Us/site"}}})
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Description: "Widgets.", Websites: []profile.Website{{URL: live.URL + "/", Repo: "Us/site", PlausibleSite: "us.example"}}})
|
||||
sig := &signals.Signal{Name: "Churches", Slug: "churches", Status: "testing"}
|
||||
signals.Save(s.DB, sig)
|
||||
sigURL := "/signals/" + strconv.FormatInt(sig.ID, 10)
|
||||
@@ -383,7 +402,7 @@ func TestSignalLandingPages(t *testing.T) {
|
||||
t.Fatalf("merge: %s", out)
|
||||
}
|
||||
body = do(h, http.MethodGet, sigURL, nil, nil).Body.String()
|
||||
if !strings.Contains(body, `href="https://us.example/for-churches/"`) || !strings.Contains(body, ">merged<") || !strings.Contains(body, "<td>42</td>") ||
|
||||
if !strings.Contains(body, `href="`+live.URL+`/for-churches/"`) || !strings.Contains(body, ">live<") || !strings.Contains(body, "<td>42</td>") ||
|
||||
!strings.Contains(body, "Remove from the site") {
|
||||
t.Errorf("live page: %s", body)
|
||||
}
|
||||
@@ -436,10 +455,67 @@ func TestSignalLandingPages(t *testing.T) {
|
||||
t.Errorf("removing: %s", body)
|
||||
}
|
||||
merged["3"] = true
|
||||
if body := do(h, http.MethodGet, sigURL, nil, nil).Body.String(); !strings.Contains(body, ">removed<") {
|
||||
if body := do(h, http.MethodGet, sigURL, nil, nil).Body.String(); !strings.Contains(body, "removal merged, still on the site") {
|
||||
t.Errorf("removal merged: %s", body)
|
||||
}
|
||||
// The site's deploy takes it off; the publishing page's check sees it.
|
||||
gone = true
|
||||
p, _ := sites.GetPage(s.DB, 1)
|
||||
p.CheckedAt = time.Time{}
|
||||
sites.SavePage(s.DB, p)
|
||||
if body := do(h, http.MethodGet, "/sites/pages/1", nil, nil).Body.String(); !strings.Contains(body, "Off the live site since") || !strings.Contains(body, ">removed<") {
|
||||
t.Errorf("removed: %s", body)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/signals", nil, nil).Body.String(); strings.Contains(body, "Landing pages on your website") {
|
||||
t.Error("still counted as live")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSitesPublishing(t *testing.T) {
|
||||
g := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/repos/Us/site/pulls":
|
||||
if r.URL.Query().Get("state") != "closed" {
|
||||
t.Errorf("query: %s", r.URL.RawQuery)
|
||||
}
|
||||
fmt.Fprint(w, `[
|
||||
{"number":5,"state":"closed","merged":true,"merged_at":"2026-11-22T09:00:00Z","title":"Sites: landing page /for-churches/","head":{"ref":"supermarket/site-page-1"},"html_url":"https://g/5"},
|
||||
{"number":4,"state":"closed","merged":false,"title":"Abandoned","head":{"ref":"x"}},
|
||||
{"number":3,"state":"closed","merged":true,"merged_at":"2026-11-21T09:00:00Z","title":"Fix the footer","head":{"ref":"footer"},"user":{"login":"carly"},"html_url":"https://g/3"}]`)
|
||||
case "/api/v1/repos/Us/site/pulls/5":
|
||||
fmt.Fprint(w, `{"number":5,"state":"closed","merged":true,"merged_at":"2026-11-22T09:00:00Z"}`)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer g.Close()
|
||||
live := httptest.NewServer(http.NotFoundHandler())
|
||||
defer live.Close()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: live.URL + "/", Repo: "Us/site"}}})
|
||||
postForm(h, "/settings/search", url.Values{"gitea_url": {g.URL}, secrets.GiteaToken: {"tok"}})
|
||||
p := &sites.SitePage{Site: live.URL, Repo: "Us/site", Kind: "landing", Path: "/for-churches/", Title: "For churches",
|
||||
Status: sites.PagePR, PRNumber: 5, Branch: "supermarket/site-page-1", Sections: "- type: hero\n title: Hi\n"}
|
||||
if err := sites.SavePage(s.DB, p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
body := do(h, http.MethodGet, "/sites/publishing", nil, nil).Body.String()
|
||||
for _, want := range []string{
|
||||
// The merge was noticed, and the page isn't live yet.
|
||||
`<a href="/sites/pages/1">For churches</a>`, "Not on the site yet (it answers 404).",
|
||||
`href="https://g/5"`, "Sites: landing page /for-churches/", "<td class=\"small\">Supermarket</td>", "merged, not live yet",
|
||||
"Fix the footer", "carly",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("missing %q in %s", want, body)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, "Abandoned") {
|
||||
t.Error("an unmerged pull request is listed")
|
||||
}
|
||||
// The page editor offers a check now.
|
||||
if body := do(h, http.MethodGet, "/sites/pages/1", nil, nil).Body.String(); !strings.Contains(body, "Check the live site now") {
|
||||
t.Errorf("page: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user