package index
import "testing"
// A ticket wants to know what proposed to fix it, and whether that
// proposal landed. The anchor index already holds every hex reference a
// post wrote; this asks it the question a ticket page asks.
func TestMentionsOfSeparatesLandingsFromThreads(t *testing.T) {
ix := openIndex(t)
target := "fc84aef2899b1111222233334444555566667777888899990000aaaabbbbcccc"
ref := target[:12]
// A landing whose MESSAGE names the ticket — the anchor comes from
// the body, which is where a person writes "Closes <hash>".
foldForumBody(t, ix, "1111aaaa", "", "Closes "+ref,
"2026-01-01T10:00:00", landingBody("fix-x", "trunk", "Closes "+ref))
// The merge is the fact and the reply is the claim (RFC 0007), so
// the DAG has to hold the merge before the fold reads "accepted".
foldMerge(t, ix, "tipfix-x", "fix-x", "2026-01-02T10:00:00", "work on fix-x")
foldMerge(t, ix, "mrgfix-x", "trunk", "2026-01-02T12:00:00",
"land fix-x", "prevtrunk", "tipfix-x")
foldForumBody(t, ix, "1111aaaaff", "1111aaaa", "",
"2026-01-03T10:00:00", landingState("accepted", "landed"))
// And a plain forum thread that mentions it too.
foldForumBody(t, ix, "2222bbbb", "", "Chatter",
"2026-01-02T00:00:00", "worth reading "+ref)
got, err := ix.MentionsOf(target)
if err != nil {
t.Fatal(err)
}
kinds := map[string]MentionRef{}
for _, m := range got {
kinds[m.Kind] = m
}
if _, ok := kinds["landing"]; !ok {
t.Fatalf("no landing among %d references: %+v", len(got), got)
}
if _, ok := kinds["forum"]; !ok {
t.Errorf("the plain thread was dropped: %+v", got)
}
// The state is the whole point: "a landing that references this has
// landed" is the answer, and a link that cannot say it is a link the
// reader must follow to learn anything.
if s := kinds["landing"].State; s != "accepted" {
t.Errorf("landing reference carries state %q, want accepted", s)
}
if b := kinds["landing"].Branch; b != "fix-x" {
t.Errorf("landing reference carries branch %q, want fix-x", b)
}
if kinds["forum"].State != "" {
t.Errorf("a plain thread was given a landing state: %q", kinds["forum"].State)
}
}
// The prefix gate: a stored reference surfaces only on the artifact
// whose hash it actually prefixes.
func TestMentionsOfHonoursThePrefix(t *testing.T) {
ix := openIndex(t)
target := "fc84aef2899b1111222233334444555566667777888899990000aaaabbbbcccc"
foldForumBody(t, ix, "3333cccc", "", "Closes "+target[:12],
"2026-01-01T10:00:00", landingBody("fix-y", "trunk", "Closes "+target[:12]))
if got, _ := ix.MentionsOf("decade00decade00decade00decade00decade00decade00decade00decade00"); len(got) != 0 {
t.Errorf("a reference surfaced on an unrelated hash: %+v", got)
}
}