package main // Issue 1859/AC8: the local run serves the real page on 127.0.0.1 alone, with invented mail and an in-memory // mail reading — no bus, store or Keycloak; every section of the list has something in it, and a task ticked // is under handled today, then back once undone. import ( "io" "net/http" "net/url" "os" "path/filepath" "reflect" "regexp" "strings" "testing" "time" ) func fetch(t *testing.T, c *http.Client, method, u string, form url.Values) (int, string) { t.Helper() var resp *http.Response var err error if method == http.MethodPost { resp, err = c.PostForm(u, form) } else { resp, err = c.Get(u) } if err != nil { t.Fatal(err) } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) return resp.StatusCode, string(body) } // section is the part of the page from one section's opening to the next's. func section(t *testing.T, body, id string) string { t.Helper() i := strings.Index(body, `id="`+id+`"`) if i < 0 { t.Fatalf("the page has no section %s", id) } rest := body[i:] if j := strings.Index(rest[1:], "
= 0 { return rest[:j+1] } return rest } var tokenField = regexp.MustCompile(`name="csrf_token" value="([^"]+)"`) // 1859/AC8. func TestTheLocalRunServesThePageWithEverySectionAndItsForms(t *testing.T) { if _, err := start("0.0.0.0:0", time.Time{}); err == nil { t.Fatal("the local run listened beyond 127.0.0.1") } thursday := time.Date(2026, 10, 22, 9, 0, 0, 0, brussels) run, err := start("127.0.0.1:0", thursday) if err != nil { t.Fatal(err) } defer run.Close() if !strings.HasPrefix(run.URL, "http://127.0.0.1:") { t.Fatalf("serves at %s", run.URL) } c := &http.Client{Timeout: 5 * time.Second} code, body := fetch(t, c, http.MethodGet, run.URL, nil) if code != http.StatusOK { t.Fatalf("/: status %d:\n%s", code, body) } for _, id := range []string{"greeting", "today", "this-week", "later", "you-promised", "waiting-on-others", "on-its-way", "good-to-know", "read-later", "handled-today", "scam-warnings"} { if s := section(t, body, id); id != "greeting" && !strings.Contains(s, `