Skip to content
quarry Artifact [f0fb0f6a99]
Login

Artifact [f0fb0f6a99]

Artifact f0fb0f6a997c0e5a538f025bd509cc919b7879cde554bec6d518df87d4d07c44:


package api

import (
	"errors"
	"strings"
	"testing"

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

// RE-RUN ASKS FOR WHAT ITS PAGE IS ABOUT.
//
// A short hash is resolved before the run is filed: filed under the
// prefix, a re-run never appeared on the check-in it tested (zeitforge,
// 2026-09-29). A landing's Re-run re-tests its merge with the target as
// it is now; a merge run's Re-run re-runs that exact pair.
func TestReRunAsksForWhatItsPageIsAbout(t *testing.T) {
	tip := strings.Repeat("ab", 20)
	ix := openLandingIndex(t, "feat", tip)
	var tipRuns []string
	var pairRuns [][3]string
	d := Deps{Repos: NewRepos(map[string]*Repo{"alpha": {Index: ix}}),
		CITrigger: func(_, checkin, _ string) error { tipRuns = append(tipRuns, checkin); return nil },
		CIRunPair: func(_, branch, b, tt string) error { pairRuns = append(pairRuns, [3]string{branch, b, tt}); return nil }}
	repo, _ := d.Repos.Get("alpha")
	trigger := func(in ciTriggerIn) error {
		in.Repo = "alpha"
		return d.ciTrigger(repo, in, "")
	}

	if err := trigger(ciTriggerIn{Checkin: tip[:12]}); err != nil || len(tipRuns) != 1 || tipRuns[0] != tip {
		t.Fatalf("FAIL: a short hash ran %v (%v), want the full hash %s", tipRuns, err, tip)
	}
	if err := trigger(ciTriggerIn{Checkin: "abcdef999999"}); !errors.Is(err, ops.ErrNotFound) {
		t.Fatalf("FAIL: a prefix naming nothing answered %v, want not found", err)
	}

	trunk, _ := ix.BranchTip("trunk")
	if err := trigger(ciTriggerIn{Landing: landingHash[:12]}); err != nil || len(pairRuns) != 1 ||
		pairRuns[0] != [3]string{"feat", tip, trunk} {
		t.Fatalf("FAIL: a landing's Re-run ran %v (%v), want feat's merge with trunk now", pairRuns, err)
	}

	b, tt := strings.Repeat("1", 64), strings.Repeat("2", 64)
	if err := trigger(ciTriggerIn{Checkin: "pair:" + b + ":" + tt}); err != nil || len(pairRuns) != 2 ||
		pairRuns[1] != [3]string{"", b, tt} {
		t.Fatalf("FAIL: a merge run's Re-run ran %v (%v), want that exact pair", pairRuns, err)
	}
	t.Log("ok: a prefix resolves, a landing re-tests its merge, a pair re-runs itself")
}