oficina / memoria Public

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

Plain git — no account needed to clone.

Download

Download this file

1package memoriatest
2
3// Gates for the shared chrome (estilo spec/shared-chrome, round 2; Memoria
4// is its §12.1 row 6). Each was run against origin/main 97b8a23 before the
5// change and failed there; the discussion quotes both runs.
6
7import (
8 "encoding/base64"
9 "net/http"
10 "net/url"
11 "os"
12 "path/filepath"
13 "regexp"
14 "strconv"
15 "strings"
16 "testing"
17
18 "golang.org/x/net/html"
19)
20
21var titleRe = regexp.MustCompile(`(?s)<title>(.*?)</title>`)
22
23func pageTitle(body string) string {
24 m := titleRe.FindStringSubmatch(body)
25 if m == nil {
26 return ""
27 }
28 return html.UnescapeString(strings.TrimSpace(m[1]))
29}
30
31func storedID(t *testing.T, h http.Handler) string {
32 t.Helper()
33 m := regexp.MustCompile(`href="/documents/(\d+)"`).FindStringSubmatch(get(t, h, "/documents").Body.String())
34 if m == nil {
35 t.Fatal("no stored document on the index")
36 }
37 return m[1]
38}
39
40// §3: an error is a page with the bar, for a browser; plain text for
41// anything else. Before: Go's "404 page not found" in monospace, and
42// "could not read that document".
43func TestHTMLErrorsRenderTheErrorPage(t *testing.T) {
44 dbPath := tempDB(t)
45 in, _ := signedInClient(t, dbPath)
46 h, _ := admissionApp(t, dbPath, []string{chromeOwner})
47 out := newClient(t, h)
48
49 cases := []struct {
50 name, path, title string
51 }{
52 {"unknown route", "/no/such/page", "Page not found · Memoria"},
53 {"missing document", "/documents/99999", "Document not available · Memoria"},
54 {"bad parameter", "/documents/not-a-number", "Document not available · Memoria"},
55 {"GET of a POST-only path", "/connectors/notion/sync", "Page not found · Memoria"},
56 }
57 for _, tc := range cases {
58 t.Run("signed in, "+tc.name, func(t *testing.T) {
59 rec := in.get(tc.path)
60 body := rec.Body.String()
61 if rec.Code != http.StatusNotFound || !strings.HasPrefix(rec.Header().Get("Content-Type"), "text/html") {
62 t.Fatalf("%s = %d %q, want a 404 page", tc.path, rec.Code, rec.Header().Get("Content-Type"))
63 }
64 if got := pageTitle(body); got != tc.title {
65 t.Errorf("title %q, want %q", got, tc.title)
66 }
67 if !strings.Contains(body, "<header estilo-bar") || !strings.Contains(body, "<details estilo-account") {
68 t.Error("the error page does not carry the bar with the viewer's account")
69 }
70 if !strings.Contains(body, "rst-error") {
71 t.Error("the error page is not estilo's error body")
72 }
73 })
74 }
75 t.Run("signed out, unknown route", func(t *testing.T) {
76 rec := out.get("/no/such/page")
77 body := rec.Body.String()
78 if rec.Code != http.StatusNotFound || !strings.HasPrefix(rec.Header().Get("Content-Type"), "text/html") {
79 t.Fatalf("= %d %q, want a 404 page", rec.Code, rec.Header().Get("Content-Type"))
80 }
81 if got := pageTitle(body); got != "Page not found · Memoria" {
82 t.Errorf("title %q", got)
83 }
84 if !strings.Contains(body, "<header estilo-bar") || strings.Contains(body, "estilo-account") || !strings.Contains(body, "estilo-bar-signin") {
85 t.Error("signed out, the error page should carry the bar with Sign in and no account")
86 }
87 })
88 t.Run("signed out, a guarded page is sign-in with the way back", func(t *testing.T) {
89 if got := location(t, out.get("/documents/99999")); got != "/signin?return_to=%2Fdocuments%2F99999" {
90 t.Errorf("Location %q", got)
91 }
92 })
93 t.Run("not a browser: plain text", func(t *testing.T) {
94 in.accept = "application/json"
95 defer func() { in.accept = "text/html" }()
96 for _, p := range []string{"/no/such/page", "/documents/99999"} {
97 rec := in.get(p)
98 if rec.Code != http.StatusNotFound || !strings.HasPrefix(rec.Header().Get("Content-Type"), "text/plain") {
99 t.Errorf("%s with Accept: application/json = %d %q, want plain text", p, rec.Code, rec.Header().Get("Content-Type"))
100 }
101 }
102 })
103 t.Run("another method is a 405 that names what is allowed", func(t *testing.T) {
104 rec := in.do(http.MethodDelete, "/documents/1", nil)
105 if rec.Code != http.StatusMethodNotAllowed || !strings.Contains(rec.Header().Get("Allow"), "GET") {
106 t.Errorf("DELETE /documents/1 = %d, Allow %q", rec.Code, rec.Header().Get("Allow"))
107 }
108 })
109}
110
111// §4: one notice vocabulary. rst-notice, a valued rst-callout and the
112// "warn" tone style nothing; a <p rst-callout-body> stacks its own margins
113// on the callout's padding (Memoria's double-height callouts).
114func TestTemplatesUseOnlyCalloutTones(t *testing.T) {
115 dir := filepath.Join("..", "memoria", "templates")
116 entries, err := os.ReadDir(dir)
117 if err != nil {
118 t.Fatal(err)
119 }
120 bad := regexp.MustCompile(`rst-notice|rst-callout="|rst-tone="warn"|<p rst-callout-body|rst-tone="info"`)
121 checked := 0
122 for _, e := range entries {
123 raw, err := os.ReadFile(filepath.Join(dir, e.Name()))
124 if err != nil {
125 t.Fatal(err)
126 }
127 checked++
128 for _, m := range bad.FindAllString(string(raw), -1) {
129 t.Errorf("%s writes %q, which is outside the callout vocabulary", e.Name(), m)
130 }
131 }
132 if checked == 0 {
133 t.Fatal("no templates read")
134 }
135}
136
137// §10: every <title> is "{part} · … · Memoria", built by the layout, and
138// the first part is the page's h1. The titles mixed "—" and "·" before.
139func TestPageTitlesFollowTheSuitePattern(t *testing.T) {
140 h := newApp(t)
141 store(t, h, "Minutes, 12 September", "We agreed to move the offsite to November.")
142 id := storedID(t, h)
143 for path, want := range map[string]string{
144 "/": "Memoria",
145 "/?q=offsite": "“offsite” · Memoria",
146 "/add": "Add content · Memoria",
147 "/documents/" + id: "Minutes, 12 September · Memoria",
148 "/documents/" + id + "/delete": "Delete document · Minutes, 12 September · Memoria",
149 "/connectors": "Sources · Memoria",
150 "/connectors/notion": "Notion · Memoria",
151 "/help/open-source": "Open source · Memoria",
152 } {
153 if got := pageTitle(get(t, h, path).Body.String()); got != want {
154 t.Errorf("%s: title %q, want %q", path, got, want)
155 }
156 }
157 // The sign-in door's titles are rastrillo's for its state (the smart
158 // door, 2026-11-22), which name the app themselves; the signed-out
159 // page keeps the suite's pattern.
160 so, _ := signinApp(t)
161 for path, want := range map[string]string{
162 "/signin": "Sign in to Memoria",
163 "/signin?sent=1": "Check your email to sign in to Memoria",
164 "/signin?err=expired": "Problem signing in to Memoria",
165 "/signed-out": "Signed out · Memoria",
166 } {
167 if got := pageTitle(get(t, so, path).Body.String()); got != want {
168 t.Errorf("%s: title %q, want %q", path, got, want)
169 }
170 }
171}
172
173// §8.2: one account menu, the last thing in the bar, with the one Sign
174// out in the app; Appearance; Help ending in Open source. Before: a Help
175// dropdown, Sources and a Sign out button in a nav that wrapped.
176func TestEverySignedInPageHasOneSignOutInTheSameCorner(t *testing.T) {
177 h := newApp(t)
178 store(t, h, "Notes", "hosting migration notes")
179 id := storedID(t, h)
180 for _, path := range []string{"/", "/?q=hosting", "/add", "/documents/" + id, "/documents/" + id + "/delete", "/connectors", "/connectors/notion", "/help/open-source"} {
181 doc := parsePage(t, get(t, h, path).Body.String())
182 signOuts := findAll(doc, func(n *html.Node) bool {
183 return (n.Data == "button" || n.Data == "a") && strings.TrimSpace(textOf(n)) == "Sign out"
184 })
185 if len(signOuts) != 1 {
186 t.Errorf("%s: %d Sign outs, want exactly one", path, len(signOuts))
187 continue
188 }
189 ends := findAll(doc, hasAttr("estilo-bar-end"))
190 if len(ends) != 1 {
191 t.Errorf("%s: %d [estilo-bar-end]", path, len(ends))
192 continue
193 }
194 var last *html.Node
195 for c := ends[0].FirstChild; c != nil; c = c.NextSibling {
196 if c.Type == html.ElementNode {
197 last = c
198 }
199 }
200 if last == nil || last.Data != "details" {
201 t.Errorf("%s: the bar does not end with the account menu", path)
202 continue
203 }
204 if _, ok := attrOf(last, "estilo-account"); !ok {
205 t.Errorf("%s: the last thing in the bar is not the account menu", path)
206 }
207 if !within(signOuts[0], last) {
208 t.Errorf("%s: Sign out is not in the account menu", path)
209 }
210 account := textOf(last)
211 for _, want := range []string{"Signed in as", memoriaTestOwner(), "Appearance", "Light", "Dark", "System", "Help", "Open source"} {
212 if !strings.Contains(account, want) {
213 t.Errorf("%s: the account menu lacks %q", path, want)
214 }
215 }
216 pressed := findAll(last, func(n *html.Node) bool {
217 v, ok := attrOf(n, "aria-pressed")
218 return ok && (v == "true" || v == "false")
219 })
220 if len(pressed) != 3 {
221 t.Errorf("%s: %d Appearance options carry aria-pressed, want 3", path, len(pressed))
222 }
223 if strings.Contains(textOf(doc), "Connect Home account") || len(findAll(doc, hasAttr("rst-dropdown"))) != 0 {
224 t.Errorf("%s: the old header's Help dropdown or \"Connect Home account\" is still there", path)
225 }
226 }
227}
228
229func memoriaTestOwner() string { return "owner@test" }
230
231// §8.4: signed out, the corner is a plain "Sign in" back to this page; on
232// the sign-in pages themselves it is empty.
233func TestTheSignedOutCorner(t *testing.T) {
234 h, _ := signinApp(t)
235 body := newClient(t, h).get("/no/such/page?x=1").Body.String()
236 doc := parsePage(t, body)
237 signIns := findAll(doc, hasAttr("estilo-bar-signin"))
238 if len(signIns) != 1 {
239 t.Fatalf("%d Sign in links in the bar", len(signIns))
240 }
241 if href, _ := attrOf(signIns[0], "href"); href != "/signin?return_to=%2Fno%2Fsuch%2Fpage%3Fx%3D1" {
242 t.Errorf("Sign in goes to %q, want back to this page", href)
243 }
244 for _, path := range []string{"/signin", "/signin?sent=1", "/signed-out"} {
245 b := get(t, h, path).Body.String()
246 if !strings.Contains(b, "<header estilo-bar") || strings.Contains(b, "estilo-bar-signin") || strings.Contains(b, "estilo-account") {
247 t.Errorf("%s: the corner of a sign-in page should be empty, under the bar", path)
248 }
249 }
250}
251
252// §12.1 (Memoria): Sources is a nav link with aria-current, rendered only
253// for owners — /connectors 404s everyone else, so a non-owner must never
254// be shown the link.
255func TestSourcesIsANavLinkForOwnersOnly(t *testing.T) {
256 h, app := newAppWithTestApp(t)
257 doc := parsePage(t, get(t, h, "/connectors").Body.String())
258 links := findAll(doc, func(n *html.Node) bool {
259 href, _ := attrOf(n, "href")
260 return n.Data == "a" && href == "/connectors" && n.Parent != nil && hasAttr("estilo-bar-nav")(n.Parent)
261 })
262 if len(links) != 1 {
263 t.Fatalf("%d Sources links in the bar's nav, want 1", len(links))
264 }
265 if v, _ := attrOf(links[0], "aria-current"); v != "page" {
266 t.Error("on /connectors the Sources link is not aria-current")
267 }
268 app.AsPerson("reader@test")
269 if b := get(t, h, "/").Body.String(); strings.Contains(b, `href="/connectors"`) {
270 t.Error("a non-owner is shown the Sources link")
271 }
272}
273
274// §8.3: Appearance posts to /appearance, sets one host-only cookie and
275// returns; the layout writes data-theme from it. Outside the session gate,
276// so an expired session cannot turn the click into a sign-in loop.
277func TestAppearance(t *testing.T) {
278 dbPath := tempDB(t)
279 c, _ := signedInClient(t, dbPath)
280 rec := c.do(http.MethodPost, "/appearance", url.Values{"mode": {"dark"}, "return_to": {"/add"}})
281 if got := location(t, rec); got != "/add" {
282 t.Errorf("Appearance returned to %q, want /add", got)
283 }
284 if c.cookies["estilo_appearance"] == nil || c.cookies["estilo_appearance"].Value != "dark" {
285 t.Fatal("no estilo_appearance=dark cookie")
286 }
287 if !strings.Contains(c.get("/add").Body.String(), `<html lang="en" data-theme="dark">`) {
288 t.Error("the page does not carry data-theme=dark")
289 }
290 h, _ := admissionApp(t, tempDB(t), []string{chromeOwner})
291 out := newClient(t, h)
292 if got := location(t, out.do(http.MethodPost, "/appearance", url.Values{"mode": {"light"}, "return_to": {"//evil.example/"}})); got != "/" {
293 t.Errorf("an off-site return_to went to %q, want /", got)
294 }
295}
296
297// §9.4: a document link opened signed out comes back to that document
298// after sign-in, through a sealed cookie; "Use a different address" keeps
299// it; a plain /signin forgets it.
300func TestASignedOutDeepLinkComesBackAfterSignIn(t *testing.T) {
301 h, mailer := admissionApp(t, tempDB(t), []string{chromeOwner})
302 c := newClient(t, h)
303 const deep = "/documents/7?x=1"
304 signin := location(t, c.get(deep))
305 if signin != "/signin?return_to=%2Fdocuments%2F7%3Fx%3D1" {
306 t.Fatalf("a signed-out deep link went to %q", signin)
307 }
308 c.get(signin)
309 var ret *http.Cookie
310 for name, ck := range c.cookies {
311 if strings.Contains(name, "return") {
312 ret = ck
313 }
314 }
315 if ret == nil {
316 t.Fatal("GET /signin?return_to= remembered nothing")
317 }
318 raw, _ := base64.RawURLEncoding.DecodeString(ret.Value)
319 if strings.Contains(ret.Value, "documents") || strings.Contains(string(raw), "documents") || !ret.HttpOnly {
320 t.Error("the return cookie is not sealed (the path reads straight out of it)")
321 }
322 // The door's form posts the page (the smart door's st.ReturnTo), and
323 // POST /auth/begin keeps it in the return memory, off rastrillo's form.
324 door := c.get(signin).Body.String()
325 begin := doorForm(door, "/auth/begin")
326 if begin.Get("return_to") != deep {
327 t.Fatalf("the door's form posts return_to %q, want %q", begin.Get("return_to"), deep)
328 }
329 begin.Set("address", chromeOwner)
330 sent := location(t, c.do(http.MethodPost, "/auth/begin", begin))
331 body := c.get(sent).Body.String()
332 forget := doorForm(body, "/signin/forget")
333 if forget == nil || forget.Get("return_to") != deep || !strings.Contains(body, "Use a different email") {
334 t.Errorf("\"Use a different email\" does not keep the return:\n%s", body)
335 }
336 u, _ := url.Parse(mailer.link())
337 dest := location(t, c.openLink(u.RequestURI()))
338 for i := 0; i < 3 && dest != deep && strings.HasPrefix(dest, "/auth/"); i++ {
339 dest = location(t, c.get(dest))
340 }
341 if dest != deep {
342 t.Errorf("sign-in landed on %q, want %q", dest, deep)
343 }
344
345 // Tampered, the cookie is ignored: the landing is the index.
346 c2 := newClient(t, h)
347 c2.get("/signin?return_to=%2Fadd")
348 for name, ck := range c2.cookies {
349 if strings.Contains(name, "return") {
350 v := []byte(ck.Value)
351 v[len(v)/2] ^= 1
352 c2.cookies[name] = &http.Cookie{Name: name, Value: string(v)}
353 }
354 }
355 if got := location(t, c2.get("/auth/landed")); got != "/" {
356 t.Errorf("a tampered return cookie still steered the landing to %q", got)
357 }
358 // And an off-site return_to is not remembered at all.
359 c3 := newClient(t, h)
360 c3.get("/signin?return_to=%2F%2Fevil.example%2F")
361 if got := location(t, c3.get("/auth/landed")); got != "/" {
362 t.Errorf("an off-site return_to steered the landing to %q", got)
363 }
364}
365
366// §9.2: already signed in, /signin skips the form to a safe return_to. And
367// the trap Astra found in Docs, Sheets and Slides: the admission check
368// runs FIRST, so a removed owner is signed out and told, once — not
369// bounced between /signin and a page that refuses them.
370func TestSigninWhenAlreadySignedInRunsTheAdmissionCheckFirst(t *testing.T) {
371 dbPath := tempDB(t)
372 c, _ := signedInClient(t, dbPath)
373 if got := location(t, c.get("/signin?return_to=%2Fadd")); got != "/add" {
374 t.Errorf("signed in, /signin?return_to=/add went to %q", got)
375 }
376 if got := location(t, c.get("/signin?return_to=%2F%2Fevil.example")); got != "/" {
377 t.Errorf("signed in, an off-site return_to went to %q", got)
378 }
379
380 // The owner is removed. Same database, same session cookie. Since
381 // the smart door, /signin's admission probe answers with the door
382 // itself, saying why, and ends the session on that response.
383 h2, _ := admissionApp(t, dbPath, []string{"someone-else@example.test"})
384 c.h = h2
385 rec := c.get("/signin")
386 if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "Your access has been removed") {
387 t.Fatalf("a removed owner at /signin = %d %q, want the door with the removal", rec.Code, rec.Header().Get("Location"))
388 }
389 // offboard's own landing still says it.
390 rec = c.get("/signin?err=removed")
391 if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "Your access has been removed") {
392 t.Errorf("the removed page = %d, and does not say so", rec.Code)
393 }
394 if !strings.Contains(location(t, c.get("/")), "/signin?return_to=") {
395 t.Error("the removed owner's session survived")
396 }
397}
398
399// And the gate itself: a removed owner meets the same sentence on any
400// page, instead of a 404 on every page until the session lapses.
401func TestARemovedOwnerIsToldOnAnyPage(t *testing.T) {
402 dbPath := tempDB(t)
403 c, _ := signedInClient(t, dbPath)
404 h2, _ := admissionApp(t, dbPath, []string{"someone-else@example.test"})
405 c.h = h2
406 if got := location(t, c.get("/add")); got != "/signin?err=removed" {
407 t.Errorf("a removed owner at /add went to %q", got)
408 }
409}
410
411// §9.2: Sign out lands on "You're signed out", not a bare sign-in form.
412func TestSignOutLandsOnTheSignedOutPage(t *testing.T) {
413 c, _ := signedInClient(t, tempDB(t))
414 dest := location(t, c.do(http.MethodPost, "/signout", url.Values{}))
415 if dest != "/signed-out" {
416 t.Fatalf("Sign out went to %q", dest)
417 }
418 rec := c.get(dest)
419 b := html.UnescapeString(rec.Body.String())
420 if rec.Code != http.StatusOK || !strings.Contains(b, "You’re signed out") || !strings.Contains(b, "You’ve signed out of Memoria on this device.") {
421 t.Errorf("the signed-out page = %d:\n%s", rec.Code, b)
422 }
423}
424
425// Delete asks first. The index's Delete was a one-click POST with no undo.
426func TestDeleteAsksFirst(t *testing.T) {
427 h := newApp(t)
428 store(t, h, "Keep me", "a document someone might delete by accident")
429 id := storedID(t, h)
430 index := get(t, h, "/documents").Body.String()
431 if strings.Contains(index, `action="/documents/`+id+`/delete"`) {
432 t.Error("the index still deletes in one click")
433 }
434 if !strings.Contains(index, `href="/documents/`+id+`/delete"`) {
435 t.Error("the index has no way to ask for a delete")
436 }
437 confirm := get(t, h, "/documents/"+id+"/delete")
438 b := html.UnescapeString(confirm.Body.String())
439 if confirm.Code != http.StatusOK || !strings.Contains(b, `method="post" action="/documents/`+id+`/delete"`) || !strings.Contains(b, "Keep me") || !strings.Contains(b, ">Cancel<") {
440 t.Fatalf("the confirmation page = %d:\n%s", confirm.Code, b)
441 }
442 if storedCount(t, h) != 1 {
443 t.Fatal("asking deleted the document")
444 }
445 post(t, h, "/documents/"+id+"/delete", url.Values{})
446 if storedCount(t, h) != 0 {
447 t.Error("the confirmed delete did not delete")
448 }
449}
450
451// Live search does not say "0 results…" while the person is still typing.
452// The zero state is one quiet line, marked for search.js to hold back
453// until a pause; a submitted search shows it at once.
454func TestNoZeroResultsWhileTyping(t *testing.T) {
455 h := newApp(t)
456 store(t, h, "Revenue", "revenue grows next year")
457 // A misspelling: the word being typed matches as a prefix now, so a
458 // partial word ("reve") finds "revenue" and is no longer the zero case.
459 frag := get(t, h, "/search?q=revx").Body.String()
460 if strings.Contains(frag, "0 results") || !strings.Contains(frag, "rst-search-empty") || strings.Contains(frag, "rst-callout") {
461 t.Errorf("the live zero state is not one marked quiet line:\n%s", frag)
462 }
463}
464
465// The layout: charset first, then the suite's stylesheet order (§0.5,
466// §12.1 item 2): tokens → theme → brand → base → menu → chrome → app.
467func TestTheLayoutLinksTheSharedChromeInOrder(t *testing.T) {
468 body := get(t, newApp(t), "/").Body.String()
469 head := body[strings.Index(body, "<head>")+len("<head>"):]
470 if !strings.HasPrefix(strings.TrimSpace(head), `<meta charset="utf-8">`) {
471 t.Error("<meta charset> is not the first thing in <head>")
472 }
473 last := -1
474 for _, name := range []string{"tokens", "theme", "brand/brand", "base", "menu", "chrome", "memoria"} {
475 m := regexp.MustCompile(`href="/static/` + name + `\.[^"]*css"`).FindStringIndex(body)
476 if m == nil {
477 t.Errorf("the layout does not link %s.css", name)
478 continue
479 }
480 if m[0] < last {
481 t.Errorf("%s.css is linked out of the suite's order", name)
482 }
483 last = m[0]
484 }
485}
486
487// Nineteen template sites wrote rst-cell-mut as an attribute, which styles
488// nothing (it is a class-only utility): muted text rendered at body colour.
489func TestMutedTextIsStyled(t *testing.T) {
490 dir := filepath.Join("..", "memoria", "templates")
491 entries, _ := os.ReadDir(dir)
492 for _, e := range entries {
493 raw, _ := os.ReadFile(filepath.Join(dir, e.Name()))
494 if n := regexp.MustCompile(`<[^>]*\srst-cell-mut[\s>]`).FindAll(raw, -1); len(n) > 0 {
495 t.Errorf("%s writes rst-cell-mut as an attribute %d times", e.Name(), len(n))
496 }
497 }
498 css, _ := os.ReadFile(filepath.Join("..", "memoria", "static", "memoria.css"))
499 if !regexp.MustCompile(`\[rst-muted\] \{ color: var\(--rst-text-muted\); \}`).Match(css) {
500 t.Error("memoria.css does not style [rst-muted]")
501 }
502 if !strings.Contains(get(t, newApp(t), "/").Body.String(), "<p rst-muted>") {
503 t.Error("the footer is not muted")
504 }
505}
506
507// Fields fit the column: width 100% plus padding overflowed by 22px at
508// 1440 and off screen at 390 (content-box); password fields were the
509// browser's own; the search input drew a second box inside [rst-search].
510func TestFormFieldsFitTheColumn(t *testing.T) {
511 css, err := os.ReadFile(filepath.Join("..", "memoria", "static", "memoria.css"))
512 if err != nil {
513 t.Fatal(err)
514 }
515 rule := regexp.MustCompile(`(?s)\[rst-stack\] input\[type="text"\],[^{]*\{[^}]*\}`).Find(css)
516 if rule == nil {
517 t.Fatal("no [rst-stack] field rule")
518 }
519 for _, want := range []string{`input[type="password"]`, "box-sizing: border-box"} {
520 if !strings.Contains(string(rule), want) {
521 t.Errorf("the field rule lacks %q", want)
522 }
523 }
524 if regexp.MustCompile(`\[rst-search\] input\[type="search"\] \{`).Match(css) {
525 t.Error("memoria.css still draws its own box on the search input, inside rastrillo's")
526 }
527 if !strings.Contains(string(css), "::file-selector-button") {
528 t.Error("the file chooser's button is the browser's own")
529 }
530}
531
532// The Sources lists are rows, not a card of bare bulleted <li>s.
533func TestSourcesAreRows(t *testing.T) {
534 b := get(t, newApp(t), "/connectors").Body.String()
535 if strings.Contains(b, "rst-list-item") || strings.Contains(b, "<ul rst-list>") {
536 t.Error("the Sources page still puts bare list items in a card")
537 }
538 if !strings.Contains(b, "<ul rst-sources>") {
539 t.Error("the Sources page has no rows")
540 }
541}
542
543var _ = strconv.Itoa
544
545// Estilo's chrome is tested against rastrillo v0.23's tokens in estilo;
546// this is the same check against the tokens.css and theme.css THIS app
547// serves (spec §12.1 item 1): a var(--rst-*) nothing defines makes its
548// whole declaration invalid, and the rule vanishes with no error.
549func TestEstilosChromeUsesOnlyDefinedTokens(t *testing.T) {
550 static := filepath.Join("..", "memoria", "static")
551 defined := map[string]bool{}
552 def := regexp.MustCompile(`(?:^|[;{,\s])(--(?:rst|estilo)-[a-zA-Z0-9_-]+)\s*:`)
553 for _, name := range []string{"tokens.css", "theme.css", "base.css", "menu.css", "chrome.css"} {
554 raw, err := os.ReadFile(filepath.Join(static, name))
555 if err != nil {
556 t.Fatal(err)
557 }
558 for _, m := range def.FindAllStringSubmatch(string(raw), -1) {
559 defined[m[1]] = true
560 }
561 }
562 if !defined["--rst-accent"] || !defined["--estilo-bar-block-size"] {
563 t.Fatal("the definition pattern found neither --rst-accent nor --estilo-bar-block-size; this gate is measuring nothing")
564 }
565 use := regexp.MustCompile(`var\(\s*(--(?:rst|estilo)-[a-zA-Z0-9_-]+)\s*([,)])`)
566 seen := 0
567 for _, name := range []string{"base.css", "menu.css", "chrome.css"} {
568 raw, err := os.ReadFile(filepath.Join(static, name))
569 if err != nil {
570 t.Fatal(err)
571 }
572 for _, m := range use.FindAllStringSubmatch(string(raw), -1) {
573 seen++
574 if m[2] == ")" && !defined[m[1]] {
575 t.Errorf("%s reads var(%s), which neither this app's tokens nor estilo define", name, m[1])
576 }
577 }
578 }
579 if seen < 20 {
580 t.Fatalf("only %d token references in estilo's chrome; the walk is broken", seen)
581 }
582}
583
584// polish audit r3 B7 and C5: the Title hint read as bold label text, and
585// /add put a section rule between "← Back to search" and its h1, where the
586// document page uses the breadcrumb nav.
587func TestTheAddPageReadsLikeTheDocumentPage(t *testing.T) {
588 b := get(t, newApp(t), "/add").Body.String()
589 if !strings.Contains(b, `<label for="title">Title <span rst-muted rst-hint>(optional)</span></label>`) {
590 t.Error("the Title hint is not a quiet \"(optional)\"")
591 }
592 if !strings.Contains(b, `<nav rst-breadcrumb><a href="/documents">← Documents</a></nav>`) {
593 t.Error("/add's back link is not the breadcrumb the document page uses")
594 }
595 if regexp.MustCompile(`(?s)<section rst-section>\s*<h1>Add content</h1>`).MatchString(b) {
596 t.Error("a section rule still sits between the back link and the h1")
597 }
598 css, _ := os.ReadFile(filepath.Join("..", "memoria", "static", "memoria.css"))
599 if !regexp.MustCompile(`\[rst-hint\] \{[^}]*font-weight: 400`).Match(css) {
600 t.Error("the hint inherits the label's weight")
601 }
602}
603