Skip to content
quarry Artifact [32f2d015fe]
Login

Artifact [32f2d015fe]

Artifact 32f2d015fe977c0ffc0cd944862af1ded4bef68a4969f48a64ab9604cd91380b:


package api

import (
	"context"
	"strings"
	"testing"

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

// checkin.get lists the wiki pages that name the check-in, by bracketed
// hash and by /info link, and stops listing a page the moment an edit
// drops the reference.
func TestCheckinGetListsWikiPagesThatNameIt(t *testing.T) {
	ix := wikiIndex(t)
	h := "abcd" + strings.Repeat("ef", 30)
	page := func(hash, title, date, body string) index.Parsed {
		return index.Parsed{Hash: hash, Art: &artifact.Artifact{Type: artifact.Wiki, WikiTitle: title,
			Date: date, User: "dan", Mimetype: "text/x-markdown", Body: []byte(body)}}
	}
	if err := ix.FoldNow([]index.Parsed{
		{Hash: h, Art: &artifact.Artifact{Type: artifact.Manifest, Date: "2026-08-15T09:00:00", User: "dan", Comment: "c"}},
		page("r1", "Bare", "2026-08-15T10:00:00", "built in ["+h[:12]+"]"),
		page("r2", "Link", "2026-08-15T10:00:01", "built in [it](/info/"+h[:16]+")"),
		page("r3", "Gone", "2026-08-15T10:00:02", "["+h[:12]+"]"),
		page("r4", "Gone", "2026-08-15T10:00:03", "no longer"),
		page("r5", "Plain", "2026-08-15T10:00:04", "mentions "+h[:12]+" unbracketed"),
	}); err != nil {
		t.Fatal(err)
	}
	r := ops.NewRegistry()
	if err := RegisterAll(r, Deps{Version: "v", Repos: testRepos(ix)}); err != nil {
		t.Fatal(err)
	}
	got, err := r.Invoke(context.Background(), "checkin.get", checkinGetIn{Repo: "test", Hash: h[:12]})
	if err != nil {
		t.Fatal(err)
	}
	have := map[string]bool{}
	for _, ref := range got.(checkinGetOut).ReferencedBy {
		have[ref.Kind+":"+ref.Ref] = true
	}
	for _, want := range []string{"wiki:Bare", "wiki:Link"} {
		if !have[want] {
			t.Errorf("FAIL: %s is not listed: %v", want, have)
		}
	}
	for _, not := range []string{"wiki:Gone", "wiki:Plain"} {
		if have[not] {
			t.Errorf("FAIL: %s is listed: %v", not, have)
		}
	}
	if !t.Failed() {
		t.Log("ok")
	}
}