Phase 4 part 6: the dashboard, CSV exports and an open metrics page

The MRR page adds churn, CLV, CAC and CLV:CAC. Eight tables download as
CSV (MRR, NRR and revenue cohorts, CAC by month and channel, spend,
products, customers). Metrics → Publish builds an open metrics page from
chosen totals only (never a customer) and opens a pull request that adds
or updates it on the site, checked with a Hugo build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:28:50 -07:00
co-authored by Claude Opus 5.5
parent 23f765159f
commit 152c14b580
18 changed files with 637 additions and 5 deletions
+28
View File
@@ -111,3 +111,31 @@ func TestSetupSite(t *testing.T) {
t.Error("the setup isn't kept")
}
}
func TestPublishPage(t *testing.T) {
if hugorepo.HugoVersion(context.Background()) == "" {
t.Skip("no hugo")
}
clone := hugotest.Site(t)
n := 0
g := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.URL.Path == "/api/v1/repos/o/site":
json.NewEncoder(w).Encode(map[string]any{"full_name": "o/site", "default_branch": "main", "clone_url": clone, "permissions": map[string]any{"push": true}})
case r.URL.Path == "/api/v1/repos/o/site/pulls":
n++
json.NewEncoder(w).Encode(map[string]any{"number": n, "html_url": fmt.Sprintf("https://gitea.example/pr/%d", n)})
}
}))
defer g.Close()
ap := &Applier{Gitea: gitea.New(g.URL, "tok"), Repo: "o/site", ReposDir: filepath.Join(t.TempDir(), "sites"), Author: "P <p@example.com>"}
pr, file, err := ap.PublishPage(context.Background(), "/metrics/", "Open metrics", "Our numbers.", "MRR: $150\n", "why")
if err != nil || pr.Number != 1 || file != "content/metrics.md" {
t.Fatalf("publish: %+v %q %v", pr, file, err)
}
repo := strings.TrimPrefix(clone, "file://")
out, _ := exec.Command("git", "-C", repo, "show", "supermarket/page-metrics:content/metrics.md").CombinedOutput()
if !strings.Contains(string(out), `title: "Open metrics"`) || !strings.Contains(string(out), "MRR: $150") {
t.Errorf("page: %s", out)
}
}