package api
import (
"testing"
"craftdesign.group/quarry/internal/index"
)
// A rung with no green run of the target's required checks waits, and
// the control still lands the whole stack: the press is one act, which
// lands it whole once the checks pass (landStack). Counting only the
// rungs below the wait offered "Land ×1" on a stack of two.
func TestAWaitingRungIsNamedAndTheStackStillLandsWhole(t *testing.T) {
st := func() *index.Strata {
return &index.Strata{Top: "c", Preflight: "lands", LandTo: "c", LandCount: 3, Segments: []index.StackSegment{
{ID: "a", Target: "trunk", State: "open", Position: 1},
{ID: "b", Target: "ba", State: "open", Position: 2},
{ID: "c", Target: "bb", State: "open", Position: 3},
}}
}
all := []index.LandingSummary{{ID: "a", Target: "trunk"}, {ID: "b", Target: "ba"}, {ID: "c", Target: "bb"}}
d := Deps{Checks: checksStub{required: []string{"quarry"}}, Repos: NewRepos(map[string]*Repo{})}
s := st()
d.strataChecks("test", all, s)
if s.WaitsAt != 1 || s.LandCount != 3 || s.LandTo != "c" || len(s.Segments[0].Waiting) != 1 {
t.Errorf("FAIL: a base with no green run read %+v", s)
}
// Nothing required: the probe's answer stands.
s = st()
Deps{Checks: checksStub{}}.strataChecks("test", all, s)
if s.WaitsAt != 0 || s.LandCount != 3 || s.LandTo != "c" {
t.Errorf("FAIL: with nothing required the stack read %+v", s)
}
// Not probed: lands whole until a rung waits.
s = st()
s.Preflight, s.LandTo, s.LandCount = "", "", 0
Deps{}.strataChecks("test", all, s)
if s.LandCount != 3 || s.LandTo != "c" {
t.Errorf("FAIL: an unprobed stack read %+v", s)
}
// A probe that stops at rung 2 is not overruled by checks above it.
s = st()
s.Preflight, s.StopsAt, s.LandTo, s.LandCount = "stops", 2, "a", 1
s.Segments[0].State = "accepted"
d.strataChecks("test", all, s)
if s.LandCount != 1 || s.WaitsAt != 0 {
t.Errorf("FAIL: checks above the stopping rung moved the walk: %+v", s)
}
}