package api
import (
"context"
"testing"
"craftdesign.group/quarry/internal/artifact"
"craftdesign.group/quarry/internal/index"
"craftdesign.group/quarry/internal/ops"
)
// checkin.get says which landing a check-in belongs to: the field is
// absent for one no landing touched, and names the landing, its state
// and the role for one on a landing's branch.
func TestCheckinGetNamesItsLanding(t *testing.T) {
ix := landingIndex(t, "dan", "feat", "trunk", "")
tip := "cccc3333cccc3333cccc3333cccc3333"
plain := "dddd4444dddd4444dddd4444dddd4444"
manifest := func(h, date, comment, branch string) index.Parsed {
return index.Parsed{Hash: h, Art: &artifact.Artifact{Type: artifact.Manifest,
Date: date, User: "dan", Comment: comment,
Tags: []artifact.Tag{{Name: "*branch", Target: "*", Value: branch}}}}
}
if err := ix.FoldNow([]index.Parsed{
manifest(tip, "2026-01-02T00:00:00", "work", "feat"),
manifest(plain, "2026-01-02T01:00:00", "elsewhere", "trunk"),
}); err != nil {
t.Fatal(err)
}
r := ops.NewRegistry()
if err := RegisterAll(r, Deps{Version: "v", Repos: testRepos(ix)}); err != nil {
t.Fatal(err)
}
get := func(h string) checkinGetOut {
got, err := r.Invoke(context.Background(), "checkin.get", checkinGetIn{Repo: "test", Hash: h, Files: "0"})
if err != nil {
t.Fatal(err)
}
return got.(checkinGetOut)
}
if l := get(tip).Landing; l == nil || l.ID != landingHash || l.Role != "branch" || l.State != "open" {
t.Errorf("FAIL: branch check-in landing = %+v", l)
}
if l := get(plain).Landing; l != nil {
t.Errorf("FAIL: a check-in on the target names landing %+v", l)
}
}