package index
import (
"strings"
"testing"
"craftdesign.group/quarry/internal/artifact"
)
// A tag records who wrote it.
//
// checkin_tag held src, date, name, sign and value and no author, so
// the forge could say a branch was closed and not say by whom. The
// person refused was their own owner, told only "cannot commit against
// a closed leaf" -- which names neither the cause nor the actor -- and
// the recovery is a raw tag cancel that appears in no UI (ad732c8f).
//
// Read back through TagHistory rather than off the row, because the
// history is what every surface renders.
func TestATagRecordsWhoWroteIt(t *testing.T) {
ix := openIndex(t)
checkin := strings.Repeat("ab", 32)
if err := ix.FoldNow([]Parsed{
{Hash: checkin, Art: &artifact.Artifact{Type: artifact.Manifest,
Date: "2026-09-18T09:00:00", User: "jva", Comment: "work"}},
// A control artifact closing that leaf, written by somebody else.
{Hash: "ctl-close", Art: &artifact.Artifact{Type: artifact.Control,
Date: "2026-09-18T10:00:00", User: "jan",
Tags: []artifact.Tag{{Name: "+closed", Target: checkin, Value: ""}}}},
}); err != nil {
t.Fatal(err)
}
events, err := ix.TagHistory(checkin)
if err != nil {
t.Fatal(err)
}
var closed *TagEvent
for i := range events {
if events[i].Name == "closed" {
closed = &events[i]
}
}
if closed == nil {
t.Fatalf("no closed tag in the history: %+v", events)
}
if closed.User != "jan" {
t.Errorf("closed tag author = %q, want jan: the forge cannot say who closed "+
"the branch, which is the half of the incident that cost an evening", closed.User)
}
if closed.Date == "" {
t.Error("the closed tag has no date, so the forge cannot say when either")
}
}