oficina / home Public

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

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "os"
5 "path/filepath"
6 "regexp"
7 "slices"
8 "strings"
9 "testing"
10)
11
12// Every card at the door draws its buttons as the door does (Paul,
13// 2026-11-21, "yes to pill buttons"): the main action a full-width pill,
14// a secondary control a quiet text button. estilo's chrome.css draws them
15// from its own hooks, never from rst-btn (estilo AGENTS.md, Vocabulary),
16// so every button on a door or hop page must carry estilo-signin-action,
17// with the variant that matches its rst-btn: "danger" for a danger
18// button, "quiet" for a ghost one. A button inside a door sign-in form
19// (estilo-signin-form) or Forget (estilo-signin-forget) is reached by
20// that form's hook instead; one anywhere else on the page is not. A card whose one way forward is a link draws it as
21// a primary button in its template; the CSS never guesses.
22func TestDoorButtonsCarryTheDoorsHooks(t *testing.T) {
23 btn := regexp.MustCompile(`<(a|button)\b[^>]*\brst-btn\b[^>]*>`)
24 variant := regexp.MustCompile(`\brst-btn(?:="([^"]*)")?`)
25 action := regexp.MustCompile(`\bestilo-signin-action(?:="([^"]*)")?`)
26 hookedForm := regexp.MustCompile(`(?s)<form\b[^>]*\b(?:estilo-signin-form|estilo-signin-forget)\b[^>]*>.*?</form>`)
27 pages := map[string]bool{}
28 for name := range doorPages {
29 pages[name] = true
30 }
31 for name := range hopPages {
32 pages[name] = true
33 }
34 n := 0
35 for name := range pages {
36 src, err := os.ReadFile(filepath.Join("templates", name))
37 if err != nil {
38 t.Fatal(err)
39 }
40 page := string(src)
41 var inHookedForm [][]int
42 for _, f := range hookedForm.FindAllStringIndex(page, -1) {
43 inHookedForm = append(inHookedForm, f)
44 }
45 for _, at := range btn.FindAllStringIndex(page, -1) {
46 n++
47 tag := page[at[0]:at[1]]
48 v := strings.Fields(variant.FindStringSubmatch(tag)[1])
49 m := action.FindStringSubmatch(tag)
50 if m == nil {
51 hooked := false
52 for _, f := range inHookedForm {
53 hooked = hooked || (f[0] < at[0] && at[1] <= f[1])
54 }
55 if !hooked {
56 t.Errorf("%s: %s has no estilo-signin-action, so the door draws it as rastrillo's plain button", name, tag)
57 }
58 continue
59 }
60 want := ""
61 switch {
62 case slices.Contains(v, "danger"):
63 want = "danger"
64 case slices.Contains(v, "ghost"):
65 want = "quiet"
66 }
67 if m[1] != want {
68 t.Errorf("%s: %s is estilo-signin-action=%q, want %q", name, tag, m[1], want)
69 }
70 }
71 }
72 if n == 0 {
73 t.Fatal("found no buttons on the door's pages")
74 }
75 // One main action per card: Use your passkey is the main action, so the
76 // recovery code's Sign in is the quiet one.
77 if src, err := os.ReadFile(filepath.Join("templates", "passkey_confirm.html")); err != nil {
78 t.Fatal(err)
79 } else if !strings.Contains(string(src), `<button type="submit" rst-btn="ghost" estilo-signin-action="quiet">Sign in</button>`) {
80 t.Error("passkey_confirm.html: the recovery code's Sign in is not the card's quiet action")
81 }
82 // The lone links Paul's ruling names are the card's main action.
83 for name, want := range map[string]string{
84 "handoff_failed.html": `<a rst-btn="primary" estilo-signin-action href="{{.Data.HomeURL}}">Back to Oficina</a>`,
85 "signin_failed.html": `<a rst-btn="primary" estilo-signin-action href="{{.Data.Again}}">Start again</a>`,
86 } {
87 src, err := os.ReadFile(filepath.Join("templates", name))
88 if err != nil {
89 t.Fatal(err)
90 }
91 if !strings.Contains(string(src), want) {
92 t.Errorf("%s lacks %s", name, want)
93 }
94 }
95}
96