oficina / memoria Public

Review fixes (Fable 5.2): audit the correction forms, drop zone and more states; dial gate on production's Keymail config

Paul Campbell pushed by claude agent, operated by paul@keymail.dev 0d322c93dbba1b8e5646103e15dbe6a8d96ea84f parent 07e611f
4 files changed, +162 −36
  • AGENTS.md +5 −4
  • internal/memoria/static/memoria.css +3 −1
  • internal/memoriatest/rhythm_browser_test.go +139 −25
  • internal/memoriatest/signindial_test.go +15 −6

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/memoria/ ./internal/memoriatest/
=== fmt ===
=== test ===
go test ./...
?   	amadan.net/oficina/memoria/cmd/memoria	[no test files]
?   	amadan.net/oficina/memoria/cmd/memoria-contract	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoria	13.165s
ok  	amadan.net/oficina/memoria/internal/memoria/chunk	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/fact	(cached)
?   	amadan.net/oficina/memoria/internal/memoria/icons	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoria/index	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/notion	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/provider	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/query	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/seal	(cached)
ok  	amadan.net/oficina/memoria/internal/memoria/sibling	(cached)
?   	amadan.net/oficina/memoria/internal/memoria/teamstate	[no test files]
ok  	amadan.net/oficina/memoria/internal/memoriatest	5.236s
?   	amadan.net/oficina/memoria/scripts/writeestilo	[no test files]
?   	amadan.net/oficina/memoria/tools/bench	[no test files]
?   	amadan.net/oficina/memoria/tools/drive	[no test files]
?   	amadan.net/oficina/memoria/tools/seed	[no test files]
?   	amadan.net/oficina/memoria/tools/vendorassets	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== spacing ===
go tool fiesta spacing -skip tokens.css internal/memoria/static
diff --git a/AGENTS.md b/AGENTS.md
index 99d7936..d65e5fd 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -168,10 +168,11 @@ so; it never renders as a confident zero.
blocks; every other margin, padding and gap is a `var(--rst-sp-N)`,
or carries `/* spacing-allow: why */` for real geometry. `make
spacing` (in `make ci`) reads static/; `TestEveryScreenKeepsTheRhythm`
- (`make browser`) runs Fiesta's rhythm audit over every screen. A new
- screen goes in its list, and a new region of Memoria's own with an
- rst- name goes in `rhythmRegions`, because the audit does not walk
- into rst- names it does not know. Field rules are `form[rst-stack]`,
+ (`make browser`) runs Fiesta's rhythm audit over the screens in its
+ list, in the states that change their blocks. A new screen or state
+ goes in that list, and a new region of Memoria's own with an rst-
+ name goes in `rhythmRegions`, because the audit does not walk into
+ rst- names it does not know. Field rules are `form[rst-stack]`,
never a bare `[rst-stack]`, which since `<main>` is one reaches every
field on every page.
- **Look at the page.** `tools/drive` serves the app with sign-in off so a
diff --git a/internal/memoria/static/memoria.css b/internal/memoria/static/memoria.css
index 5bc380f..36770bf 100644
--- a/internal/memoria/static/memoria.css
+++ b/internal/memoria/static/memoria.css
@@ -235,7 +235,9 @@ form[rst-stack] textarea {
padding: var(--rst-sp-2) var(--rst-sp-3);
width: 100%;
}
-form[rst-stack] input:focus-visible,
+form[rst-stack] input[type="text"]:focus-visible,
+form[rst-stack] input[type="email"]:focus-visible,
+form[rst-stack] input[type="password"]:focus-visible,
form[rst-stack] textarea:focus-visible {
border-color: var(--rst-accent);
outline: 2px solid var(--rst-accent);
diff --git a/internal/memoriatest/rhythm_browser_test.go b/internal/memoriatest/rhythm_browser_test.go
index ba04fc0..11bdad5 100644
--- a/internal/memoriatest/rhythm_browser_test.go
+++ b/internal/memoriatest/rhythm_browser_test.go
@@ -20,11 +20,20 @@
// root is always walked. Fiesta's own components inside them (a callout,
// a table, a list row) are still Fiesta's.
//
-// The skips, and only these: the document's own text inside the paper
-// card ([rst-passage], the renderer's paragraphs, lists, tables and
-// quotes, spaced as a document is and not as a screen), and the
-// connect pages' and the door's insides, which are estilo's and Home's
-// and audited there (estilo 6238a47; Home 8125a3c).
+// One skip: the Colophon's list ([estilo-credits]), estilo's template
+// and stylesheet, whose h1 and list keep the browser's margins (18.8px);
+// that is estilo's to put on a stack. The door's card and the connect
+// pages are estilo's too, and opaque here by their estilo- and rst-
+// names without a skip; estilo audits its own card (6238a47).
+//
+// Screens are drawn in the states that change their blocks: the front
+// page with recent searches, a fact box, ?explain=facts, an AI answer,
+// no results, a document, its delete question, Add content (and with
+// its outcome flash), Sources and Notion unconnected and then connected
+// with an import behind them and suite apps in each breaker state, a
+// correction, Reports with a row, the 👎 page, the Colophon, a 404, and
+// team mode's partial lists. Not the upload tray: it is fixed in the
+// corner, out of the page's flow.
//
// Written against origin/main (5d9034d) first, its static/ and
// templates/ under this branch's go.mod: 72 findings on 26 of the 34
@@ -61,7 +70,9 @@ import (
"github.com/chromedp/chromedp"
memoria "amadan.net/oficina/memoria/internal/memoria"
+ "amadan.net/oficina/memoria/internal/memoria/notion"
"amadan.net/oficina/memoria/internal/memoria/provider"
+ "amadan.net/oficina/memoria/internal/memoria/sibling"
)
// quickAI answers at once, with a paragraph and a list, so the answer
@@ -91,6 +102,8 @@ var rhythmRegions = []string{
"[rst-fact-box]",
"[rst-paper]",
"[rst-correct]",
+ "[rst-correct-form]",
+ "[rst-dropzone]",
"[rst-sources] > li",
"[rst-report]",
"[rst-page-footer]",
@@ -98,8 +111,6 @@ var rhythmRegions = []string{
// rhythmSkip are the regions whose spacing is not the page's.
var rhythmSkip = []string{
- "[rst-passage]",
- "[rst-doc-props]",
// The Colophon is estilo's template and estilo's stylesheet
// (estilo/credits); its h1 and list keep the browser's margins, which
// is estilo's to put on its stack.
@@ -137,6 +148,12 @@ var settle = evalOnly(`document.fonts.ready.then(() => true)`, func(p *runtime.E
// TestEveryScreenKeepsTheRhythm is the audit over every signed-in
// screen, at a desktop width and a phone's.
func TestEveryScreenKeepsTheRhythm(t *testing.T) {
+ var app interface {
+ Store() *memoria.Store
+ UseFakeSource(memoria.SourceClient, func(context.Context, string) (string, error))
+ UseSiblings(memoria.Custody)
+ PreviewUnknownStanding()
+ }
rig := harness.New(t, func(origin string) http.Handler {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger)
@@ -148,6 +165,7 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
if err != nil {
t.Fatalf("AppForTest: %v", err)
}
+ app = a
a.UseFakeModel(quickAI{})
for _, doc := range [][2]string{
{"Office", "## Office Address\n\nThe office phone number is: +353 (0)1 547 7854\n\n" +
@@ -205,6 +223,27 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
feedback = u.Path
}
+ audit := func(path string, width int64, actions ...chromedp.Action[chromedp.Void]) {
+ t.Helper()
+ ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second)
+ defer cancel()
+ err := chromedp.Do(ctx, append([]chromedp.Action[chromedp.Void]{chromedp.EmulateViewport(width, 900)}, append(actions, settle)...)...)
+ var found []rhythm.Finding
+ if err == nil {
+ found, err = auditRhythm(ctx)
+ }
+ if err != nil {
+ t.Fatalf("%s at %dpx: %v", path, width, err)
+ }
+ if len(found) > 0 {
+ t.Errorf("%s at %dpx: %s", path, width, rhythm.Report(found))
+ }
+ }
+ visit := func(path, ready string, width int64) {
+ t.Helper()
+ audit(path, width, chromedp.Navigate(rig.Origin+path), chromedp.WaitVisible(chromedp.CSS(ready)))
+ }
+
screens := []struct{ path, ready string }{
{"/", `[rst-home]`},
{"/?q=" + url.QueryEscape("office phone number"), `[rst-fact-box]`},
@@ -225,26 +264,101 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) {
}
for _, width := range []int64{1280, 390} {
for _, s := range screens {
- ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second)
- err := chromedp.Do(ctx,
- chromedp.EmulateViewport(width, 900),
- chromedp.Navigate(rig.Origin+s.path),
- chromedp.WaitVisible(chromedp.CSS(s.ready)),
- settle,
- )
- var found []rhythm.Finding
- if err == nil {
- found, err = auditRhythm(ctx)
- }
- cancel()
- if err != nil {
- t.Fatalf("%s at %dpx: %v", s.path, width, err)
- }
- if len(found) > 0 {
- t.Errorf("%s at %dpx: %s", s.path, width, rhythm.Report(found))
- }
+ visit(s.path, s.ready, width)
+ }
+ // Add content with its outcome: the flash under the form.
+ audit("/add, stored", width,
+ chromedp.Navigate(rig.Origin+"/add"),
+ chromedp.WaitVisible(chromedp.CSS(`textarea[name="body"]`)),
+ chromedp.SendKeys(chromedp.CSS(`textarea[name="body"]`), "The fire drill is on Thursdays."),
+ chromedp.Click(chromedp.CSS(`[rst-actions] button`)),
+ chromedp.WaitVisible(chromedp.CSS(`main [rst-callout]`)),
+ )
+ }
+
+ // Sources and Notion connected, with an import behind them, and the
+ // suite apps in the breaker's three states (tools/drive's seed).
+ seedRhythmConnector(t, app)
+ seedRhythmSiblings(t, app)
+ for _, width := range []int64{1280, 390} {
+ visit("/connectors/notion", `[rst-facts]`, width)
+ visit("/connectors", `[rst-source-name]`, width)
+ }
+
+ // Team mode with the reader's standing unknown: the list pages are
+ // partial, with the notice.
+ app.PreviewUnknownStanding()
+ for _, width := range []int64{1280, 390} {
+ for _, path := range []string{"/", "/documents", "/reports", "/?q=" + url.QueryEscape("office phone number")} {
+ visit(path, `main [rst-callout]`, width)
+ }
+ }
+}
+
+// rhythmSource is a two-page stand-in for Notion.
+type rhythmSource struct{}
+
+func (rhythmSource) Roots(context.Context) (roots, orphans []notion.Ref, err error) {
+ return []notion.Ref{{ID: "handbook", Title: "Handbook", EditedTime: "t1", Kind: notion.KindPage}}, nil, nil
+}
+
+func (rhythmSource) Fetch(_ context.Context, ref notion.Ref) (*notion.Content, error) {
+ c := &notion.Content{Markdown: "## " + ref.Title + "\n\nImported for the rhythm audit.", UnreadBlocks: 2}
+ if ref.ID == "handbook" {
+ c.Children = []notion.Ref{{ID: "onboarding", Title: "Onboarding", Path: []string{"Handbook"}, EditedTime: "t1", Kind: notion.KindPage}}
+ }
+ return c, nil
+}
+
+// seedRhythmConnector connects Notion and runs one import to the end.
+func seedRhythmConnector(t *testing.T, app interface {
+ Store() *memoria.Store
+ UseFakeSource(memoria.SourceClient, func(context.Context, string) (string, error))
+}) {
+ t.Helper()
+ ctx := context.Background()
+ app.UseFakeSource(rhythmSource{}, func(context.Context, string) (string, error) { return "rhythm-workspace", nil })
+ if err := app.Store().SaveConnector(ctx, "notion", "ntn_rhythm_token", "rhythm-workspace"); err != nil {
+ t.Fatal(err)
+ }
+ c, err := app.Store().Connector(ctx, "notion")
+ if err != nil {
+ t.Fatal(err)
+ }
+ run, err := app.Store().StartRun(ctx, c.ID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ memoria.NewSyncer(app.Store(), slog.New(slog.NewTextHandler(io.Discard, nil))).RunWith(ctx, rhythmSource{}, c.ID, run.ID)
+}
+
+// seedRhythmSiblings puts three suite apps on Sources, quiet, firing and
+// cannot-determine, as tools/drive does.
+func seedRhythmSiblings(t *testing.T, app interface {
+ Store() *memoria.Store
+ UseSiblings(memoria.Custody)
+}) {
+ t.Helper()
+ ctx := context.Background()
+ custody, err := memoria.NewSiblings("rhythm", nil, []sibling.Sibling{
+ {Name: "Docs", BaseURL: "https://rhythm.docs.oficina.works", Token: "rhythm"},
+ {Name: "Sheets", BaseURL: "https://rhythm.sheets.oficina.works", Token: "rhythm"},
+ {Name: "Calendar", BaseURL: "https://rhythm.calendar.oficina.works", Token: "rhythm"},
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ app.UseSiblings(custody)
+ store, now := app.Store(), time.Now().UTC()
+ for app, since := range map[string]time.Time{"Docs": now.AddDate(0, 0, -30), "Sheets": now.AddDate(0, 0, -30), "Calendar": now.AddDate(0, 0, -2)} {
+ if err := store.StartCounting(ctx, app, since); err != nil {
+ t.Fatal(err)
}
}
+ for _, who := range []string{"ana@example.com", "ben@example.com", "cleo@example.com"} {
+ store.SeedTallyForDrive(ctx, "Sheets", who, now.AddDate(0, 0, -3), 5, 0)
+ store.SeedTallyForDrive(ctx, "Sheets", who, now, 0, 4)
+ }
}
// TestTheDoorKeepsTheRhythm: the signed-out pages, drawn through the
diff --git a/internal/memoriatest/signindial_test.go b/internal/memoriatest/signindial_test.go
index 2609c6a..8fc1371 100644
--- a/internal/memoriatest/signindial_test.go
+++ b/internal/memoriatest/signindial_test.go
@@ -68,6 +68,10 @@ func (m *stubMailer) Send(ctx context.Context, to, subject, body string) error {
const dialTestOwner = "owner@example.test"
+// processTransport is http.DefaultTransport as the process started with
+// it, before any test put a recorder or a fake in its place.
+var processTransport = http.DefaultTransport
+
// signinApp builds the app the way main.go does — production constructor,
// real auth, real owners list — and points the whole process's HTTP
// transport at a recorder.
@@ -93,18 +97,23 @@ func signinAppWithOwners(t *testing.T, owners []string) (http.Handler, *dialReco
if err != nil {
t.Fatalf("App: %v", err)
}
+ // Auth is built over the process's own transport, with KeymailServers
+ // nil as production has it. rastrillo v0.45.0 copies
+ // http.DefaultTransport into its public-addresses-only Keymail client
+ // when auth is built, and panics unless it is an *http.Transport; a
+ // subtest that builds a second app while an earlier app's recorder is
+ // still installed would hand it the recorder. The recorder goes in
+ // below, after: the classifier's first step, the _keymail DNS lookup,
+ // is what it sees, and an owner's sign-in still shows it.
+ installed := http.DefaultTransport
+ http.DefaultTransport = processTransport
au, err := memoria.NewAuth(d.Writer(), memoria.AuthEnv{
Origin: testOrigin,
InstanceKey: "signin-dial-gate-instance-key",
Owners: []string{dialTestOwner},
Mailer: &stubMailer{},
- // Listed, so rastrillo's keymail client sends through
- // http.DefaultTransport, the recorder below. Unlisted (nil, as in
- // production), it copies the transport when auth is built and
- // dials public addresses only, and the recorder would see the
- // DNS half of a dial and never the HTTP half (rastrillo v0.45.0).
- KeymailServers: []string{"example.test"},
}, logger, a)
+ http.DefaultTransport = installed
if err != nil {
t.Fatalf("NewAuth: %v", err)
}