oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1package theme
2
3import (
4 "crypto/sha256"
5 "encoding/hex"
6 "net/http"
7 "net/http/httptest"
8 "os"
9 "path/filepath"
10 "regexp"
11 "strings"
12 "testing"
13)
14
15// Paul, 2026-10-25 (AGENTS.md row 9): the chrome is the system UI face
16// and downloads nothing, because no webfont renders in WebKit without a
17// frame of invisible text. Held here, in the plain suite, so CI keeps it
18// without a browser (fonts_browser_test.go is the proof in one): the
19// token is the system stack, and no stylesheet estilo ships declares a
20// face or names Onest.
21func TestChromeFontIsSystemUI(t *testing.T) {
22 const want = `system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`
23 m := regexp.MustCompile(`--rst-font:\s*([^;]+);`).FindAllSubmatch(css, -1)
24 if len(m) != 1 || string(m[0][1]) != want {
25 t.Fatalf("--rst-font = %q, want the system UI stack %q", m, want)
26 }
27 sheets, _ := filepath.Glob("../*/*.css")
28 if len(sheets) < 8 {
29 t.Fatalf("found only %d stylesheets; the scan would pass vacuously", len(sheets))
30 }
31 for _, p := range sheets {
32 b, err := os.ReadFile(p)
33 if err != nil {
34 t.Fatal(err)
35 }
36 if strings.Contains(p, "testdata") {
37 continue
38 }
39 if regexp.MustCompile(`(?i)@font-face|\bonest\b`).Match(b) {
40 t.Errorf("%s declares a webfont or names Onest; the chrome downloads no font", p)
41 }
42 }
43}
44
45func TestFontHandlerServesOnlyV1sTwoFiles(t *testing.T) {
46 h := FontHandler()
47 for path, want := range map[string]int{
48 FontPrefix + "fonts.css": 200,
49 FontPrefix + "onest-latin.woff2": 200,
50 FontPrefix + "onest.woff2": 404,
51 FontPrefix + "../theme/estilo.css": 404,
52 FontPrefix: 404,
53 "/static/estilo/fonts/v2/fonts.css": 404,
54 "/static/other/onest-latin.woff2": 404,
55 } {
56 rec := httptest.NewRecorder()
57 h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
58 if rec.Code != want {
59 t.Errorf("GET %s = %d, want %d", path, rec.Code, want)
60 }
61 }
62 rec := httptest.NewRecorder()
63 h.ServeHTTP(rec, httptest.NewRequest(http.MethodPost, FontPrefix+"fonts.css", nil))
64 if rec.Code != http.StatusMethodNotAllowed {
65 t.Errorf("POST = %d, want 405", rec.Code)
66 }
67}
68
69// v1 answers exactly as it shipped (both sha256s are origin/main
70// f14458a's): cached for a year as immutable under these names, and a
71// page that still links them keeps working.
72func TestFontV1IsUnchanged(t *testing.T) {
73 for path, want := range map[string]string{
74 FontPrefix + "fonts.css": "2b3d039ae92b9f87aa549c364a25d9ee2199127e4c53deff8760482d13deb336",
75 FontPrefix + "onest-latin.woff2": "cc61cbd632bb677cd55f0eec9ebdd3e1525c5f30904cbf0769e2ac50d0fba992",
76 } {
77 rec := httptest.NewRecorder()
78 FontHandler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
79 sum := sha256.Sum256(rec.Body.Bytes())
80 if got := hex.EncodeToString(sum[:]); got != want {
81 t.Errorf("%s changed (sha256 %s); it is cached as immutable under that name", path, got)
82 }
83 }
84}
85