package api
import (
"reflect"
"testing"
"craftdesign.group/quarry/internal/oltp"
)
type deferredStub struct{ rows map[string]oltp.CIDeferred }
func (d deferredStub) CIDeferredFor(_, checkin string) (oltp.CIDeferred, bool, error) {
w, ok := d.rows[checkin]
return w, ok, nil
}
// A check-in waiting for a worker slot is a row on every checks list,
// and is not a verdict.
//
// Without the row a check-in the forge had deliberately not started
// showed nothing at all — the confident-nothing shape jva has caught
// three times. With it, a landing opened over the wait still asks for
// the run (withoutVerdict), which is the drain's other door.
func TestAWaitingCheckinIsARowAndNotAVerdict(t *testing.T) {
d := Deps{Deferred: deferredStub{rows: map[string]oltp.CIDeferred{
"c1": {Repo: "r", Checkin: "c1", Branch: "feat/x", Since: "2026-09-23T02:00:00Z"}}}}
got := d.checksOn("r", "c1", false)
if len(got) != 1 || got[0].Status != "deferred" || got[0].RunID != "" || got[0].Started != "2026-09-23T02:00:00Z" || got[0].Branch != "feat/x" {
t.Fatalf("FAIL: checks = %+v, want one waiting row with no run", got)
}
if got := d.checksOn("r", "c2", false); len(got) != 0 {
t.Errorf("FAIL: a check-in that is not waiting grew a row: %+v", got)
}
if got := d.checksOn("r", "c1", true); len(got) != 0 {
t.Errorf("FAIL: a premerge subject grew a waiting row: %+v", got)
}
if got := withoutVerdict([]string{"quarry"}, []CIRun{{Workflow: "quarry", Pipeline: "waiting for a worker slot", Status: "deferred"}}, nil); !reflect.DeepEqual(got, []string{"quarry"}) {
t.Errorf("FAIL: a waiting row counted as a verdict: missing = %v", got)
}
}