oficina / mapa Public

The editor's data island, POST /links/resolve and the draft bar

Level-up §6.8. Every editable page (a team page, a daily note written
or not, a scratch page, New scratch page) carries
<script type="application/json" id="mapa-editor"> with {source, base,
draft: {version, base} | null, links: {key: {kind, href, title}}},
written by encoding/json so no body can end the element. Revisions and
versions are text: they are int63s.

A person with a draft is shown the draft's text as the page body, under
the bar "Unsaved changes from <ago>. You're seeing your unsaved
version." with Save, Discard and Show the saved version (?saved=1, the
committed text, with no island).

POST /links/resolve answers up to 32 link keys' chip states, through
the scoped accessor's new linkState, and writes nothing; gate 8 drives
it as view-only. Gate 1 and the history scope test compare the island's
random revisions as one value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d792d32b864fb6a4a7ccec77e43c5491f15d246a parent f5b54b5
14 files changed, +295 −22
  • internal/mapa/around.go +36 −0
  • internal/mapa/handlers_pages.go +6 −5
  • internal/mapa/handlers_search.go +1 −0
  • internal/mapa/island.go +190 −0
  • internal/mapa/private.go +11 −1
  • internal/mapa/templates/day.html +2 −2
  • internal/mapa/templates/page.html +2 −2
  • internal/mapa/templates/partials.html +12 −3
  • internal/mapa/templates/scratch_new.html +1 −0
  • internal/mapa/today.go +9 −0
  • internal/mapatest/drafts_test.go +5 −5
  • internal/mapatest/gate1_test.go +13 −2
  • internal/mapatest/gate8_test.go +3 −0
  • internal/mapatest/history_panel_test.go +4 −2
