Files
mesh-catalog/modules/mesh-knowledge/cmd/mesh-knowledge/page_test.go
T
jschoubben df79ab8769 mesh-knowledge: the overview's delivery block and the progress verb's groups lines go
Review round 1, Must 3: the groups and group-ended are retired; the overview
showed the deliveries, another module's state, which the status view owns.
The overview keeps two sources (the tracker, the asks), consumes no merge,
transition or pipeline's end, and the progress verb asks no groups.

Builds: design 47 H §764 (the gate's verb groups; the runner's group-ended); H-A-28; H-A-125

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 06:04:16 +01:00

70 lines
2.9 KiB
Go

package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"slices"
"strconv"
"strings"
"testing"
"time"
)
// The page's handler answers GET and nothing else; its manifest declares the port for this machine only and requires a route
// (ADR 0616 §4, AC P2).
func TestThePageAnswersGetOnlyAndTheManifestKeepsItToThisMachine(t *testing.T) {
w := newOverviewWorld(t)
w.entries = []*Entry{recordEntry(301, StatusAccepted, "2026-11-02", w.now.Add(-24*time.Hour), nil)}
w.o.Start()
h := PageHandler(w.o)
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil))
body := rec.Body.String()
if rec.Code != 200 || !strings.Contains(body, "Design 47, milestone 1") || !strings.Contains(body, "ADR 0301") || !strings.Contains(body, "Approve ADR 0301") ||
strings.Contains(body, "Delivery") { // no delivery block (design 47 H, H-A-125)
t.Fatalf("%d\n%.600s", rec.Code, body)
}
if strings.Contains(body, "<form") || strings.Contains(body, "<script") || !strings.Contains(rec.Header().Get("Content-Security-Policy"), "default-src 'none'") {
t.Fatalf("the page carries a form or a script, or no policy: %v", rec.Header())
}
for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodHead, http.MethodOptions} {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest(method, "/", strings.NewReader("x")))
if rec.Code != http.StatusMethodNotAllowed || rec.Header().Get("Allow") != http.MethodGet {
t.Errorf("%s answered %d", method, rec.Code)
}
}
if rec := httptest.NewRecorder(); func() int { h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/other", nil)); return rec.Code }() != 404 {
t.Error("another path answered")
}
// A source that does not answer is said on the page, never shown as an empty list.
w.fail[AsksVerb] = true
w.o.Rebuild(SourceAsks)
rec = httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil))
if !strings.Contains(rec.Body.String(), "The operator channel does not answer") || !strings.Contains(rec.Body.String(), "verb: no answer in time") {
t.Fatalf("%.1500s", rec.Body.String())
}
// The manifest: the port listens from this machine, the route is required and the page is the one the code serves.
_, raw := readManifest(t)
var m struct {
Requires []any `json:"requires"`
Listens []struct {
Name string `json:"name"`
Port int `json:"port"`
From string `json:"from"`
} `json:"listens"`
Contributes map[string]map[string]string `json:"contributes"`
}
if err := json.Unmarshal([]byte(raw), &m); err != nil {
t.Fatal(err)
}
if len(m.Listens) != 1 || m.Listens[0].From != "machine" || ":"+strconv.Itoa(m.Listens[0].Port) != PageAddress || m.Contributes["route"]["endpoint"] != m.Listens[0].Name {
t.Fatalf("%+v", m)
}
if !slices.Contains(m.Requires, any("route")) {
t.Fatal("the route is not required")
}
}