Skip to content
quarry Artifact [7fc09cc511]
Login

Artifact [7fc09cc511]

Artifact 7fc09cc511cbc784ac6f9b23ba3f6ac6a726278327b58ea678d534bbf584a34e:


package index

import (
	"fmt"
	"strings"
	"testing"

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

// A timeline entry says whether any check-in names it as a parent: the
// fact a paged timeline needs to draw a branch merged above a chunk.
// The newest has no child; every check-in below it in a chain does.
func TestTimelineSaysWhetherACheckinHasAChild(t *testing.T) {
	ix := openIndex(t)
	var batch []Parsed
	for i := 0; i < 3; i++ {
		art := &artifact.Artifact{Type: artifact.Manifest, User: "dan",
			Date: fmt.Sprintf("2026-10-02T0%d:00:00", i), Comment: fmt.Sprintf("c%d", i)}
		if i > 0 {
			art.Parents = []string{strings.Repeat(fmt.Sprintf("%02d", i), 32)}
		}
		batch = append(batch, Parsed{Hash: strings.Repeat(fmt.Sprintf("%02d", i+1), 32), Art: art})
	}
	if err := ix.FoldNow(batch); err != nil {
		t.Fatal(err)
	}
	es, _, err := ix.Timeline(TimelineFilter{Kind: "ci", Limit: 10})
	if err != nil {
		t.Fatal(err)
	}
	got := map[string]bool{}
	for _, e := range es {
		got[e.Hash[:2]] = e.HasChild
	}
	if got["03"] || !got["02"] || !got["01"] {
		t.Fatalf("FAIL: hasChild %v; want the newest (03) without a child and 01, 02 with one", got)
	}
	t.Log("ok: hasChild follows the parent edges")
}