diff --git a/internal/mapa/around.go b/internal/mapa/around.go
index c35d781..e15cae9 100644
--- a/internal/mapa/around.go
+++ b/internal/mapa/around.go
@@ -186,3 +186,39 @@ func (view scoped) around(page *entry, backlinks,
ring := view.mapNeighbours(page, backlinks, mentions)
return &Around{Out: view.linksOut(page), Map: view.mapOf(page, ring)}
}
+
+// LinkState is one chip's state for the editor (level-up §6.8): its
+// kind (team, pending, date, block, "block gone" or broken), where it
+// leads, and the current title of the team page it names, or the day
+// in words.
+type LinkState struct {
+ Kind string `json:"kind"`
+ Href string `json:"href"`
+ Title string `json:"title"`
+}
+
+// linkState is where a [[link]] leads for this scope, as a chip draws
+// it. Like target, it reads team titles and the scope's own days only.
+func (view scoped) linkState(target, anchor string) LinkState {
+ if markup.IsDateShaped(target) {
+ if !markup.IsDate(target) {
+ return LinkState{Kind: "broken"}
+ }
+ return LinkState{Kind: "date", Href: "/d/" + target,
+ Title: markup.DayLabel(target, thisYear())}
+ }
+ page := view.target(target)
+ if page == nil {
+ return LinkState{Kind: "pending", Href: pendingHref(target)}
+ }
+ state := LinkState{Kind: "team", Href: page.href(),
+ Title: page.record.Title}
+ switch {
+ case anchor == "":
+ case page.hasMarker(anchor):
+ state.Kind, state.Href = "block", state.Href+"#b-"+anchor
+ default:
+ state.Kind = "block gone"
+ }
+ return state
+}
diff --git a/internal/mapa/handlers_pages.go b/internal/mapa/handlers_pages.go
index 18facc2..9586b36 100644
--- a/internal/mapa/handlers_pages.go
+++ b/internal/mapa/handlers_pages.go
@@ -2,6 +2,7 @@ package mapa
import (
"errors"
+ "html/template"
"net/http"
"strconv"
@@ -82,12 +83,10 @@ func (app *app) showPage(writer http.ResponseWriter,
app.fail(writer, request, err)
return
}
- data := map[string]any{"Page": page, "Notice": notice(request)}
- draft, found, err := app.store.OwnDraft(request.Context(), viewer,
+ state, err := app.editorFor(request, viewer, &page,
DraftKey{PageID: page.ID})
- if found {
- data["Draft"] = draft
- }
+ data := map[string]any{"Page": page, "Notice": notice(request),
+ "Draft": state.Draft, "Saved": state.Saved, "Island": state.Island}
editing, editErr := app.store.Editing(request.Context(), viewer, page.ID)
if err = errors.Join(err, editErr); err != nil {
app.fail(writer, request, err)
@@ -126,6 +125,8 @@ type pageForm struct {
// this editor holds; empty for a page that does not exist yet.
Drafts string
Version int64
+ // Island is the editor's data (level-up §6.8), on New scratch page.
+ Island template.JS
}
func (app *app) newPage(writer http.ResponseWriter, request *http.Request) {
diff --git a/internal/mapa/handlers_search.go b/internal/mapa/handlers_search.go
index fdebf16..90f7160 100644
--- a/internal/mapa/handlers_search.go
+++ b/internal/mapa/handlers_search.go
@@ -23,6 +23,7 @@ func (app *app) searchRoutes(router chi.Router) {
router.Get("/search", app.searchPage)
router.Get("/search/suggest", app.searchSuggest)
router.Get("/links/suggest", app.linkSuggest)
+ router.Post("/links/resolve", app.resolveLinks)
}
func (app *app) searchPage(writer http.ResponseWriter,
diff --git a/internal/mapa/island.go b/internal/mapa/island.go
new file mode 100644
index 0000000..391285f
--- /dev/null
+++ b/internal/mapa/island.go
@@ -0,0 +1,190 @@
+package mapa
+
+import (
+ "context"
+ "encoding/json"
+ "html/template"
+ "net/http"
+ "strings"
+
+ "amadan.net/oficina/mapa/internal/mapa/markup"
+)
+
+// What the editor is given (level-up §6.8). Every editable page carries
+// a JSON island, <script type="application/json" id="mapa-editor">,
+// holding the source the editor mounts over, the page's current
+// revision, the person's draft if they have one, and each link's chip
+// state under the viewer's scope. Chips typed after mount ask
+// POST /links/resolve. Both read through the scoped accessor
+// (around.go) and write nothing.
+
+// maxResolve is how many link targets one /links/resolve may ask for.
+const maxResolve = 32
+
+// island is the editor's data, as JSON. Revisions and versions are
+// int63s, past what a JavaScript number holds, so they are text.
+type island struct {
+ Source string `json:"source"`
+ Base string `json:"base"`
+ Draft *islandDraft `json:"draft"`
+ Links map[string]LinkState `json:"links"`
+}
+
+type islandDraft struct {
+ Version string `json:"version"`
+ Base string `json:"base"`
+}
+
+// linkKey is how a link is named in the island and in /links/resolve:
+// its target as typed, with "#^id" when it names a block.
+func linkKey(target, anchor string) string {
+ if anchor == "" {
+ return target
+ }
+ return target + "#^" + anchor
+}
+
+// splitKey reads a link key back, by the parser's own rule for what
+// sits between [[ and ]] (markup's wikiSpan): "|" ends the target, "#^"
+// starts the anchor, and the target is trimmed.
+func splitKey(key string) (string, string, bool) {
+ target, _, _ := strings.Cut(key, "|")
+ target, anchor, _ := strings.Cut(target, "#")
+ target = strings.TrimSpace(target)
+ if !strings.HasPrefix(anchor, "^") {
+ anchor = ""
+ } else {
+ anchor = strings.TrimSpace(anchor[1:])
+ }
+ return target, anchor, target != ""
+}
+
+// LinkStates is each key's chip state for scope.
+func (index *Index) LinkStates(ctx context.Context, scope Scope,
+ keys []string) (map[string]LinkState, error) {
+ if err := index.Sync(ctx); err != nil {
+ return nil, err
+ }
+ index.mutex.RLock()
+ defer index.mutex.RUnlock()
+ view := index.in(scope)
+ out := make(map[string]LinkState, len(keys))
+ for _, key := range keys {
+ if target, anchor, ok := splitKey(key); ok {
+ out[key] = view.linkState(target, anchor)
+ }
+ }
+ return out, nil
+}
+
+// islandFor is the island for a page the viewer may edit: source is the
+// text the page shows (the draft's, when there is one), revision the
+// page's current one (0 for a page or day not written yet).
+func (app *app) islandFor(ctx context.Context, viewer Viewer,
+ source string, revision int64, draft *DraftView) (template.JS, error) {
+ var keys []string
+ for _, link := range markup.Links(source) {
+ keys = append(keys, linkKey(link.Target, link.Anchor))
+ }
+ links, err := app.index.LinkStates(ctx, ScopeOf(viewer), keys)
+ if err != nil {
+ return "", err
+ }
+ data := island{Source: source, Base: idText(revision), Links: links}
+ if draft != nil {
+ data.Draft = &islandDraft{Version: idText(draft.Version),
+ Base: idText(draft.BaseRevision)}
+ }
+ // encoding/json escapes <, >, & and U+2028/9, so no body can end
+ // the script element early or open a comment in it.
+ encoded, err := json.Marshal(data)
+ return template.JS(encoded), err
+}
+
+// resolveLinks is POST /links/resolve: up to maxResolve link keys in
+// the body, as "target" fields, answered as {key: {kind, href, title}}.
+// A POST so the targets travel in the body, not a URL that logs keep;
+// it writes nothing, like /preview.
+func (app *app) resolveLinks(writer http.ResponseWriter,
+ request *http.Request) {
+ viewer, err := app.viewer(request)
+ if err == nil {
+ err = request.ParseForm()
+ }
+ if err != nil {
+ app.fail(writer, request, err)
+ return
+ }
+ keys := request.PostForm["target"]
+ if len(keys) > maxResolve {
+ refuseJSON(writer, http.StatusUnprocessableEntity, "too many")
+ return
+ }
+ states, err := app.index.LinkStates(request.Context(), ScopeOf(viewer),
+ keys)
+ if err != nil {
+ app.fail(writer, request, err)
+ return
+ }
+ answer(writer, states)
+}
+
+// editorState is what an editable page shows of the person's draft,
+// and its island.
+type editorState struct {
+ Draft *DraftView
+ // Saved is ?saved=1: the committed text, the draft still offered.
+ Saved bool
+ Island template.JS
+}
+
+// editorFor is a page's editor state for the viewer. A person with a
+// draft is shown the draft's text as the page body, so the editor
+// mounts over the markup it will edit (level-up §6.8); ?saved=1 shows
+// the committed text instead, and carries no island, since it is not
+// the text the draft continues.
+func (app *app) editorFor(request *http.Request, viewer Viewer,
+ page *PageView, key DraftKey) (editorState, error) {
+ ctx := request.Context()
+ state := editorState{Saved: request.URL.Query().Get("saved") == "1"}
+ draft, found, err := app.store.OwnDraft(ctx, viewer, key)
+ if err != nil || (found && state.Saved) {
+ state.Draft = pointerIf(found, draft)
+ return state, err
+ }
+ if found {
+ state.Draft = &draft
+ page.Body = draft.Body
+ page.HTML, err = app.index.Preview(ctx, ScopeOf(viewer), draft.Body)
+ if err != nil {
+ return state, err
+ }
+ }
+ state.Island, err = app.islandFor(ctx, viewer, page.Body,
+ page.Revision, state.Draft)
+ return state, err
+}
+
+func pointerIf(found bool, draft DraftView) *DraftView {
+ if !found {
+ return nil
+ }
+ return &draft
+}
+
+// dayEditor is editorFor for a day: its note's, or an unwritten day's.
+// A day re-shown after a refused POST carries no island: its editor is
+// the textarea's, holding that tab's text.
+func (app *app) dayEditor(request *http.Request, viewer Viewer,
+ data *dayData) error {
+ if request.Method != http.MethodGet {
+ return nil
+ }
+ key := DraftKey{Date: data.Page.Date}
+ if data.Written {
+ key = DraftKey{PageID: data.Page.ID}
+ }
+ state, err := app.editorFor(request, viewer, &data.Page, key)
+ data.Saved, data.Island = state.Saved, state.Island
+ return err
+}
diff --git a/internal/mapa/private.go b/internal/mapa/private.go
index bfc63ba..00316fd 100644
--- a/internal/mapa/private.go
+++ b/internal/mapa/private.go
@@ -2,6 +2,7 @@ package mapa
import (
"errors"
+ "html/template"
"net/http"
"strconv"
@@ -41,9 +42,18 @@ func (app *app) listScratch(writer http.ResponseWriter,
func (app *app) newScratch(writer http.ResponseWriter,
request *http.Request) {
+ viewer, err := app.viewer(request)
+ var island template.JS
+ if err == nil {
+ island, err = app.islandFor(request.Context(), viewer, "", 0, nil)
+ }
+ if err != nil {
+ app.fail(writer, request, err)
+ return
+ }
app.showForm(writer, request, http.StatusOK, "scratch_new",
pageForm{Action: "/scratch", Label: "New scratch page",
- Page: PageView{Kind: KindScratch}})
+ Page: PageView{Kind: KindScratch}, Island: island})
}
func (app *app) createScratch(writer http.ResponseWriter,
diff --git a/internal/mapa/templates/day.html b/internal/mapa/templates/day.html
index 982c479..429ca0e 100644
--- a/internal/mapa/templates/day.html
+++ b/internal/mapa/templates/day.html
@@ -1,8 +1,8 @@
{{define "content"}}{{$d := .Data}}{{$page := $d.Page}}
{{template "mapa-doc-head" dict "Page" $page "Edit" (or (and $d.Written (not $d.Editing) (printf "/d/%s/edit" $page.Date)) "") "Day" $d.Pill}}
{{template "notice" $d.Notice}}
-{{with $d.Draft}}{{template "mapa-unsaved" dict "Draft" . "Save" (printf "/d/%s/draft/save" $page.Date) "Discard" (printf "/d/%s/draft/discard" $page.Date)}}{{end}}
-{{range $d.Orphans}}<div mapa-unsaved role="status"><p><strong>You have unsaved changes to a page that was deleted.</strong></p><form method="post" action="/p/{{.Public}}/draft/scratch"><button rst-btn="primary" type="submit">Save as a scratch page</button></form><form method="post" action="/p/{{.Public}}/draft/discard"><input type="hidden" name="version" value="{{.Version}}"><button rst-btn type="submit">Discard</button></form></div>{{end}}
+{{with $d.Draft}}{{template "mapa-unsaved" dict "Draft" . "Save" (printf "/d/%s/draft/save" $page.Date) "Discard" (printf "/d/%s/draft/discard" $page.Date) "Href" (or (and $d.Written (not $d.Editing) $page.Href) "") "Saved" $d.Saved}}{{end}}
+{{template "mapa-island" $d.Island}}{{range $d.Orphans}}<div mapa-unsaved role="status"><p><strong>You have unsaved changes to a page that was deleted.</strong></p><form method="post" action="/p/{{.Public}}/draft/scratch"><button rst-btn="primary" type="submit">Save as a scratch page</button></form><form method="post" action="/p/{{.Public}}/draft/discard"><input type="hidden" name="version" value="{{.Version}}"><button rst-btn type="submit">Discard</button></form></div>{{end}}
{{range $d.Elsewhere}}<p mapa-unsaved role="status"><span><strong>You have unsaved changes</strong> on another page.</span> <a rst-btn href="/p/{{.Public}}">Open it</a></p>{{end}}
{{if $d.Editing}}
<form rst-form method="post" action="/d/{{$page.Date}}" mapa-edit-form data-drafts="{{$d.Drafts}}" data-version="{{$d.Version}}">
diff --git a/internal/mapa/templates/page.html b/internal/mapa/templates/page.html
index 6a5b5a1..83b910d 100644
--- a/internal/mapa/templates/page.html
+++ b/internal/mapa/templates/page.html
@@ -1,8 +1,8 @@
{{define "content"}}{{$d := .Data}}{{$page := $d.Page}}
{{template "mapa-doc-head" dict "Page" $page "Last" $d.Last "Edit" (printf "%s/edit" $page.Href)}}
{{template "notice" $d.Notice}}
-{{with $d.Draft}}{{template "mapa-unsaved" dict "Draft" . "Save" (printf "/p/%s/draft/save" $page.Public) "Discard" (printf "/p/%s/draft/discard" $page.Public)}}{{end}}
-<article mapa-body>
+{{with $d.Draft}}{{template "mapa-unsaved" dict "Draft" . "Save" (printf "/p/%s/draft/save" $page.Public) "Discard" (printf "/p/%s/draft/discard" $page.Public) "Href" $page.Href "Saved" $d.Saved}}{{end}}
+{{template "mapa-island" $d.Island}}<article mapa-body>
{{if $page.Body}}{{$page.HTML}}{{else}}<p mapa-empty>This page is empty. <a href="{{$page.Href}}/edit">Write something</a>.</p>{{end}}
</article>
<footer mapa-foot-refs>
diff --git a/internal/mapa/templates/partials.html b/internal/mapa/templates/partials.html
index 0b83c73..65cf98c 100644
--- a/internal/mapa/templates/partials.html
+++ b/internal/mapa/templates/partials.html
@@ -27,16 +27,25 @@
</div>
{{end}}
-{{/* mapa-unsaved: the offer of a draft a closed tab left (§5). Keys:
- Draft (DraftView), Save, Discard (form actions). */}}
+{{/* mapa-unsaved: the draft bar (§5, level-up §6.8). The page shows
+ the person's unsaved text, or with Saved (?saved=1) the committed
+ text. Keys: Draft (DraftView), Save, Discard (form actions), Href
+ (the page, for "Show the saved version"; "" where nothing is saved
+ yet), Saved. */}}
{{define "mapa-unsaved"}}
<div mapa-unsaved role="status">
-<p><strong>You have unsaved changes</strong> from <time datetime="{{.Draft.Updated.Format "2006-01-02T15:04:05Z07:00"}}" title="{{.Draft.Updated.Format "2 January 2006 15:04"}}">{{ago .Draft.Updated}}</time>.</p>
+<p><strong>Unsaved changes</strong> from <time datetime="{{.Draft.Updated.Format "2006-01-02T15:04:05Z07:00"}}" title="{{.Draft.Updated.Format "2 January 2006 15:04"}}">{{ago .Draft.Updated}}</time>. {{if .Saved}}You're seeing the saved version.{{else}}You're seeing your unsaved version.{{end}}</p>
<form method="post" action="{{.Save}}"><input type="hidden" name="version" value="{{.Draft.Version}}"><button rst-btn="primary" type="submit">Save</button></form>
<form method="post" action="{{.Discard}}"><input type="hidden" name="version" value="{{.Draft.Version}}"><button rst-btn type="submit">Discard</button></form>
+{{with .Href}}{{if $.Saved}}<a rst-btn href="{{.}}">Show your unsaved version</a>{{else}}<a rst-btn href="{{.}}?saved=1">Show the saved version</a>{{end}}{{end}}
</div>
{{end}}
+{{/* mapa-island: the editor's data (level-up §6.8), JSON written by
+ encoding/json, which escapes <, >, & and U+2028/9. */}}
+{{define "mapa-island"}}{{with .}}<script type="application/json" id="mapa-editor">{{.}}</script>
+{{end}}{{end}}
+
{{/* mapa-editing: "Ana is editing", team pages only (§5). */}}
{{define "mapa-editing"}}{{with .}}<p mapa-meta mapa-editing>{{range $i, $who := .}}{{if $i}}, {{end}}{{$who}}{{end}} {{if eq (len .) 1}}is{{else}}are{{end}} editing this page.</p>{{end}}{{end}}
diff --git a/internal/mapa/templates/scratch_new.html b/internal/mapa/templates/scratch_new.html
index 925172e..64d0625 100644
--- a/internal/mapa/templates/scratch_new.html
+++ b/internal/mapa/templates/scratch_new.html
@@ -1,6 +1,7 @@
{{define "content"}}
{{template "back-nav" dict "Href" "/scratch" "Label" "Scratch"}}
{{template "page-header" dict "Title" "New scratch page" "Sub" "Only you can open it. It is saved when you save it, and not before."}}
+{{template "mapa-island" .Data.Island}}
<form rst-form method="post" action="{{.Data.Action}}" mapa-edit-form>
{{template "mapa-editor" dict "Body" .Data.Body "Error" .Data.Error}}
{{template "form-foot" dict "Submit" "Save" "CancelHref" "/scratch" "CancelLabel" "Cancel"}}
diff --git a/internal/mapa/today.go b/internal/mapa/today.go
index bc825ee..a009e5b 100644
--- a/internal/mapa/today.go
+++ b/internal/mapa/today.go
@@ -2,6 +2,7 @@ package mapa
import (
"errors"
+ "html/template"
"net/http"
"strconv"
"strings"
@@ -81,6 +82,10 @@ type dayData struct {
// strip, and ‹ Today › with its month.
Week *WeekView
Pill *dayPill
+ // Saved is ?saved=1, the committed text with the draft still
+ // offered; Island is the editor's data (level-up §6.8).
+ Saved bool
+ Island template.JS
}
// dayCalendar fills in the week strip and the month calendar, both read
@@ -128,6 +133,10 @@ func (app *app) showDay(writer http.ResponseWriter, request *http.Request,
app.fail(writer, request, err)
return
}
+ if err := app.dayEditor(request, viewer, &data); err != nil {
+ app.fail(writer, request, err)
+ return
+ }
if request.Method == http.MethodPost {
data.Body = request.PostFormValue("body")
}
diff --git a/internal/mapatest/drafts_test.go b/internal/mapatest/drafts_test.go
index 8e26b95..aa93602 100644
--- a/internal/mapatest/drafts_test.go
+++ b/internal/mapatest/drafts_test.go
@@ -59,12 +59,12 @@ func TestGate11AClosedTabsDraftIsOfferedAsSaveOrDiscard(t *testing.T) {
acme := rig.createPage(t, Ana, "Acme", "Committed.")
rig.autosave(t, Ana, acme, revisionOf(t, rig, acme), "0", "Left open.")
offer := rig.page(t, Ana, acme)
- if !strings.Contains(offer, "You have unsaved changes") ||
+ if !strings.Contains(offer, "Unsaved changes</strong> from") ||
!strings.Contains(offer, `action="`+acme+`/draft/save"`) ||
!strings.Contains(offer, `action="`+acme+`/draft/discard"`) {
t.Fatal("the draft is not offered as Save or Discard")
}
- if strings.Contains(rig.page(t, Bo, acme), "You have unsaved changes") {
+ if strings.Contains(rig.page(t, Bo, acme), "Unsaved changes</strong>") {
t.Fatal("Ana's draft is offered to Bo")
}
if rig.post(t, Ana, acme+"/draft/save", nil).Code != http.StatusSeeOther {
@@ -171,11 +171,11 @@ func TestGate11DraftsAreDiscarded30DaysAfterTheirLastWrite(t *testing.T) {
acme := rig.createPage(t, Ana, "Acme", "Text.")
rig.autosave(t, Ana, acme, revisionOf(t, rig, acme), "0", "Old draft.")
moving.now = moving.now.Add(29 * 24 * time.Hour)
- if !strings.Contains(rig.page(t, Ana, acme), "unsaved changes") {
+ if !strings.Contains(rig.page(t, Ana, acme), "Unsaved changes</strong>") {
t.Fatal("a 29-day-old draft is gone")
}
moving.now = moving.now.Add(2 * 24 * time.Hour)
- if strings.Contains(rig.page(t, Ana, acme), "unsaved changes") {
+ if strings.Contains(rig.page(t, Ana, acme), "Unsaved changes</strong>") {
t.Fatal("a 31-day-old draft is still offered")
}
rig.built.Store.Sweep(context.Background())
@@ -251,7 +251,7 @@ func TestGate11AStaleFirstSaveOfADayKeepsTheNewerDraft(t *testing.T) {
laptop.Header().Get("Location"))
}
offer := rig.page(t, Ana, day)
- if !strings.Contains(offer, "You have unsaved changes") ||
+ if !strings.Contains(offer, "Unsaved changes</strong> from") ||
!strings.Contains(offer, phone["version"].(string)) {
t.Fatal("the phone's draft is not offered on the note")
}
diff --git a/internal/mapatest/gate1_test.go b/internal/mapatest/gate1_test.go
index 0d1cad1..27c2108 100644
--- a/internal/mapatest/gate1_test.go
+++ b/internal/mapatest/gate1_test.go
@@ -2,6 +2,7 @@ package mapatest
import (
"net/url"
+ "regexp"
"strings"
"testing"
"time"
@@ -130,9 +131,10 @@ func TestGate1ScopeLeaksNothing(t *testing.T) {
}
without, with := boSees(t, quiet, acme), boSees(t, busy, acme)
for key, want := range without {
- if with[key] != want {
+ want, got := steadyRevisions(want), steadyRevisions(with[key])
+ if got != want {
t.Errorf("Bo's %s differs when Ana's private notes hold "+
- "the term:\n%s", key, firstDifference(want, with[key]))
+ "the term:\n%s", key, firstDifference(want, got))
}
}
if !strings.Contains(without["/search?q=zebracorn"], "Notes") {
@@ -157,6 +159,15 @@ func TestGate1AnaSeesHerOwn(t *testing.T) {
}
}
+// islandRevision is a revision in the editor's island. Revisions are
+// random in both worlds (doctrine §6.6), so they say nothing about
+// Ana's notes and are compared as one value.
+var islandRevision = regexp.MustCompile(`"(base|version)":"[0-9]+"`)
+
+func steadyRevisions(page string) string {
+ return islandRevision.ReplaceAllString(page, `"$1":"R"`)
+}
+
func firstDifference(want, got string) string {
for at := range min(len(want), len(got)) {
if want[at] != got[at] {
diff --git a/internal/mapatest/gate8_test.go b/internal/mapatest/gate8_test.go
index 0d3016b..56b1291 100644
--- a/internal/mapatest/gate8_test.go
+++ b/internal/mapatest/gate8_test.go
@@ -120,6 +120,9 @@ func gate8Steps(t *testing.T, world *rig) []step {
posting("/d/{date}", Ana, day, url.Values{"body": {"Saved day."},
"revision": {"0"}}),
posting("/preview", Ana, "/preview", url.Values{"body": {"x"}}),
+ // The editor's chip states: JSON, written nowhere (level-up §6.8).
+ posting("/links/resolve", Ana, "/links/resolve",
+ url.Values{"target": {"Acme", "2026-11-12", "Nothing yet"}}),
posting("/scratch", Ana, "/scratch", url.Values{"body": {"Mine."}}),
posting("/settings", Ana, "/settings",
url.Values{"zone": {"Europe/Madrid"}}),
diff --git a/internal/mapatest/history_panel_test.go b/internal/mapatest/history_panel_test.go
index 2f32a64..f0bee65 100644
--- a/internal/mapatest/history_panel_test.go
+++ b/internal/mapatest/history_panel_test.go
@@ -202,8 +202,10 @@ func TestHistoryKeepsScope(t *testing.T) {
revisions := regexp.MustCompile(`/history/[0-9]+`)
for _, path := range []string{acme + "/history",
acme + "/history?panel=1"} {
- without := revisions.ReplaceAllString(quiet.page(t, Bo, path), "")
- with := revisions.ReplaceAllString(busy.page(t, Bo, path), "")
+ without := steadyRevisions(revisions.ReplaceAllString(
+ quiet.page(t, Bo, path), ""))
+ with := steadyRevisions(revisions.ReplaceAllString(
+ busy.page(t, Bo, path), ""))
if without != with {
t.Errorf("Bo's %s differs:\n%s", path,
firstDifference(without, with))