Skip to content
quarry Artifact [ac5127c843]
Login

Artifact [ac5127c843]

Artifact ac5127c843467567d39b05e024a80af2984910b45498a52bdb8430ac25453f6b:


package index

import (
	"testing"

	"craftdesign.group/quarry/internal/artifact"
)

// A landing's message is split the way a commit message is: first line
// is the title. So a record whose whole statement is "Closes
// 2058808c3504." carries its only reference in the TITLE, and reading
// the body alone left every such landing invisible on the ticket it
// settled — which is exactly what production showed: 618 landing posts,
// 50 anchors, and tickets with no sign the work existed.
func TestAReferenceInTheTitleAnchorsToo(t *testing.T) {
	ix := openIndex(t)
	const full = "2058808c35049e2b7f1a4c6d8e0b3a5c7d9f1e2b4a6c8e0d2f4a6b8c0d2e4f60"
	if err := ix.FoldNow([]Parsed{{Hash: "aaaa1111", Art: &artifact.Artifact{
		Type: artifact.Forum, ThreadTitle: "Closes 2058808c3504.", Date: "2026-01-01T10:00:00",
		User: "dan", Body: []byte("zit-landing: 1\nbranch: x\ntarget: trunk\n\nNo hashes here.\n"),
	}}}); err != nil {
		t.Fatal(err)
	}
	got, err := ix.MentionsOf(full)
	if err != nil {
		t.Fatal(err)
	}
	if len(got) != 1 || got[0].Root != "aaaa1111" {
		t.Fatalf("FAIL: the ticket sees %d mentions, want the landing that closes it: %+v", len(got), got)
	}
}

// The body still anchors, and a reference in both places anchors once.
func TestTitleAndBodyAnchorsDoNotDuplicate(t *testing.T) {
	ix := openIndex(t)
	const full = "fc84aef2899b1d3e5f7a9c1b3d5e7f9a1c3b5d7e9f1a3c5b7d9e1f3a5c7b9d1e"
	if err := ix.FoldNow([]Parsed{{Hash: "bbbb2222", Art: &artifact.Artifact{
		Type: artifact.Forum, ThreadTitle: "Closes fc84aef2899b.", Date: "2026-01-01T10:00:00",
		User: "dan", Body: []byte("the fix for fc84aef2899b is here"),
	}}}); err != nil {
		t.Fatal(err)
	}
	got, err := ix.MentionsOf(full)
	if err != nil {
		t.Fatal(err)
	}
	if len(got) != 1 {
		t.Fatalf("FAIL: %d mentions for one reference named twice: %+v", len(got), got)
	}
}