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 "html"
5 "net/http"
6 "net/url"
7 "regexp"
8 "strings"
9 "testing"
10
11 "amadan.net/oficina/estilo.git/sky"
12)
13
14// The sign-in page is the suite's door (estilo chrome, 2026-09-29): one
15// card on the team's sky with Memoria's mark and name at its head. Paul's
16// ruling is that every app's sign-in is "a version of the Oficina sign-in
17// screen", so this pins that the page IS the door rather than memoria's
18// old bare form — and that everything the door links is actually served:
19// a card whose stylesheet 404s, or a sky whose layers nothing mounts,
20// renders as a plain form with no error anywhere.
21//
22// And the door's form must still sign someone in. Its field is named by
23// estilo, not by this app, so the POST below uses the name the RENDERED
24// page carries, not one typed here: if the door ever renamed the field,
25// an owner's address would stop reaching the handler and this fails.
26//
27// MUTATION-TESTED 2026-09-29 by its author (so they prove consistency, not
28// coverage — AGENTS.md), each reverted: the sky mount removed from app.go
29// -> both served layers 404 here (and TestSkyRouteIsEstilosPrefix red);
30// the chrome.css link removed from signin.html -> "does not link chrome.css".
31func TestSigninPageIsTheDoor(t *testing.T) {
32 h, rec := signinApp(t)
33 rr := get(t, h, "/signin")
34 if rr.Code != http.StatusOK {
35 t.Fatalf("GET /signin = %d", rr.Code)
36 }
37 body := rr.Body.String()
38
39 for _, want := range []string{
40 "estilo-door",
41 `<span>Memoria</span>`,
42 // The smart door (Home spec 2026-11-19-smart-door.md, step 6):
43 // rastrillo's screen in estilo's door, in rastrillo's approved
44 // words. Standalone, with nothing remembered, the one way in is
45 // the email field.
46 `estilo-signin-screen`,
47 `<h1 id="rst-signin-heading">Sign in to Memoria</h1>`,
48 `action="/auth/begin"`,
49 `>Continue</button>`,
50 // The door's tab title is rastrillo's for its state.
51 `<title>Sign in to Memoria</title>`,
52 } {
53 if !strings.Contains(html.UnescapeString(body), html.UnescapeString(want)) {
54 t.Errorf("the sign-in page lacks %q", want)
55 }
56 }
57 // Paul, 2026-11-19: no Colophon link on the sign-in door ("makes no
58 // sense at all"). The page stays reachable signed out; the door does
59 // not link it.
60 if strings.Contains(body, `href="/help/open-source"`) {
61 t.Error("the sign-in page links Open source")
62 }
63 // Retired (§9.2): "Email me a link" (Paul, 2026-10-01), the lede
64 // "Memoria holds your team's work…", and the
65 // footer's egress claim, which is about searching and is said only to
66 // somebody signed in.
67 // And the old title, "Sign in — Memoria".
68 // And the old door's: its help line, its "Sign in" submit and title
69 // (the smart door, 2026-11-22), and no Oficina ID standalone.
70 for _, gone := range []string{"Email me a link", "holds your team", "<footer", "leaves this instance", "Sign in — Memoria",
71 "We’ll email you a link", "Sign in · Memoria", "Oficina ID"} {
72 if strings.Contains(body, gone) {
73 t.Errorf("the sign-in page still carries %q", gone)
74 }
75 }
76
77 // Every sky layer the door links: the two inline placeholders (which
78 // is why CSP must allow img-src data:) and the served ones.
79 layers := regexp.MustCompile(`<img estilo-sky-layer="([a-z]+)"[^>]* src="([^"]+)"`).FindAllStringSubmatch(body, -1)
80 if len(layers) < 3 {
81 t.Fatalf("found %d sky layers on the sign-in page, want the placeholders and the served layers", len(layers))
82 }
83 served := 0
84 for _, m := range layers {
85 src := html.UnescapeString(m[2])
86 if strings.HasPrefix(src, "data:") {
87 continue
88 }
89 served++
90 if !strings.HasPrefix(src, sky.Prefix) {
91 t.Errorf("sky layer %s is %q, not under %s", m[1], src, sky.Prefix)
92 }
93 if got := get(t, h, src); got.Code != http.StatusOK || got.Header().Get("Content-Type") != "image/svg+xml" {
94 t.Errorf("GET %s = %d %q; the sky layer is linked but not served", src, got.Code, got.Header().Get("Content-Type"))
95 }
96 }
97 if served == 0 {
98 t.Error("no sky layer is served from the app; the served half of the sky was never checked")
99 }
100
101 // The door's stylesheets are linked and served.
102 for _, name := range []string{"chrome", "sky"} {
103 m := regexp.MustCompile(`href="(/static/` + name + `[^"]*\.css)"`).FindStringSubmatch(body)
104 if m == nil {
105 t.Errorf("the sign-in page does not link %s.css", name)
106 continue
107 }
108 if got := get(t, h, m[1]); got.Code != http.StatusOK || !strings.Contains(got.Body.String(), "estilo-") {
109 t.Errorf("GET %s = %d; the door's stylesheet is linked but not served", m[1], got.Code)
110 }
111 }
112
113 // The field name the door renders, read off the page.
114 field := regexp.MustCompile(`<input rst-input type="email" id="rst-signin-email" name="([^"]+)"`).FindStringSubmatch(body)
115 if field == nil {
116 t.Fatalf("no email field on the door:\n%s", body)
117 }
118 if field[1] != "address" {
119 t.Errorf("the door's field is named %q; beginGuard and rastrillo read address", field[1])
120 }
121 rr = post(t, h, "/auth/begin", url.Values{field[1]: {dialTestOwner}})
122 if rr.Code != http.StatusSeeOther || !sentLocation(rr.Header().Get("Location")) {
123 t.Errorf("an owner's POST from the door = %d %q, want 303 to Sent", rr.Code, rr.Header().Get("Location"))
124 }
125 // A stranger's POST answers the same, so the redirect alone cannot
126 // tell a read address from an ignored one. The classifier dialling is
127 // what proves the owner's address reached sign-in.
128 if !rec.dialed() {
129 t.Error("the owner's address never reached the sign-in classifier; the door's field is not what the handler reads")
130 }
131}
132