oficina / sheets Public

wip: review fixes

claude agent, operated by paul@keymail.dev 69b704fbc0d16105831a2316969d6880d0836b8e parent eb88892
9 files changed, +102 −35
  • go.mod +2 −2
  • go.sum +2 −2
  • internal/sheets/auth.go +14 −1
  • internal/sheets/keymail_signin_test.go +1 −0
  • internal/sheets/rhythm_browser_test.go +42 −11
  • internal/sheets/signin_door_states_test.go +3 −2
  • internal/sheets/static/sheets.css +33 −12
  • internal/sheets/templates/import.html +1 −1
  • internal/sheets/templates/import_report.html +4 −4
diff --git a/go.mod b/go.mod
index 92b02fb..7338338 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,8 @@ require (
amadan.net/oficina/home/handoff v0.0.0-20261121235253-98726fac99a7
amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2
amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2
- amadan.net/rastrillo/rastrillo v0.44.1
+ amadan.net/rastrillo/fiesta v1.6.1
+ amadan.net/rastrillo/rastrillo v0.45.0
github.com/carlosframework/rastrillo v0.23.0
github.com/chromedp/cdproto v0.158.6
github.com/chromedp/chromedp v0.21.0
@@ -23,7 +24,6 @@ require (
)
require (
- amadan.net/rastrillo/fiesta v1.6.1 // indirect
amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
diff --git a/go.sum b/go.sum
index 71d2f20..cd23d09 100644
--- a/go.sum
+++ b/go.sum
@@ -16,8 +16,8 @@ amadan.net/rastrillo/fiesta v1.6.1 h1:WYgHt652+uQj6eR0Y0JLin+XrdRPGk1WPW7o0lSrc9
amadan.net/rastrillo/fiesta v1.6.1/go.mod h1:LpO391W1dIRUxOIKklHm+bGyWXtlFyBRRPQCysb9LjY=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3/go.mod h1:ZaaxeE278dJltdrLwmwpxUjQ5wuKzqDAVSNRet+WupY=
-amadan.net/rastrillo/rastrillo v0.44.1 h1:7RNROXSmxr1m9Ax/siyPxS2DEjppIHAj/jWectdoxVQ=
-amadan.net/rastrillo/rastrillo v0.44.1/go.mod h1:0bufVMz8D4aWvxvJjehW70T8Jsvytrp1YEwoIzFTKm8=
+amadan.net/rastrillo/rastrillo v0.45.0 h1:zJfxetxg/H/CkCBFIvdGQbiATQ0hV3JR7H82AMk4bmM=
+amadan.net/rastrillo/rastrillo v0.45.0/go.mod h1:Vk7QL+RePyKtcP+7XclR9hpSDp/CjrVo37TENKifaFY=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
diff --git a/internal/sheets/auth.go b/internal/sheets/auth.go
index aa06139..d646f68 100644
--- a/internal/sheets/auth.go
+++ b/internal/sheets/auth.go
@@ -169,6 +169,15 @@ func splitOwners(raw string) []string {
return out
}
+// keymailTestServers is auth.Config.KeymailServers, and nil outside
+// this package's tests. From rastrillo v0.45.0 an unlisted Keymail
+// server is dialed only at a public address, by a client cloned from
+// http.DefaultTransport; the tests' in-process Keymail fixtures
+// (keymailtest) answer behind a wrapped DefaultTransport at a name
+// nothing resolves, so TestMain lists their host here, and auth reaches
+// them through its listed-servers guard instead.
+var keymailTestServers []string
+
// NewAuth wires the sign-in flow. Exactly one per process: auth's
// underlying flow carries rate-limiter state on the value, so one per
// request would get a fresh empty budget every time and rate-limit
@@ -234,7 +243,11 @@ func NewAuth(db *sql.DB, env AuthEnv, logger *slog.Logger, app *App) (*auth.Auth
// offer sign-in, and has to be told it worked.
SignedInPath: signedInPath,
Subject: chrome.EmailSubject("Sheets"),
- Logger: logger,
+ // nil in every deployment: rastrillo's default, any server an
+ // address's own _keymail delegation names, dialed only at a
+ // public address. Only the tests list one (keymailTestServers).
+ KeymailServers: keymailTestServers,
+ Logger: logger,
})
if err != nil {
queue.close()
diff --git a/internal/sheets/keymail_signin_test.go b/internal/sheets/keymail_signin_test.go
index 9311d0c..fbec938 100644
--- a/internal/sheets/keymail_signin_test.go
+++ b/internal/sheets/keymail_signin_test.go
@@ -20,6 +20,7 @@ import (
// registers answer HTTPS (keymailtest). Before it, every POST /signin
// in this suite classified its address against the real network.
func TestMain(m *testing.M) {
+ keymailTestServers = []string{keymailHost}
restore, err := keymailtest.Install()
if err != nil {
fmt.Fprintln(os.Stderr, "keymailtest.Install:", err)
diff --git a/internal/sheets/rhythm_browser_test.go b/internal/sheets/rhythm_browser_test.go
index 8592b63..1da6f0a 100644
--- a/internal/sheets/rhythm_browser_test.go
+++ b/internal/sheets/rhythm_browser_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"time"
+ "amadan.net/oficina/estilo.git/googleimport"
"amadan.net/rastrillo/fiesta/check/rhythm"
"amadan.net/rastrillo/rastrillo/harness"
"github.com/chromedp/cdproto/emulation"
@@ -31,15 +32,31 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
app, cookies := signIn(t)
s, cells := newSheet(t, app, cookies, "Quarterly plan")
postCell(t, app, cookies, cells, `{"r":0,"c":0,"raw":"Revenue"}`)
+ // A workbook whose report has lines, so the report's list is read.
+ report := importWorkbook(t, app, cookies, googleWorkbook(t, googleRows))
- rig := harness.New(t, func(string) http.Handler { return productionHandler(t, app) })
+ // The import page with Google Drive configured: its section is
+ // drawn only then.
+ google := New(Config{DB: app.db, Auth: app.auth, Sealer: app.sealer, Origin: testOrigin, Admit: app.admit,
+ GoogleImport: googleimport.Config{ClientID: "123456789-client.apps.googleusercontent.com", APIKey: "AIzaPublicBrowserKey123456789", AppID: "123456789"}})
+
+ serving := http.Handler(productionHandler(t, app))
+ rig := harness.New(t, func(string) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { serving.ServeHTTP(w, r) })
+ })
// Each screen is loaded once, at a desktop width, and read there and
- // again at a phone's.
- audit := func(name, path, ready string, skip []string) {
+ // again at a phone's. ready is a selector only that screen draws, the
+ // browser must still be on path when it is read (a lost session
+ // lands on the sign-in door, whose rhythm is not this page's), and
+ // main must hold at least blocks children, so a page that drew
+ // nothing cannot pass by having nothing to measure.
+ audit := func(name, path, ready string, blocks int, skip []string) {
t.Helper()
for i, width := range []int64{1280, 390} {
ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second)
var found []rhythm.Finding
+ var at string
+ var drawn int
actions := []chromedp.Action[chromedp.Void]{
command(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: width, Height: 900, DeviceScaleFactor: 1}),
}
@@ -48,19 +65,27 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
}
actions = append(actions,
chromedp.WaitVisible(chromedp.CSS(ready)),
+ evalInto(&at, `location.pathname + location.search`),
+ evalInto(&drawn, `[...document.querySelector('main').children].filter(e => e.getClientRects().length > 0).length`),
evalInto(&found, rhythm.Expression("main", rhythm.Options{Skip: skip})))
err := chromedp.Do(ctx, actions...)
cancel()
if err != nil {
t.Fatalf("%s at %dpx: %v", name, width, err)
}
+ if at != path {
+ t.Fatalf("%s: the browser is at %s, not %s", name, at, path)
+ }
+ if drawn < blocks {
+ t.Fatalf("%s at %dpx: main draws %d blocks, want at least %d", name, width, drawn, blocks)
+ }
if len(found) > 0 {
t.Errorf("%s at %dpx: %s", name, width, rhythm.Report(found))
}
}
}
- audit("the sign-in door", "/signin", `input[name="address"]`, nil)
+ audit("the sign-in door", "/signin", `input[name="address"]`, 1, nil)
var set []chromedp.Action[chromedp.Void]
for _, c := range cookies {
@@ -69,12 +94,18 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
rig.Run(set...)
sheet := fmt.Sprintf("/sheets/%d", s.ID)
- audit("the list", "/sheets", `main`, nil)
- audit("the sheet", sheet, `td[data-x="0"][data-y="0"]`,
+ audit("the list", "/sheets", `[data-sheet-list]`, 2, nil)
+ // The sheet is the grid and its chrome, all of it a component's
+ // own: what is left is the formula row and the notices.
+ audit("the sheet", sheet, `td[data-x="0"][data-y="0"]`, 1,
[]string{"[data-sheet-grid]", "[data-menubar]", "[data-toolbar]", "[data-tabstrip]"})
- audit("share", sheet+"/share", `input[name=address], input[type=email]`, nil)
- audit("comments", sheet+"/comments", `main textarea, main input[type=text]`, nil)
- audit("history", sheet+"/history", `main`, nil)
- audit("the table view", sheet+"/table", `table[data-cell-table]`, []string{"table[data-cell-table]"})
- audit("import", "/sheets/import", `main input[type=file]`, nil)
+ audit("share", sheet+"/share", `#role`, 6, nil)
+ audit("comments", sheet+"/comments", `main textarea[name], main form[rst-form]`, 3, nil)
+ audit("history", sheet+"/history", `main form[action$="/undo"]`, 3, nil)
+ audit("the table view", sheet+"/table", `table[data-cell-table]`, 3, []string{"table[data-cell-table]"})
+ audit("import", "/sheets/import", `main input[type=file]`, 2, nil)
+ audit("an import report", report, `[data-import-report]`, 3, nil)
+
+ serving = productionHandler(t, google)
+ audit("import, with Google Drive", "/sheets/import", `main [estilo-google-import], main section h2`, 3, nil)
}
diff --git a/internal/sheets/signin_door_states_test.go b/internal/sheets/signin_door_states_test.go
index ab3e73c..27a53cf 100644
--- a/internal/sheets/signin_door_states_test.go
+++ b/internal/sheets/signin_door_states_test.go
@@ -65,13 +65,14 @@ func TestSmartDoorStatesWithHome(t *testing.T) {
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}},
+ // rastrillo v0.45.0: the door never names Keymail.
+ want: []string{"Continue as <bdi>bob@example.com</bdi>", `name="expect" value="keymail"`, otherWays}},
{name: "problem", path: "/signin?err=rate", record: oficina,
want: []string{"Too many tries. Try again in a few minutes.", emailField},
not: []string{oficinaButton},
title: "Problem signing in to Sheets"},
{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"}},
+ want: []string{"We 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},
diff --git a/internal/sheets/static/sheets.css b/internal/sheets/static/sheets.css
index cac6347..85704b1 100644
--- a/internal/sheets/static/sheets.css
+++ b/internal/sheets/static/sheets.css
@@ -71,8 +71,8 @@
* inline padding as estilo's items, so their labels line up with the
* item text above and below. */
[data-menubar] [estilo-menu] > [data-size-form] {
- /* spacing-allow: estilo's own item inset (its value as the fallback), so the labels line up with the items' */
- padding: var(--rst-sp-1) var(--estilo-item-padding-inline, 0.65rem);
+ /* spacing-allow: estilo's item inset, declared in estilo's menu.css, which this check does not read */
+ padding: var(--rst-sp-1) var(--estilo-item-padding-inline, var(--rst-sp-3));
}
/* ── The keyboard shortcuts dialog ──────────────────────────────────
@@ -900,6 +900,14 @@
z-index: 50;
}
+/* The overlay is position: fixed, but it is also <main>'s child, and
+ * the stack gives every child after the first a block-start margin,
+ * which a fixed box still takes: it opened 4px below the window's top.
+ * (0,3,0), as the stack's own rule, and later. */
+[rst-stack] > [data-drop-page][rst-modal-overlay] {
+ margin: 0;
+}
+
[data-drop-page] [rst-modal-panel] {
max-width: 24rem;
transition: border-color 120ms ease;
@@ -1146,7 +1154,7 @@
[data-cell-format] select {
font-size: var(--rst-fs-xs);
- padding-block: 0.15rem; /* spacing-allow: the compact selects at the xs size, the row's density */
+ padding-block: var(--rst-sp-1);
}
/* ── The list's thumbnails ───────────────────────────────────────────
@@ -1174,16 +1182,11 @@
* never had — not to drop the semantics that make the list announce as
* one to a screen reader.
*
- * The block margin is REPLACED rather than removed. Nothing in
- * rastrillo stacks the children of [rst-page] — there is no
- * `> * + *` rule — so what separated this card from the import form
- * above it was the <ul>'s own UA `margin-block: 1em`. Zeroing the
- * shorthand would have closed that gap as a side effect of fixing the
- * padding, so the margin is restated from the token scale, which is
- * where every other gap on the page comes from. */
+ * It sets no block margin: <main> is Fiesta's stack (layout.html),
+ * which spaces the list from whatever is above and below it, and whose
+ * child rule zeroes the <ul>'s UA `margin-block: 1em` anyway. */
[data-sheet-list] {
list-style: none;
- margin-block: var(--rst-sp-4);
margin-inline: 0;
padding: 0;
}
@@ -1215,7 +1218,6 @@
* columns directly, so the narrow rule restates them. */
[data-share-list] {
list-style: none;
- margin-block: var(--rst-sp-3) var(--rst-sp-4);
margin-inline: 0;
padding: 0;
}
@@ -1319,3 +1321,22 @@
display: inline;
margin-inline-start: var(--rst-sp-2);
}
+
+/* ── Import from Google Drive ─────────────────────────────────────────
+ *
+ * estilo's chooser (estilo-google-import) brings markup and no
+ * stylesheet, so its paragraphs kept the browser's 1em margins: its
+ * disclosure sat 24px under its heading and its status 60-odd px under
+ * the disclosure, around the Choose button the script reveals. Spaced
+ * here as a column on the scale, the buttons at their own width, until
+ * estilo spaces it itself. */
+[estilo-google-import] {
+ align-items: flex-start;
+ display: flex;
+ flex-direction: column;
+ gap: var(--rst-sp-3);
+}
+
+[estilo-google-import] p {
+ margin: 0;
+}
diff --git a/internal/sheets/templates/import.html b/internal/sheets/templates/import.html
index e9ef46f..933809a 100644
--- a/internal/sheets/templates/import.html
+++ b/internal/sheets/templates/import.html
@@ -63,7 +63,7 @@ the import finishes.</p>
scripting off the component says how to download from Google and
use the form instead. */}}
{{if .Data.Google.Enabled}}
-<section>
+<section rst-stack rst-section>
<h2>From Google Drive</h2>
{{template "estilo-google-import" .Data.Google}}
</section>
diff --git a/internal/sheets/templates/import_report.html b/internal/sheets/templates/import_report.html
index 68f63ef..ba6c832 100644
--- a/internal/sheets/templates/import_report.html
+++ b/internal/sheets/templates/import_report.html
@@ -10,7 +10,7 @@
{{/* Always shown, whatever the report holds: a report can only list
what it detected, so the page says what import carries at all
rather than let an empty list read as "everything". */}}
-<section>
+<section rst-stack rst-section>
<h2>What import carries</h2>
<p>The first worksheet's values; formulas Sheets can calculate; number
formats written as format codes; fill and text colours; bold, italic and
@@ -22,12 +22,12 @@ original file.</p>
{{template "callout" (dict "Body" (printf "Only the first worksheet came across. %d other worksheet(s) were left out." .Data.OmittedWorksheets) "Tone" "warning")}}
{{end}}
-<section>
+<section rst-stack rst-section>
<h2>What changed or was left out</h2>
{{if .Data.Lines}}
-<ul data-import-report>
+<ul rst-stack data-import-report>
{{range .Data.Lines}}
-<li>
+<li rst-stack>
<p><strong>{{.Title}}</strong>: {{.Count}}</p>
{{with .Detail}}<p>{{.}}</p>{{end}}
{{if .Cells}}<p rst-field-help>Cells: {{range $i, $c := .Cells}}{{if $i}}, {{end}}{{$c}}{{end}}{{if .More}}, and {{.More}} more{{end}}.</p>{{end}}