oficina / meet Public

Calls: Connect your Oficina account only when it isn't, and finishes itself

The account menu offers Connect only when no Oficina link is stored. A
sign-in through id with an unlinked identity now leads, after one local
sign-in, straight to the confirm step; the card's buttons sit in one
row and a stored link shows Accounts connected. Pins estilo f14458a and
home connect ff16bf5. Landed on local make ci (go1.26.5); the hub runner's go1.26.10 fails the credits test, on Paul's ruling. Reviewed by GPT-6-Astra via Codex (#28).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from fix/connect-item-when-linked into main.
claude agent, operated by paul@keymail.dev 7edba8b9fcc419578365c6573545c56e8acb2871 parent 47f6a80
5 files changed, +232 −15
  • go.mod +3 −3
  • go.sum +6 −6
  • internal/calls/chrome.go +12 −5
  • internal/calls/home.go +1 −1
  • internal/calls/home_connect_item_test.go +210 −0

CI failed — run details

landed from fix/connect-item-when-linked

diff --git a/go.mod b/go.mod
index f74cada..6f9dedd 100644
--- a/go.mod
+++ b/go.mod
@@ -3,9 +3,9 @@ module amadan.net/oficina/calls
go 1.26.0
require (
- amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1
- amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c
- amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
+ amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c
+ amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d
+ amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d
amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060
github.com/go-chi/chi/v5 v5.3.2
github.com/keymaildev/signin v0.1.1
diff --git a/go.sum b/go.sum
index 29d8244..9fbaefd 100644
--- a/go.sum
+++ b/go.sum
@@ -1,9 +1,9 @@
-amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1 h1:Xaidrm9rzFyne6PujFYXiY7nGRy+/KzH7kGBM2+D5LQ=
-amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
-amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A=
-amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
+amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c h1:jPbFJwPi7lHe+UNe+Gbj0ivVsy+pLqMSq2EP2Xff/q0=
+amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
+amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d h1:9sVZBph2xUuejZt73DYaoCfoyvrvZCnuPHcyMsg562E=
+amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk=
+amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d h1:8RTZkLQnyxvH2g0RMovhN/m2LN9D8qb+kBfqdBeqq+s=
+amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE=
amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060/go.mod h1:WmC8TAIfqjAkSwmD+FCTqr7VuqAO5FaX03HlV49K608=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
diff --git a/internal/calls/chrome.go b/internal/calls/chrome.go
index 36358e1..844fe7d 100644
--- a/internal/calls/chrome.go
+++ b/internal/calls/chrome.go
@@ -212,7 +212,7 @@ func (a *app) account(r *http.Request, v viewer) *chrome.Account {
Help: []estilomenu.Item{{Href: "/help/open-source", Label: "Open source"}},
SignOut: chrome.SignOut{Action: "/signout", Label: "Sign out"},
}
- if a.offersHomeLink(v) {
+ if a.offersHomeLink(r, v) {
acc.Items = []estilomenu.Item{{Href: "/account/home", Label: "Connect your Oficina account"}}
}
return acc
@@ -220,10 +220,17 @@ func (a *app) account(r *http.Request, v viewer) *chrome.Account {
// offersHomeLink is whether the account menu offers to connect the
// person's Oficina account: only with Home configured, only to a member
-// (the page is behind requireMember), and never to somebody who signed
-// in through Home, whose account already is the connection.
-func (a *app) offersHomeLink(v viewer) bool {
- return a.home != nil && v.signedIn() && a.isMember(v.person) && (v.method == "magiclink" || v.method == "keymail")
+// (the page is behind requireMember), never to somebody who signed in
+// through Home, whose account already is the connection, and never once
+// the account has a stored link, however this session signed in (an
+// emailed link still signs in a linked account). The link lookup is one
+// query on the UNIQUE (issuer, person_id) index; an error offers nothing.
+func (a *app) offersHomeLink(r *http.Request, v viewer) bool {
+ if a.home == nil || !v.signedIn() || !a.isMember(v.person) || (v.method != "magiclink" && v.method != "keymail") {
+ return false
+ }
+ linked, err := a.home.bridge.Linked(r.Context(), v.person.ID)
+ return err == nil && !linked
}
// switcher is the app switcher, or nil when no hub directory is
diff --git a/internal/calls/home.go b/internal/calls/home.go
index d158a4f..647b4d5 100644
--- a/internal/calls/home.go
+++ b/internal/calls/home.go
@@ -161,7 +161,7 @@ func (a *app) endRemovedSession(w http.ResponseWriter, r *http.Request) {
}
func (a *app) renderHome(w http.ResponseWriter, r *http.Request, state, label string, status int) {
- home := connect.Page(state, label)
+ home := connect.PageFor(r, state, label)
if state == "signedout" {
// Where Sign out lands: the Oficina door, in the door's words
// (connect's name the hub); its Sign in goes to connect's action.
diff --git a/internal/calls/home_connect_item_test.go b/internal/calls/home_connect_item_test.go
new file mode 100644
index 0000000..93d68fd
--- /dev/null
+++ b/internal/calls/home_connect_item_test.go
@@ -0,0 +1,210 @@
+package calls
+
+import (
+ "bytes"
+ "encoding/base64"
+ "encoding/json"
+ "net/http"
+ "regexp"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/home/connect"
+ "amadan.net/oficina/home/handoff/seal"
+)
+
+// connectItem is the account menu's "Connect your Oficina account".
+const connectItem = `<a estilo-menu-item href="/account/home"><span estilo-menu-label>Connect your Oficina account</span></a>`
+
+// localComplete signs alice in with an emailed link in this browser and
+// returns where GET /auth/local/complete sends her, without following it.
+func (f *homeRouterFixture) localComplete(t *testing.T) string {
+ t.Helper()
+ homeRedirect(t, f.do("POST", "/signin", "address=alice%40example.test&force=1"))
+ link := regexp.MustCompile(`https://[^\s<>\"]+/auth/verify\?[^\s<>\"]+`).FindString(f.mailBody())
+ if link == "" {
+ t.Fatal("no captured local verification link")
+ }
+ if landing := homeRedirect(t, f.followLink(t, link)); landing != connect.LocalCompletePath {
+ t.Fatal("wrong local landing", landing)
+ }
+ return homeRedirect(t, f.do("GET", connect.LocalCompletePath, ""))
+}
+
+// existingAccount gives alice the account an unknown Oficina sign-in asks
+// her to sign in to: one earlier emailed-link sign-in (which creates her
+// persons row on /continue), then sign out. Without the row the resume
+// cannot bind, and connect falls back to the Connect page.
+func (f *homeRouterFixture) existingAccount(t *testing.T) {
+ t.Helper()
+ f.local(t)
+ homeSignout(t, f.do("POST", "/signout", ""))
+}
+
+// linkedRows is how many stored links alice's persons row has.
+func (f *homeRouterFixture) linkedRows(t *testing.T) int {
+ t.Helper()
+ var n int
+ if err := f.app.db.Writer().QueryRow("SELECT count(*) FROM home_identity_links l JOIN persons p ON p.id = l.person_id WHERE p.email = 'alice@example.test'").Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ return n
+}
+
+// confirmAndLand presses Connect accounts on the confirm page and follows
+// the answer to the page it leads to, which must be "Accounts connected"
+// whose one button goes back to want.
+func (f *homeRouterFixture) confirmAndLand(t *testing.T, want string) {
+ t.Helper()
+ next := homeRedirect(t, f.do("POST", "/account/home/confirm", ""))
+ if !strings.HasPrefix(next, "/account/home/confirm?") {
+ t.Fatalf("the confirm POST leads to %q, not the connected page", next)
+ }
+ w := f.do("GET", next, "")
+ body := w.Body.String()
+ if w.Code != http.StatusOK || !strings.Contains(body, "<h1>Accounts connected</h1>") {
+ t.Fatalf("after the confirm POST: %d, want Accounts connected:\n%s", w.Code, body)
+ }
+ if button := `<a rst-btn="primary" href="` + want + `">Back to the app</a>`; !strings.Contains(body, button) {
+ t.Fatalf("Accounts connected does not lead back with %q:\n%s", button, body)
+ }
+}
+
+// Paul's bug: a linked account signed in with the app's own emailed link
+// was still offered "Connect your Oficina account". The offer follows the
+// stored link, not how this session signed in.
+func TestTheConnectItemFollowsTheStoredLinkNotTheSessionMethod(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ if body := f.do("GET", "/", "").Body.String(); !strings.Contains(body, connectItem) {
+ t.Fatalf("an unlinked local session is not offered to connect:\n%s", body)
+ }
+ f.link(t) // ends signed in through Home
+ if body := f.do("GET", "/", "").Body.String(); strings.Contains(body, "/account/home") {
+ t.Fatal("a Home session is offered to connect the account it already is")
+ }
+ if f.linkedRows(t) != 1 {
+ t.Fatal("the link flow stored no link")
+ }
+ homeSignout(t, f.do("POST", "/signout", ""))
+ f.local(t)
+ if body := f.do("GET", "/", "").Body.String(); strings.Contains(body, connectItem) {
+ t.Fatal("a linked account signed in by emailed link is still offered to connect")
+ }
+}
+
+// Right after Connect accounts, in the same (emailed-link) session: the
+// answer is "Accounts connected", the link row exists, and the next page's
+// menu no longer offers to connect.
+func TestConfirmingTheLinkSaysSoAndRetiresTheMenuItem(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ if w := f.do("GET", "/account/home", ""); w.Code != 200 {
+ t.Fatal("account", w.Code)
+ }
+ start := homeRedirect(t, f.do("POST", "/account/home", ""))
+ if next := homeRedirect(t, f.exchange(t, start, "opaque-home-alice")); next != "/account/home/confirm" {
+ t.Fatal("confirmation", next)
+ }
+ w := f.do("GET", "/account/home/confirm", "")
+ if w.Code != 200 || !strings.Contains(w.Body.String(), "<h1>Connect these two accounts?</h1>") || !strings.Contains(w.Body.String(), "alice@example.test") {
+ t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String())
+ }
+ f.confirmAndLand(t, "/")
+ if f.linkedRows(t) != 1 {
+ t.Fatal("Connect accounts stored no link")
+ }
+ if body := f.do("GET", "/", "").Body.String(); strings.Contains(body, connectItem) {
+ t.Fatal("the menu still offers to connect right after connecting")
+ }
+}
+
+// An Oficina sign-in with no link here shows the unknown page, whose one
+// button is the local sign-in. Signing in locally in the same browser then
+// begins the link itself: the Home freshness start, a fresh assertion, the
+// confirm page, and Connect accounts stores the link, landing back on the
+// page the sign-in was for.
+func TestAnUnknownOficinaSigninResumesAsALinkAfterLocalSignin(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.existingAccount(t)
+ start := homeRedirect(t, f.do("GET", "/signin?return_to=%2Fsettings", ""))
+ w := f.exchange(t, start, "opaque-home-alice")
+ if w.Code != http.StatusForbidden || !strings.Contains(w.Body.String(), `<a rst-btn="primary" href="/signin/local">Sign in to your existing account</a>`) {
+ t.Fatalf("unknown assertion: %d, want the unknown page:\n%s", w.Code, w.Body.String())
+ }
+ resume := f.localComplete(t)
+ if resume != "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm" {
+ t.Fatalf("local sign-in after an unknown assertion lands on %q, not the Home freshness start", resume)
+ }
+ if _, ok := f.cookies["__Host-oficina-home-init"]; !ok {
+ t.Fatal("no link initiation cookie")
+ }
+ if next := homeRedirect(t, f.exchange(t, resume, "opaque-home-alice")); next != "/account/home/confirm" {
+ t.Fatal("after the fresh assertion", next)
+ }
+ if w := f.do("GET", "/account/home/confirm", ""); w.Code != 200 || !strings.Contains(w.Body.String(), "<h1>Connect these two accounts?</h1>") {
+ t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String())
+ }
+ if f.linkedRows(t) != 0 {
+ t.Fatal("linked before the confirm click")
+ }
+ f.confirmAndLand(t, "/settings")
+ if f.linkedRows(t) != 1 {
+ t.Fatal("Connect accounts stored no link")
+ }
+ homeSignout(t, f.do("POST", "/signout", ""))
+ start = homeRedirect(t, f.do("GET", "/signin", ""))
+ if w := f.exchange(t, start, "opaque-home-alice"); w.Code != 303 {
+ t.Fatalf("Oficina sign-in after linking: %d\n%s", w.Code, w.Body.String())
+ }
+}
+
+// homeMarker seals connect's local-link navigation marker as connect
+// does, for the fixture's Home DEK, issued at issued.
+func homeMarker(t *testing.T, action string, issued time.Time) *http.Cookie {
+ t.Helper()
+ s, err := seal.New(bytes.Repeat([]byte{7}, 32), "oficina/calls")
+ if err != nil {
+ t.Fatal(err)
+ }
+ payload, _ := json.Marshal(struct {
+ Version int `json:"v"`
+ Action string `json:"action"`
+ Issued int64 `json:"issued"`
+ Expires int64 `json:"expires"`
+ }{1, action, issued.Unix(), issued.Unix() + 600})
+ sealed, err := s.Seal("oficina/calls.local-link-navigation.v1:"+homeTestOrigin, payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return &http.Cookie{Name: "__Host-oficina-local-link-navigation", Value: base64.RawURLEncoding.EncodeToString(sealed)}
+}
+
+// An expired unknown-assertion marker (10 minutes) is ignored: the local
+// sign-in lands on /continue as any other. The same marker, current, does
+// resume, which shows the forged marker is the one connect writes.
+func TestAnExpiredUnknownMarkerLandsAsBefore(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.existingAccount(t)
+ f.cookies["__Host-oficina-local-link-navigation"] = homeMarker(t, "link-resume", time.Now().Add(-11*time.Minute))
+ if got := f.localComplete(t); got != "/continue" {
+ t.Fatalf("expired marker: local sign-in lands on %q, want /continue", got)
+ }
+ homeSignout(t, f.do("POST", "/signout", ""))
+ f.cookies["__Host-oficina-local-link-navigation"] = homeMarker(t, "link-resume", time.Now().Add(-time.Minute))
+ if got := f.localComplete(t); got != "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm" {
+ t.Fatalf("current marker: local sign-in lands on %q, want the Home freshness start", got)
+ }
+}
+
+// The connect pages' two buttons share one form-foot row, primary first.
+func TestTheConnectPagesButtonsShareOneRowPrimaryFirst(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ body := f.do("GET", "/account/home", "").Body.String()
+ want := `<div rst-form-foot><form method="post" action="/account/home"><button rst-btn="primary" type="submit">Connect</button></form><a rst-btn="ghost" href="/">Back</a></div>`
+ if !strings.Contains(body, want) {
+ t.Fatalf("the connect page's buttons are not one row, primary first; want %s in:\n%s", want, body)
+ }
+}