oficina / docs Public

Smart door tests: every route and state, remembering Oficina ID, the chained Forget, and the screen contract

The contract estilo's review asked for: estilo-signin-screen over
rastrillo's real states (first visit, Oficina ID remembered, email
remembered, the chooser, a problem, Sent, a step-up, /signin/local and the
confirm step) has the door as the only element child of
[estilo-signin-screen] > section. Each new test was seen to fail against a
mutation of the code it covers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev dd90db579e294de724b4e4559c2ed3677a045d02 parent 157f10d
3 files changed, +477 −5
  • internal/docs/auth.go +7 −2
  • internal/docs/render.go +1 −3
  • internal/docs/signin_smart_door_test.go +469 −0
diff --git a/internal/docs/auth.go b/internal/docs/auth.go
index d48f6da..ad5dae4 100644
--- a/internal/docs/auth.go
+++ b/internal/docs/auth.go
@@ -461,6 +461,9 @@ const signinForgetPath = "/signin/forget"
// stays on the door.
const oficinaChain = "oficina"
+// oficinaIDName is the suite's sign-in service, the federated door's name.
+const oficinaIDName = "Oficina ID"
+
// signinPage is the view data of the sign-in door (views/signin.html):
// rastrillo's sign-in screen (its ui "signin" partial, fed by
// auth.SigninState) drawn inside estilo's door by estilo-signin-screen.
@@ -500,8 +503,10 @@ func (h *handlers) signin(w http.ResponseWriter, r *http.Request) {
st.Federated = &rauth.FederatedDoor{
Provider: lastsignin.ProviderOficina,
Href: href,
- Label: rastrillo.T(r, "docs.signin.oficina_id"),
- Icon: chrome.OficinaGlyph,
+ // A name, like the door's own "Docs": the same in every
+ // language, and rastrillo draws it as "Continue with {name}".
+ Label: oficinaIDName,
+ Icon: chrome.OficinaGlyph,
}
}
if refusedHere(r) {
diff --git a/internal/docs/render.go b/internal/docs/render.go
index abde83f..f4ffcfe 100644
--- a/internal/docs/render.go
+++ b/internal/docs/render.go
@@ -414,9 +414,7 @@ var Catalog = rastrillo.Catalog{
// continuation are rastrillo's sign-in screen copy
// (rastrillo.ui.signin_*), and the signed-out page is estilo's
// chrome.English. What stays is what only Docs knows: the refusal
- // (Config.Refused, the screen's app-problem slot), and the name of the
- // federated door, which rastrillo draws as "Continue with {name}".
- "docs.signin.oficina_id": "Oficina ID",
+ // (Config.Refused, the screen's app-problem slot).
"docs.signin.error.refused": "That address can’t sign in to Docs. Use a different address, or ask whoever runs this team to add it.",
// docs.signout.label is the sign-out control's text — both its
diff --git a/internal/docs/signin_smart_door_test.go b/internal/docs/signin_smart_door_test.go
new file mode 100644
index 0000000..2d63788
--- /dev/null
+++ b/internal/docs/signin_smart_door_test.go
@@ -0,0 +1,469 @@
+package docs
+
+// The smart door (Home spec 2026-11-19-smart-door.md, step 6; home/connect
+// MIGRATING.md): every route and state the door answers, remembering
+// Oficina ID in MintHomeSession, and the signed-out page's Forget, chained
+// to Oficina ID's own.
+
+import (
+ "fmt"
+ "html"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "regexp"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/estilo.git/chrome"
+ "amadan.net/rastrillo/rastrillo/lastsignin"
+)
+
+// remember gives the browser a remembered way in, sealed by Docs' own jar,
+// as rastrillo would have after a sign-in.
+func (b *routerBrowser) remember(t *testing.T, rec lastsignin.Record) {
+ t.Helper()
+ w := httptest.NewRecorder()
+ b.f.app.handlers.auth.RememberJar().Remember(w, rec)
+ cookies := w.Result().Cookies()
+ if len(cookies) != 1 {
+ t.Fatalf("the jar refused %+v", rec)
+ }
+ b.cookies[cookies[0].Name] = cookies[0]
+}
+
+// remembered is the browser's remembered way in, read by Docs' own jar.
+func (b *routerBrowser) remembered(t *testing.T) (lastsignin.Record, lastsignin.ReadResult) {
+ t.Helper()
+ return b.f.app.handlers.auth.RememberJar().Read(b.request("GET", "/", ""))
+}
+
+// door is the sign-in card's own content: rastrillo's section inside
+// estilo-signin-screen, unescaped.
+func door(t *testing.T, body string) string {
+ t.Helper()
+ start := strings.Index(body, "<div estilo-signin-screen>")
+ if start < 0 {
+ t.Fatalf("no estilo-signin-screen:\n%s", body)
+ }
+ end := strings.Index(body[start:], "</section>")
+ return html.UnescapeString(body[start : start+end])
+}
+
+var (
+ oficinaButton = "Continue with Oficina ID"
+ otherWays = "Other ways to sign in"
+ emailField = `name="address" required`
+)
+
+func TestSmartDoorStatesWithHome(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ glyph := string(chrome.OficinaGlyph)
+ cases := []struct {
+ name, path string
+ record *lastsignin.Record
+ want, not []string
+ title string
+ }{
+ {name: "first visit", path: "/signin",
+ want: []string{oficinaButton, `href="/signin/oficina"`, glyph, otherWays, `href="/signin?way=oficina&ways=1"`},
+ not: []string{emailField, "Continue as", "Use a different email"},
+ title: "Sign in to Docs"},
+ {name: "first visit from a page", path: "/signin?return_to=%2Fd%2Fabc",
+ want: []string{`href="/signin/oficina?return_to=%2Fd%2Fabc"`, `href="/signin?return_to=%2Fd%2Fabc&way=oficina&ways=1"`}},
+ {name: "local: email is the one way", path: "/signin/local",
+ want: []string{emailField, ">Continue</button>"},
+ not: []string{"Oficina ID", "/signin/oficina", otherWays}},
+ {name: "step-up: local ways only", path: "/signin?reauth=1",
+ want: []string{emailField, "Sign in again to continue."},
+ not: []string{"Oficina ID", "/signin/oficina"}},
+ {name: "step-up remembered Oficina ID", path: "/signin?reauth=1",
+ record: &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"},
+ want: []string{"Continue as <bdi>alice@example.com</bdi>", "Sign in again to continue."},
+ not: []string{"Oficina ID", "/signin/oficina"}},
+ {name: "chooser", path: "/signin?ways=1",
+ want: []string{"<h1 id=\"rst-signin-heading\">Other ways to sign in</h1>", `href="/signin?way=email"`, ">Email</span>", ">Back</span>"},
+ not: []string{oficinaButton, emailField},
+ title: "Other ways to sign in to Docs"},
+ {name: "email chosen", path: "/signin?way=email",
+ want: []string{emailField, otherWays},
+ not: []string{oficinaButton}},
+ {name: "Oficina ID remembered", path: "/signin",
+ record: &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"},
+ want: []string{oficinaButton, otherWays},
+ // Never captioned with an address.
+ not: []string{"alice@example.com", emailField}},
+ {name: "Oficina ID remembered: the chooser", path: "/signin?ways=1&way=oficina",
+ record: &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"},
+ want: []string{">Email <bdi>alice@example.com</bdi></span>", "Use a different email", ">Back</span>"},
+ not: []string{oficinaButton}},
+ {name: "Oficina ID remembered for a Home-only person", path: "/signin?ways=1&way=oficina",
+ record: &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina},
+ want: []string{">Email</span>"},
+ not: []string{"<bdi>"}},
+ {name: "email link remembered", path: "/signin",
+ record: &lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"},
+ want: []string{"Continue as <bdi>bob@example.com</bdi>", `name="address" value="bob@example.com"`, otherWays},
+ not: []string{oficinaButton}},
+ {name: "email link remembered: the chooser", path: "/signin?ways=1&way=email",
+ record: &lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"},
+ want: []string{glyph + "<span>Oficina ID</span>", `href="/signin?way=oficina"`, "Use a different email"},
+ not: []string{">Email</span>"}},
+ {name: "Keymail remembered", path: "/signin",
+ record: &lastsignin.Record{Method: lastsignin.MethodKeymail, Address: "bob@example.com"},
+ want: []string{"Continue to Keymail", `name="expect" value="keymail"`, "as <bdi>bob@example.com</bdi>", otherWays}},
+ {name: "problem", path: "/signin?err=rate",
+ record: &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina},
+ want: []string{"Too many tries. Try again in a few minutes.", emailField},
+ not: []string{oficinaButton},
+ title: "Problem signing in to Docs"},
+ {name: "a failed Keymail keeps force", path: "/signin?err=keymail&force=1",
+ want: []string{"Keymail couldn't confirm it's you.", `name="force" value="1"`, "Send me a link instead"}},
+ {name: "sent", path: "/signin?sent=1",
+ want: []string{"Check your email", "We sent a link to your inbox.", "Use a different email"},
+ not: []string{oficinaButton, emailField},
+ title: "Check your email to sign in to Docs"},
+ {name: "an unknown way is the remembered one", path: "/signin?way=nonsense",
+ want: []string{oficinaButton}},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ b := f.browser()
+ if c.record != nil {
+ b.remember(t, *c.record)
+ }
+ rec := b.do("GET", c.path, "")
+ if rec.Code != http.StatusOK {
+ t.Fatalf("GET %s: %d %q", c.path, rec.Code, rec.Header().Get("Location"))
+ }
+ if rec.Header().Get("Cache-Control") != "no-store" {
+ t.Error("the door is cacheable")
+ }
+ card := door(t, rec.Body.String())
+ for _, want := range c.want {
+ if !strings.Contains(card, want) {
+ t.Errorf("lacks %q:\n%s", want, card)
+ }
+ }
+ for _, not := range c.not {
+ if strings.Contains(card, not) {
+ t.Errorf("has %q:\n%s", not, card)
+ }
+ }
+ if c.title != "" {
+ if got := html.UnescapeString(titleOfPage(rec.Body.String())); got != c.title {
+ t.Errorf("<title> = %q, want %q", got, c.title)
+ }
+ }
+ })
+ }
+}
+
+func titleOfPage(body string) string {
+ m := regexp.MustCompile(`<title>([^<]*)</title>`).FindStringSubmatch(body)
+ if m == nil {
+ return ""
+ }
+ return m[1]
+}
+
+// Standalone Docs has only email: no Oficina ID anywhere, and no chooser
+// with nothing on it.
+func TestSmartDoorStandaloneHasOnlyEmail(t *testing.T) {
+ app, err := NewForTest(t)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, path := range []string{"/signin", "/signin?way=oficina"} {
+ rec := serve(app, httptest.NewRequest(http.MethodGet, path, nil))
+ card := door(t, rec.Body.String())
+ if rec.Code != http.StatusOK || !strings.Contains(card, emailField) || strings.Contains(card, "Oficina") || strings.Contains(card, otherWays) {
+ t.Errorf("GET %s: %d\n%s", path, rec.Code, card)
+ }
+ }
+ // Nothing links the chooser here; typed in, it has no Oficina ID row.
+ if card := door(t, serve(app, httptest.NewRequest(http.MethodGet, "/signin?ways=1", nil)).Body.String()); strings.Contains(card, "Oficina") || !strings.Contains(card, ">Back</span>") {
+ t.Errorf("standalone chooser:\n%s", card)
+ }
+ if rec := serve(app, httptest.NewRequest(http.MethodGet, "/signin/oficina", nil)); rec.Code != http.StatusNotFound {
+ t.Errorf("standalone /signin/oficina: %d, want 404", rec.Code)
+ }
+}
+
+// Continue with Oficina ID starts the Home exchange, keeping the page; a
+// step-up never reaches Home; a browser already signed in and admitted
+// skips both doors, unless the query names a state of the door.
+func TestSmartDoorRoutesWithHome(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ b := f.browser()
+ routerRedirect(t, b.do("GET", "/signin/oficina?return_to=%2Fd%2Fabc", ""), "/auth/start?return_to=%2Fd%2Fabc")
+ if b.cookies[connectReturnCookie] == nil {
+ t.Fatal("/signin/oficina did not remember the page for the Home landing")
+ }
+ routerRedirect(t, b.do("GET", "/signin/oficina?reauth=1&return_to=%2Fd%2Fabc", ""), "/signin/local?reauth=1&return_to=%2Fd%2Fabc")
+
+ alice := f.browser()
+ alice.localSignin(t, "alice@example.com")
+ routerRedirect(t, alice.do("GET", "/signin?return_to=%2Fd%2Fabc", ""), "/d/abc")
+ routerRedirect(t, alice.do("GET", "/signin/oficina", ""), "/")
+ for _, path := range []string{"/signin?reauth=1", "/signin?sent=1", "/signin?err=rate", "/signin/local"} {
+ if rec := alice.do("GET", path, ""); rec.Code != http.StatusOK {
+ t.Errorf("signed in, GET %s: %d %q, want the door", path, rec.Code, rec.Header().Get("Location"))
+ }
+ }
+}
+
+// The refusal (Config.Refused) is drawn in the screen's app-problem slot,
+// with the email field, never the remembered one-tap that would only offer
+// the refused address again.
+func TestSmartDoorRefusalIsTheAppProblem(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ b := f.browser()
+ b.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "carol@example.com"})
+ rec := httptest.NewRecorder()
+ req := b.request("POST", "/auth/verify", "")
+ f.app.handlers.signinRefused(rec, req)
+ card := door(t, rec.Body.String())
+ if rec.Code != http.StatusForbidden || !strings.Contains(card, `id="rst-signin-app-problem"`) || !strings.Contains(card, "docs.signin.error.refused") || !strings.Contains(card, `id="rst-signin-email" name="address"`) || strings.Contains(card, "Continue as") {
+ t.Fatalf("refusal: %d\n%s", rec.Code, card)
+ }
+}
+
+// A Home sign-in is remembered as Oficina ID, with the address of the
+// person connect resolved, written in MintHomeSession and only there.
+func TestMintHomeSessionRemembersOficinaID(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ alice := f.browser()
+ alice.localSignin(t, "alice@example.com")
+ alice.linkProof(t, "opaque-alice", "alice@example.com")
+ alice.confirmLink(t, "/")
+
+ // This browser last signed in as bob, by email. Oficina ID signs alice
+ // in: the record is hers, and nothing of bob's is carried over.
+ b := f.browser()
+ b.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"})
+ nonce := b.start(t, "/auth/start?return_to=%2F", "")
+ routerRedirect(t, b.exchange(t, nonce, "opaque-alice", time.Now().Add(-time.Hour)), "/")
+ got, res := b.remembered(t)
+ want := lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"}
+ if res != lastsignin.Valid || got != want {
+ t.Fatalf("remembered %+v (%v), want %+v", got, res, want)
+ }
+ // And the door offers it next time, with her address only in the chooser.
+ signoutChained(t, b.do("POST", "/signout", ""))
+ card := door(t, b.do("GET", "/signin", "").Body.String())
+ if !strings.Contains(card, oficinaButton) || strings.Contains(card, "alice@example.com") {
+ t.Fatalf("the door after an Oficina ID sign-in:\n%s", card)
+ }
+
+ // A local sign-in is remembered by rastrillo itself, as the email link.
+ alice.localSignin(t, "alice@example.com")
+ if got, res := alice.remembered(t); res != lastsignin.Valid || got.Method != lastsignin.MethodMagicLink || got.Address != "alice@example.com" {
+ t.Fatalf("local sign-in remembered %+v (%v)", got, res)
+ }
+
+ // An unknown subject mints nothing, so remembers nothing.
+ stranger := f.browser()
+ stranger.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"})
+ if rec := stranger.exchange(t, stranger.start(t, "/auth/start?return_to=%2F", ""), "opaque-nobody", time.Now().Add(-time.Hour)); rec.Code != http.StatusForbidden {
+ t.Fatalf("unknown subject: %d", rec.Code)
+ }
+ if got, res := stranger.remembered(t); res != lastsignin.Valid || got.Method != lastsignin.MethodMagicLink || got.Address != "bob@example.com" {
+ t.Fatalf("an unknown Home subject changed the record: %+v (%v)", got, res)
+ }
+}
+
+// A Home-only person (team mode, "I'm new here") has no address here: the
+// record is Oficina ID with none.
+func TestMintHomeSessionRemembersAHomeOnlyPersonWithoutAnAddress(t *testing.T) {
+ f := newTeamRouterFixture(t)
+ b := f.browser()
+ b.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"})
+ nonce := b.start(t, "/auth/start?return_to=%2F", "")
+ b.chooseNew(t, b.exchange(t, nonce, teamSubject('b'), time.Now().Add(-time.Hour)))
+ got, res := b.remembered(t)
+ if want := (lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina}); res != lastsignin.Valid || got != want {
+ t.Fatalf("remembered %+v (%v), want %+v", got, res, want)
+ }
+}
+
+// Signed out: "Forget me on this device", a POST to rastrillo's Forget.
+// With Home it then chains to Oficina ID's own Forget, which returns only
+// to this consumer's exact /signed-out. The door's "Use a different email"
+// posts to the same Forget and stays on the door.
+func TestSignedOutForgetChainsToOficinaID(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ b := f.browser()
+ page := b.do("GET", "/signed-out", "")
+ form := regexp.MustCompile(`(?s)<form estilo-signin-forget method="post" action="([^"]+)">(.*?)</form>`).FindStringSubmatch(page.Body.String())
+ if page.Code != http.StatusOK || form == nil || form[1] != signinForgetPath || !strings.Contains(form[2], `name="chain" value="oficina"`) || !strings.Contains(form[2], "Forget me on this device") {
+ t.Fatalf("signed-out page has no chained Forget: %d\n%s", page.Code, page.Body.String())
+ }
+ if !strings.Contains(page.Body.String(), `href="/signin">Sign in</a>`) {
+ t.Fatal("signed-out page lost Sign in")
+ }
+
+ b.remember(t, lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"})
+ jar := f.app.handlers.auth.RememberJar().CookieName()
+ rec := b.do("POST", signinForgetPath, url.Values{"chain": {"oficina"}}.Encode())
+ want := bridgeIssuer + "/forget?return=" + url.QueryEscape(bridgeOrigin+"/signed-out")
+ routerRedirect(t, rec, want)
+ if _, ok := b.cookies[jar]; ok {
+ t.Fatal("Forget kept the remembered way in")
+ }
+ if !strings.Contains(rec.Header().Get("Content-Security-Policy"), "form-action 'self' "+bridgeIssuer) {
+ t.Fatalf("form-action does not allow the chain to %s: %q", bridgeIssuer, rec.Header().Get("Content-Security-Policy"))
+ }
+
+ // The door's "Use a different email": forgets, and opens the email way.
+ b.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"})
+ routerRedirect(t, b.do("POST", signinForgetPath, url.Values{"way": {"email"}, "return_to": {"/d/abc"}}.Encode()), "/signin?return_to=%2Fd%2Fabc&way=email")
+ if _, ok := b.cookies[jar]; ok {
+ t.Fatal("Use a different email kept the remembered way in")
+ }
+
+ // A cross-site post is refused, and chains nowhere.
+ r := b.request("POST", signinForgetPath, url.Values{"chain": {"oficina"}}.Encode())
+ r.Header.Set("Origin", "https://evil.example")
+ r.Header.Set("Sec-Fetch-Site", "cross-site")
+ if refused := b.serve(r); refused.Code != http.StatusForbidden || refused.Header().Get("Location") != "" {
+ t.Fatalf("cross-site Forget: %d %q", refused.Code, refused.Header().Get("Location"))
+ }
+}
+
+// Standalone, the signed-out page's Forget is Docs' own, with no chain.
+func TestSignedOutForgetStandalone(t *testing.T) {
+ app, err := NewForTest(t)
+ if err != nil {
+ t.Fatal(err)
+ }
+ page := serve(app, httptest.NewRequest(http.MethodGet, "/signed-out", nil)).Body.String()
+ if !strings.Contains(page, `<form estilo-signin-forget method="post" action="/signin/forget">`) || strings.Contains(page, `name="chain"`) {
+ t.Fatalf("standalone signed-out page:\n%s", page)
+ }
+ req := httptest.NewRequest(http.MethodPost, DefaultOrigin+signinForgetPath, strings.NewReader("chain=oficina"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Sec-Fetch-Site", "same-origin")
+ rec := serve(app, req)
+ if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/signin" {
+ t.Fatalf("standalone Forget: %d %q, want 303 /signin", rec.Code, rec.Header().Get("Location"))
+ }
+}
+
+// The contract estilo's review asked for: estilo-signin-screen over
+// rastrillo's real sign-in states. HideBrand drops the partial's brand
+// column (estilo's door draws Docs' mark and name around the card), so
+// [estilo-signin-screen] > section has the door as its only element child,
+// in every state.
+func TestSmartDoorScreenHoldsOnlyTheDoor(t *testing.T) {
+ f := newRouterHomeFixture(t)
+ oficina := &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.com"}
+ email := &lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.com"}
+ for _, c := range []struct {
+ name, path string
+ record *lastsignin.Record
+ }{
+ {"first visit", "/signin", nil},
+ {"Oficina ID remembered", "/signin", oficina},
+ {"email remembered", "/signin", email},
+ {"the chooser", "/signin?ways=1", email},
+ {"problem", "/signin?err=expired", email},
+ {"sent", "/signin?sent=1", email},
+ {"step-up", "/signin?reauth=1", oficina},
+ {"email only", "/signin/local", nil},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ b := f.browser()
+ if c.record != nil {
+ b.remember(t, *c.record)
+ }
+ rec := b.do("GET", c.path, "")
+ if rec.Code != http.StatusOK {
+ t.Fatalf("GET %s: %d", c.path, rec.Code)
+ }
+ screenOnlyHoldsTheDoor(t, rec.Body.String())
+ })
+ }
+ // And the confirm step an emailed link opens (Config.RenderConfirm).
+ b := f.browser()
+ confirm := b.do("GET", b.localLink(t, "alice@example.com"), "")
+ if confirm.Code != http.StatusOK {
+ t.Fatalf("confirm: %d", confirm.Code)
+ }
+ screenOnlyHoldsTheDoor(t, confirm.Body.String())
+}
+
+var startTag = regexp.MustCompile(`<(/?)([a-zA-Z][a-zA-Z0-9-]*)([^>]*)>`)
+
+// voidElements have no end tag.
+var voidElements = map[string]bool{"area": true, "base": true, "br": true, "col": true, "embed": true, "hr": true, "img": true, "input": true, "link": true, "meta": true, "source": true, "track": true, "wbr": true}
+
+// screenOnlyHoldsTheDoor checks that the first section inside
+// [estilo-signin-screen] is rastrillo's [rst-signin] and that its only
+// element child is the door, [rst-signin-door].
+func screenOnlyHoldsTheDoor(t *testing.T, body string) {
+ t.Helper()
+ children, err := screenChildren(body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(children) != 1 || !strings.HasPrefix(children[0], "<div rst-signin-door") {
+ t.Fatalf("[estilo-signin-screen] > section has %d element children %q, want only the door", len(children), children)
+ }
+}
+
+// screenChildren is the start tags of the element children of
+// [estilo-signin-screen] > section, which must be rastrillo's.
+func screenChildren(body string) ([]string, error) {
+ at := strings.Index(body, "<div estilo-signin-screen>")
+ if at < 0 {
+ return nil, fmt.Errorf("no [estilo-signin-screen]")
+ }
+ rest := body[at+len("<div estilo-signin-screen>"):]
+ tags := startTag.FindAllStringSubmatchIndex(rest, -1)
+ if len(tags) == 0 {
+ return nil, fmt.Errorf("[estilo-signin-screen] is empty")
+ }
+ first := rest[tags[0][0]:tags[0][1]]
+ if strings.TrimSpace(rest[:tags[0][0]]) != "" || !strings.HasPrefix(first, "<section rst-signin") {
+ return nil, fmt.Errorf("[estilo-signin-screen]'s first child is not rastrillo's section: %q", first)
+ }
+ depth := 0
+ var children []string
+ for _, m := range tags[1:] {
+ closing, name, tag := rest[m[2]:m[3]] == "/", strings.ToLower(rest[m[4]:m[5]]), rest[m[0]:m[1]]
+ if closing {
+ if depth == 0 {
+ if name != "section" {
+ return nil, fmt.Errorf("unbalanced markup: %q closes the section", tag)
+ }
+ return children, nil
+ }
+ depth--
+ continue
+ }
+ if depth == 0 {
+ children = append(children, tag)
+ }
+ if !voidElements[name] && !strings.HasSuffix(tag, "/>") {
+ depth++
+ }
+ }
+ return nil, fmt.Errorf("the section never closes")
+}
+
+// The check sees what HideBrand removes: a brand column beside the door,
+// as the partial draws without it, is a second child.
+func TestScreenChildrenSeesABrandColumn(t *testing.T) {
+ branded := `<div estilo-signin-screen>
+<section rst-signin aria-labelledby="rst-signin-heading">
+<div rst-signin-brand><div rst-signin-mark><img src="x" alt=""></div><p rst-signin-name>Docs</p></div>
+<div rst-signin-door="one-way"><h1>Sign in to Docs</h1><input name="address"><br></div>
+</section>
+</div>`
+ children, err := screenChildren(branded)
+ if err != nil || len(children) != 2 || !strings.HasPrefix(children[0], "<div rst-signin-brand") {
+ t.Fatalf("children %q, %v: want the brand column and the door", children, err)
+ }
+}