Review L1 and L7: the scoped accessor's guard counts (test and mutation); view forms write no row; the toggle and Help tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fable's Phase 1 review (6e3aa6b): Review L1 and L7: the scoped accessor's guard counts (test and mutation); view forms write no row; the toggle and Help tests
3 files changed,
+158
−0
internal/mapatest/frame_test.go+86 −0internal/mapatest/sidebar_test.go+67 −0scripts/mutate/mutations.go+5 −0
CI passed — run details
CI log
=== editor === cd editor && npm ci --no-audit --no-fund --loglevel=error added 16 packages in 329ms cd editor && node build-bundles.mjs wrote internal/mapa/static/editor.9c9edc5536b1d844.js (36245 bytes, 11.3KB gzipped; L12 budget 120KB) cd editor && node --test ✔ golden file has bodies (0.584249ms) ✔ markup.mjs parses every body into Go's blocks, byte offsets and all (10.818931ms) ✔ markup.mjs strips and spans every block as Go does (14.90523ms) ✔ the schema's toDOM draws every body as Go renders it (30.903438ms) ✔ emphasis draws the four pinned outputs (10.92014ms) ✔ a body ends in the editor's empty paragraph (0.155302ms) ℹ tests 6 ℹ suites 0 ℹ pass 6 ℹ fail 0 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 132.853388 === vet === go vet ./... go vet -tags browser ./internal/mapatest/ === fmt === === code === go tool rastrillo budget code The base has no .rastrillo/code.txt: skipping the check that records only go down. budget code: within the limits. === test === CGO_ENABLED=0 go test ./... ? amadan.net/oficina/mapa/cmd/mapa [no test files] ok amadan.net/oficina/mapa/internal/mapa 0.358s ? amadan.net/oficina/mapa/internal/mapa/icons [no test files] ok amadan.net/oficina/mapa/internal/mapa/markup (cached) ok amadan.net/oficina/mapa/internal/mapa/seal (cached) ok amadan.net/oficina/mapa/internal/mapatest 7.679s ? amadan.net/oficina/mapa/scripts/mutate [no test files] ? amadan.net/oficina/mapa/scripts/preview [no test files] === migration-check === go tool rastrillo migration check rastrillo migration check: models and migrations agree
diff --git a/internal/mapatest/frame_test.go b/internal/mapatest/frame_test.go| new file mode 100644 |
| index 0000000..c016a4d |
| --- /dev/null |
| +++ b/internal/mapatest/frame_test.go |
| @@ -0,0 +1,86 @@ |
| +package mapatest |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// getWith is a GET carrying cookies, as a browser that set them sends. |
| +func (rig *rig) getWith(who, target string, |
| + cookies ...*http.Cookie) string { |
| + recorder := httptest.NewRecorder() |
| + request := httptest.NewRequest(http.MethodGet, target, nil) |
| + for _, cookie := range cookies { |
| + request.AddCookie(cookie) |
| + } |
| + rig.built.As(who).ServeHTTP(recorder, request) |
| + return recorder.Body.String() |
| +} |
| + |
| +// The Links toggle says what the panel is (review M2): expanded when it |
| +// is open, collapsed when the cookie closed it, from first paint. |
| +func TestTheLinksToggleSaysWhetherThePanelIsOpen(t *testing.T) { |
| + rig := newRig(t) |
| + acme := rig.createPage(t, Ana, "Acme", "One.") |
| + toggle := func(page string) string { |
| + return between(page, `aria-controls="mapa-links"`, ">") |
| + } |
| + open := rig.getWith(Ana, acme) |
| + if !strings.Contains(toggle(open), `disabled`) || |
| + !strings.Contains(between(open, `aria-expanded="`, |
| + `" aria-controls="mapa-links"`), "true") { |
| + t.Fatalf("the open panel's toggle: %q", toggle(open)) |
| + } |
| + closed := rig.getWith(Ana, acme, |
| + &http.Cookie{Name: "mapa-links", Value: "closed"}) |
| + collapsed := `aria-expanded="false" aria-controls="mapa-links"` |
| + if !strings.Contains(closed, collapsed) { |
| + t.Fatal("the closed panel's toggle does not say collapsed") |
| + } |
| + if !strings.Contains(closed, `id="mapa-links" aria-label="Links" hidden`) { |
| + t.Fatal("the closed panel is drawn") |
| + } |
| +} |
| + |
| +// The view preferences are cookies, never rows (L7): neither form |
| +// changes a table, whatever it is sent. |
| +func TestViewFormsWriteNoRow(t *testing.T) { |
| + rig := newRig(t) |
| + rig.createPage(t, Ana, "Acme", "One.") |
| + before := dumpAll(t, rig) |
| + for _, route := range []string{"/view/sidebar", "/view/links"} { |
| + for _, state := range []string{"open", "rail", "closed", ""} { |
| + answer := rig.post(t, Ana, route, url.Values{ |
| + "state": {state}, "return": {"/pages"}}) |
| + if answer.Code != http.StatusSeeOther { |
| + t.Fatalf("%s %q answered %d", route, state, answer.Code) |
| + } |
| + } |
| + } |
| + if dumpAll(t, rig) != before { |
| + t.Fatal("a view form wrote to the database") |
| + } |
| +} |
| + |
| +// Help → Markdown in Mapa is a page (review M1), and every row of the |
| +// Help menu leads somewhere that answers. |
| +func TestHelpMarkdownIsAPage(t *testing.T) { |
| + rig := newRig(t) |
| + page := rig.page(t, Ana, "/help/markdown") |
| + for _, words := range []string{"Markdown in Mapa", "[[Page title]]", |
| + "[[2026-11-12]]", "no escapes"} { |
| + if !strings.Contains(page, words) { |
| + t.Errorf("the Markdown help lacks %q", words) |
| + } |
| + } |
| + for _, href := range strings.Split(between(page, `id="mapa-menu-help"`, |
| + "</details>"), `href="`)[1:] { |
| + target, _, _ := strings.Cut(href, `"`) |
| + if answer := rig.get(t, Ana, target); answer.Code != 200 { |
| + t.Errorf("Help's %s answered %d", target, answer.Code) |
| + } |
| + } |
| +} |
diff --git a/internal/mapatest/sidebar_test.go b/internal/mapatest/sidebar_test.go| index 5a2ea5a..77fb212 100644 |
| --- a/internal/mapatest/sidebar_test.go |
| +++ b/internal/mapatest/sidebar_test.go |
| @@ -1,10 +1,14 @@ |
| package mapatest |
| import ( |
| + "context" |
| "net/http" |
| "net/url" |
| "strings" |
| "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/mapa/internal/mapa" |
| ) |
| // Pins are the viewer's own (level-up §3.2, §11 Q1 proposed): Bo's pin |
| @@ -51,3 +55,66 @@ func TestRecentlyEditedIsWhatYouWroteIn(t *testing.T) { |
| t.Fatal("Ana, who wrote nothing, has Recently edited") |
| } |
| } |
| + |
| +// Recently edited is yours only (review L2): what a teammate wrote, and |
| +// a teammate's later edit to a page you wrote, change nothing in it. |
| +func TestRecentlyEditedIsYoursOnly(t *testing.T) { |
| + rig := newRig(t) |
| + mine := rig.createPage(t, Bo, "Mine", "Bo's.") |
| + rig.createPage(t, Ana, "Theirs", "Ana's.") |
| + revision := revisionAs(t, rig, Ana, mine) |
| + rig.post(t, Ana, mine, url.Values{"revision": {revision}, |
| + "body": {"Ana was here."}}) |
| + recent := between(rig.page(t, Bo, "/pages"), "Recently edited", |
| + "</nav>") |
| + if strings.Contains(recent, "Theirs") || !strings.Contains(recent, |
| + "Mine") { |
| + t.Fatalf("Bo's Recently edited:\n%s", recent) |
| + } |
| + anas := between(rig.page(t, Ana, "/pages"), "Recently edited", |
| + "</nav>") |
| + if strings.Index(anas, "Mine") > strings.Index(anas, "Theirs") { |
| + t.Fatalf("Ana's edit to Mine is not her newest:\n%s", anas) |
| + } |
| +} |
| + |
| +// The sealed pins are one length however many pages are pinned (review |
| +// L11), so the file does not count them. |
| +func TestSealedPinsAreOneLength(t *testing.T) { |
| + rig := newRig(t) |
| + one := rig.createPage(t, Ana, "One", "1.") |
| + two := rig.createPage(t, Ana, "Two", "2.") |
| + rig.post(t, Ana, one+"/pin", url.Values{"pin": {"1"}}) |
| + rig.post(t, Bo, one+"/pin", url.Values{"pin": {"1"}}) |
| + rig.post(t, Bo, two+"/pin", url.Values{"pin": {"1"}}) |
| + var lengths []int |
| + err := rig.db.G.Raw("SELECT length(sealed_pins) FROM members " + |
| + "WHERE sealed_pins IS NOT NULL").Scan(&lengths).Error |
| + if err != nil || len(lengths) != 2 || lengths[0] != lengths[1] { |
| + t.Fatalf("sealed pins lengths %v (%v)", lengths, err) |
| + } |
| +} |
| + |
| +// The scoped accessor's own guard counts (review L1): asked by id for a |
| +// page outside the scope, it answers nothing, even when the caller's |
| +// list of ids was wrong. Without the guard this test fails. |
| +func TestTheScopedAccessorGuardsEveryRead(t *testing.T) { |
| + rig := newRig(t) |
| + rig.createPage(t, Bo, "Bo's", "So Bo is a member.") |
| + rig.post(t, Ana, "/scratch", url.Values{"body": {"Ana alone."}}) |
| + var private []int64 |
| + err := rig.db.G.Raw("SELECT id FROM pages WHERE rung = ?", |
| + "private").Scan(&private).Error |
| + if err != nil || len(private) != 1 { |
| + t.Fatalf("Ana's private page: %v (%v)", private, err) |
| + } |
| + ctx := context.Background() |
| + bo, err := rig.built.Store.Viewer(ctx, Bo, time.UTC) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := rig.built.Index.SideLinks(ctx, mapa.ScopeOf(bo), private, |
| + 0, ""); len(got) != 0 { |
| + t.Fatal("the accessor read a page outside its scope") |
| + } |
| +} |
diff --git a/scripts/mutate/mutations.go b/scripts/mutate/mutations.go| index d462fd5..39d4457 100644 |
| --- a/scripts/mutate/mutations.go |
| +++ b/scripts/mutate/mutations.go |
| @@ -36,6 +36,11 @@ var mutations = []mutation{ |
| to: "\tfor _, days := range view.index.days {\n" + |
| "\t\tif view.page(days[date]) != nil {\n" + |
| "\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}"}}}, |
| + {gate: "1", test: "TestTheScopedAccessorGuardsEveryRead", |
| + name: "the scoped accessor drops its own guard", |
| + edits: []edit{{file: around, |
| + from: "\tif page == nil || !view.scope.sees(page) {", |
| + to: "\tif page == nil {"}}}, |
| {gate: "1", test: gateOne, name: "search reads every person's postings", |
| edits: []edit{{file: rank, |
| from: "\tif own := index.ownTerms[scope.Member]; " + |