@ 261101.7

261029.4 · 00011b6688dc6372821c09b0a62727dbb8effcb3

A search's recent pages come only from the page's own tree

Recent pages crossed trees, so on the web address a search in one repo listed pages from repos read before. Each page's search box now names its tree, and each stored entry keeps the tree it was opened in. A version counts as its tree. Entries stored before this have no tree and are dropped.

reading declarations

Changes to search_test.go. All files

search_test.go

@@ -1,6 +1,7 @@ package main  import (+	"context" 	"encoding/json" 	"net/url" 	"os"@@ -59,6 +60,31 @@ func TestSearchBoxScope(t *testing.T) { 	} } +// Recent pages stay within their tree: each page names its tree for the+// script, a version names the tree it is a version of, and a tree at /+// names itself, not the trees whose paths lie below it.+func TestRecentsStayInTheirTree(t *testing.T) {+	s, dir := repoTree(t)+	tr := s.list()[0]+	tr.prefix, tr.label = "/notes/", "~/notes"+	other := t.TempDir()+	os.WriteFile(filepath.Join(other, "x.md"), []byte("# x\n"), 0o644)+	addTree(t, s, other, "/", "~")+	h := s.handler()+	star := stardatesIn(context.Background(), dir).byHash[head(t, dir, "HEAD~1")]+	for _, c := range []struct{ url, want string }{+		{"/notes/", "/notes/"},+		{"/notes/a/b.go", "/notes/"},+		{"/notes@" + star + "/a/b.go", "/notes/"},+		{"/x.md", "/"},+	} {+		w := get(h, c.url)+		if !strings.Contains(w.Body.String(), `data-recents="`+c.want+`"`) {+			t.Errorf("%s: want data-recents=%q, status %d", c.url, c.want, w.Code)+		}+	}+}+ // A directory's own entries come first and are marked here; deeper ones // follow unmarked. func TestSearchHereFirst(t *testing.T) {