Phase 3 part 3: the audit, ranked by traffic, with AI visibility

A polite crawl of each website (Search Console's busiest pages, the
sitemap, then links; up to 300 pages; robots.txt honoured) checks titles
and descriptions (characters and pixels), headings, canonical, noindex,
status and redirects, broken links (outside ones twice), alt text, Open
Graph, JSON-LD, text without JavaScript, and whether the title says what
the page's main search asks. Issues are ranked by severity, then the
page's clicks and impressions. AI visibility: AI crawlers in robots.txt,
llms.txt, structured data, Organization data. Optional PageSpeed checks.
Weekly in the background, or Audit now. Schema 14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 07:53:10 -07:00
co-authored by Claude Opus 5.5
parent a7de13087e
commit 43a7b42126
21 changed files with 1643 additions and 17 deletions
+64
View File
@@ -0,0 +1,64 @@
package web
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"supermarket/internal/profile"
"supermarket/internal/seo"
)
func TestAuditPage(t *testing.T) {
var srv *httptest.Server
srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, `<html><head><title>Home</title></head><body><h1>Hi</h1><a href="/nope/">x</a></body></html>`)
case "/sitemap.xml":
fmt.Fprintf(w, `<urlset><url><loc>%s/</loc></url></urlset>`, srv.URL)
default:
http.NotFound(w, r)
}
}))
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/audit", nil, nil).Body.String(); !strings.Contains(body, "Not audited yet") {
t.Fatal("no empty state")
}
if rec := postForm(h, "/seo/audit?site=0", nil); rec.Code != http.StatusSeeOther {
t.Fatalf("start: %d %s", rec.Code, rec.Body)
}
deadline := time.Now().Add(10 * time.Second)
for {
a, _ := seo.LatestAudit(s.DB, srv.URL)
if a != nil && a.Status != "running" {
if a.Status != "done" {
t.Fatalf("audit: %+v", a)
}
break
}
if time.Now().After(deadline) {
t.Fatal("the audit didn't finish")
}
time.Sleep(50 * time.Millisecond)
}
if rec := do(h, http.MethodGet, "/seo/audit/status?site=0", nil, nil); rec.Header().Get("HX-Refresh") != "true" {
t.Error("the status poll doesn't reload when done")
}
body := do(h, http.MethodGet, "/seo/audit", nil, nil).Body.String()
for _, want := range []string{"AI visibility", "No llms.txt", "Answers 404", "/nope/", "Title very short", "pages read"} {
if !strings.Contains(body, want) {
t.Errorf("audit page lacks %q", want)
}
}
if body := do(h, http.MethodGet, "/seo/audit?severity=error", nil, nil).Body.String(); strings.Contains(body, "Title very short") {
t.Error("the severity filter shows notices")
}
}