Artifact 4c1a187f399b17ae74b53d6030739bcd350994f325ea6e504c5be45795cdc5a1:
- File
internal/index/counts_test.go
— part of check-in
[9b2b188ece]
at
2026-08-23 11:08:48
on branch trunk
— caps: private tickets exist for holders of e
The edge resolved a CapSet and threw it away; it now rides the context, so an op can ask which letters the caller holds. Private tickets list, count and resolve for e, and for nobody else. One privacyWhere() so a fourth read path cannot silently ship without the clause. (user: dmestas, size: 2851) [annotate] [blame] [check-ins using]
package index import ( "testing" "craftdesign.group/quarry/internal/artifact" ) func wikiEdit(hash, title, date string) Parsed { return Parsed{Hash: hash, Art: &artifact.Artifact{ Type: artifact.Wiki, Date: date, User: "dan", WikiTitle: title, Body: []byte("body"), }} } // Counts is memoized because it is read on every page render, which // makes staleness the thing to prove. A nav that says "wiki 3" after a // fourth page is saved is a small lie, and small lies about counts are // how a reader learns not to trust the rest of the page. func TestCountsRefreshAfterAFold(t *testing.T) { ix := openIndex(t) got, err := ix.Counts(false) if err != nil { t.Fatal(err) } if got.WikiPages != 0 { t.Fatalf("empty index reports %d wiki pages", got.WikiPages) } if err := ix.FoldNow([]Parsed{ wikiEdit("w1", "Home", "2026-01-01T00:00:00"), wikiEdit("w2", "Install", "2026-01-02T00:00:00"), }); err != nil { t.Fatal(err) } got, err = ix.Counts(false) if err != nil { t.Fatal(err) } if got.WikiPages != 2 { t.Fatalf("after fold: %d wiki pages, want 2 — the memo went stale", got.WikiPages) } // A second edit to an EXISTING page must not raise the page count: // the nav links to a list of pages, so it has to count pages. if err := ix.FoldNow([]Parsed{ wikiEdit("w3", "Home", "2026-01-03T00:00:00"), }); err != nil { t.Fatal(err) } got, _ = ix.Counts(false) if got.WikiPages != 2 { t.Fatalf("re-editing a page changed the count to %d, want 2", got.WikiPages) } // Reset is the reindex path; the memo must not survive it. if err := ix.Reset(); err != nil { t.Fatal(err) } got, err = ix.Counts(false) if err != nil { t.Fatal(err) } if got.WikiPages != 0 { t.Fatalf("after Reset: %d wiki pages, want 0 — the memo survived a reindex", got.WikiPages) } } // The forum count is THREADS, not posts, because that is what the forum // page lists. Counting posts would send a reader to a page showing // fewer rows than the nav promised. func TestForumCountIsThreadsNotPosts(t *testing.T) { ix := openIndex(t) root := "f1" if err := ix.FoldNow([]Parsed{ {Hash: root, Art: &artifact.Artifact{ Type: artifact.Forum, Date: "2026-01-01T00:00:00", User: "dan", ThreadTitle: "A thread", Body: []byte("hi"), }}, {Hash: "f2", Art: &artifact.Artifact{ Type: artifact.Forum, Date: "2026-01-02T00:00:00", User: "dan", InReplyTo: root, ThreadRoot: root, Body: []byte("reply"), }}, {Hash: "f3", Art: &artifact.Artifact{ Type: artifact.Forum, Date: "2026-01-03T00:00:00", User: "dan", InReplyTo: root, ThreadRoot: root, Body: []byte("reply"), }}, }); err != nil { t.Fatal(err) } got, err := ix.Counts(false) if err != nil { t.Fatal(err) } if got.ForumThreads != 1 { t.Fatalf("ForumThreads = %d for one thread with two replies, want 1", got.ForumThreads) } }