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
3import (
4 "amadan.net/oficina/estilo.git/base"
5 "amadan.net/oficina/estilo.git/brand"
6 "amadan.net/oficina/estilo.git/busy"
7 "amadan.net/oficina/estilo.git/chrome"
8 estilomenu "amadan.net/oficina/estilo.git/menu"
9 "amadan.net/oficina/estilo.git/sky"
10 "bytes"
11 "os"
12 "path/filepath"
13 "testing"
14
15 "amadan.net/oficina/estilo.git/theme"
16 "amadan.net/rastrillo/rastrillo/ui"
17)
18
19// The scaffold delivered these files once; they are app-owned from
20// then on. This test pins each vendored copy byte-identical to the
21// library it came from: a reviewer runs the suite instead of reading
22// ~56KB of assets as app diff, and a framework upgrade that forgets
23// to re-copy is caught instead of drifting silently. If you edit one
24// DELIBERATELY, delete its line below — the file is yours.
25//
26// tokens.css is the only one. select.js, datetime.js and calendar.js
27// are rastrillo's too, but no page here links them, so they are not on
28// disk (TestNoUnusedRastrilloScriptsOnDisk); rastrillo.js is estilo's.
29func TestVendoredAssetsMatchTheLibrary(t *testing.T) {
30 for name, lib := range map[string][]byte{
31 "tokens.css": ui.TokensCSS(),
32 } {
33 vendored, err := os.ReadFile(filepath.Join("..", "memoria", "static", name))
34 if err != nil {
35 t.Errorf("read vendored %s: %v", name, err)
36 continue
37 }
38 if !bytes.Equal(vendored, lib) {
39 t.Errorf("static/%s differs from the library copy; re-copy it (or delete its pin if the edit was deliberate)", name)
40 }
41 }
42}
43
44// static/theme.css is Calma with Memoria's accent, from estilo (estilo
45// AGENTS.md, decisions table, row 8). This pins it to the estilo this app
46// is built against. After an estilo upgrade, re-write it with
47// `go run ./scripts/writeestilo` — never by hand.
48func TestThemeIsEstilosForMemoria(t *testing.T) {
49 want, ok := theme.ForApp("memoria")
50 if !ok {
51 t.Fatal("estilo's theme ring has no memoria")
52 }
53 got, err := os.ReadFile(filepath.Join("..", "memoria", "static", "theme.css"))
54 if err != nil {
55 t.Fatal(err)
56 }
57 if !bytes.Equal(got, want) {
58 t.Error("static/theme.css differs from estilo's theme for memoria; run go run ./scripts/writeestilo")
59 }
60}
61
62// app.go mounts Onest at a literal pattern (the route gate reads
63// literals); this keeps that literal equal to estilo's versioned prefix.
64func TestFontRouteIsEstilosPrefix(t *testing.T) {
65 src, err := os.ReadFile(filepath.Join("..", "memoria", "app.go"))
66 if err != nil {
67 t.Fatal(err)
68 }
69 if !bytes.Contains(src, []byte(`"GET `+theme.FontPrefix+`"`)) {
70 t.Errorf("app.go does not mount Onest at %s", theme.FontPrefix)
71 }
72}
73
74// rastrillo's busy rule (Paul, 2026-09-29): a submit button's label gives
75// way to a spinner for at least 650ms, the button disables, and Back
76// resets it. static/ carries it as estilo does — the shim without the old
77// rule, busy.js and busy.css — pinned here to the estilo this app builds
78// against. After an estilo upgrade: go run ./scripts/writeestilo.
79func TestBusyFilesAreEstilos(t *testing.T) {
80 for name, want := range map[string][]byte{
81 "rastrillo.js": busy.ShimJS(),
82 "busy.js": busy.JS(),
83 "busy.css": busy.CSS(),
84 } {
85 got, err := os.ReadFile(filepath.Join("..", "memoria", "static", name))
86 if err != nil {
87 t.Fatal(err)
88 }
89 if !bytes.Equal(got, want) {
90 t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name)
91 }
92 }
93}
94
95// app.go mounts the sign-in door's sky at a literal pattern, for the same
96// reason as the font: the route gate reads literals. This keeps it equal
97// to estilo's versioned prefix, so a new sky version cannot leave the
98// door linking layers nothing serves.
99func TestSkyRouteIsEstilosPrefix(t *testing.T) {
100 src, err := os.ReadFile(filepath.Join("..", "memoria", "app.go"))
101 if err != nil {
102 t.Fatal(err)
103 }
104 if !bytes.Contains(src, []byte(`"GET `+sky.Prefix+`"`)) {
105 t.Errorf("app.go does not mount the sky at %s", sky.Prefix)
106 }
107}
108
109// app.go mounts the switcher's tile icons at a literal pattern, for the
110// same reason as the sky. This keeps it equal to estilo's brand.Prefix,
111// which chrome.SuiteApps builds every tile's icon path from.
112func TestBrandRouteIsEstilosPrefix(t *testing.T) {
113 src, err := os.ReadFile(filepath.Join("..", "memoria", "app.go"))
114 if err != nil {
115 t.Fatal(err)
116 }
117 if !bytes.Contains(src, []byte(`"GET `+brand.Prefix+`"`)) {
118 t.Errorf("app.go does not mount the brand icons at %s", brand.Prefix)
119 }
120}
121
122// The sign-in door (estilo chrome's estilo-signin and friends) is styled
123// by chrome.css and sky.css, vendored into static/ so they are served
124// fingerprinted like every other stylesheet. Pinned to the estilo this
125// app builds against; after an upgrade: go run ./scripts/writeestilo.
126func TestDoorStylesAreEstilos(t *testing.T) {
127 // And the rest of the shared chrome (round 2): links (base.css), the
128 // floating panels (menu.css) and chrome.js's Escape and outside-click
129 // close.
130 for name, want := range map[string][]byte{
131 "chrome.css": chrome.CSS(),
132 "sky.css": sky.CSS(),
133 "base.css": base.CSS(),
134 "menu.css": estilomenu.CSS(),
135 "chrome.js": chrome.JS(),
136 } {
137 got, err := os.ReadFile(filepath.Join("..", "memoria", "static", name))
138 if err != nil {
139 t.Fatal(err)
140 }
141 if !bytes.Equal(got, want) {
142 t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name)
143 }
144 }
145}
146
147// rastrillo doctor --fix re-copies what the library ships and the app
148// lacks, and at 29e4491 that includes the old combined shim (with the
149// old busy rule inside) as rastrillo.js, plus select.js, datetime.js and
150// calendar.js. Memoria links none of the three, and its rastrillo.js is
151// estilo's split shim (TestBusyFilesAreEstilos): the old shim loaded
152// beside busy.js makes the two busy rules fight. After a --fix, run
153// go run ./scripts/writeestilo and delete what it added; this fails
154// until both are done.
155func TestNoUnusedRastrilloScriptsOnDisk(t *testing.T) {
156 for _, name := range []string{"select.js", "datetime.js", "calendar.js"} {
157 if _, err := os.Stat(filepath.Join("..", "memoria", "static", name)); err == nil {
158 t.Errorf("static/%s is on disk; no page links it — delete it (rastrillo doctor --fix adds it)", name)
159 }
160 }
161}
162