runner_step_output (pipeline, mover, step) reads the step from the state pipelines and asks the verb output of the build seat's holder on the node its step key names, by the step's ask, once per artifact the step ran for; a step that reads a shared run is answered by that run's ask. The runner keeps no output of its own: the objects step-outputs go, with the step's and the log entry's output and show's outputs; the runner seat's form rises to 4. The manifest invokes the three build seats' output. Builds: design 47 H2 §791; H-A-412 (1)
163 lines
8.3 KiB
Go
163 lines
8.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
|
)
|
|
|
|
// Design 47 H2 §778, H-A-395: every ask but a test run's is bounded from its put; its holder's ask-taken arms the bound again
|
|
// with what is left of it since taken-at, each step-progress from now, and the step's end deletes it. The bound passing ends
|
|
// the step could not run ("not answered" when taken, "not taken" naming the seat's holder when not), drops its ask through
|
|
// the seat's drop, raises the finding and ends the pipeline; a late ask-taken clears the finding. At a start an ask taken 9
|
|
// minutes before, with a 10-minute bound, has one minute left.
|
|
func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) {
|
|
for _, taken := range []bool{true, false} {
|
|
t.Run(fmt.Sprintf("taken %v", taken), func(t *testing.T) {
|
|
v, store, said, asks, _, _ := verbsFixture()
|
|
var armed, rearmed, unbound, raised, cleared, dropped []string
|
|
logs := []string{}
|
|
v.Hearer.Logf = func(f string, a ...any) { logs = append(logs, fmt.Sprintf(f, a...)) }
|
|
now := time.Date(2026, 11, 22, 2, 0, 0, 0, time.UTC)
|
|
v.Hearer.Now = func() time.Time { return now }
|
|
c := &AskClock{Bound: 10 * time.Minute,
|
|
Arm: func(key string, ttl time.Duration) error { armed = append(armed, key+" "+ttl.String()); return nil },
|
|
Rearm: func(key string, ttl time.Duration) error { rearmed = append(rearmed, key+" "+ttl.String()); return nil },
|
|
Unbound: func(key string) error { unbound = append(unbound, key); return nil },
|
|
Raise: func(s, ask string, _ time.Duration) error { raised = append(raised, s+" "+ask); return nil },
|
|
Clear: func(s, ask string) error { cleared = append(cleared, s+" "+ask); return nil }}
|
|
v.Starter.Asks, v.Hearer.Asks = c, c
|
|
v.Hearer.DropRun = func(onSeat, node, ask, why string) error {
|
|
dropped = append(dropped, onSeat+" "+node+" "+ask+" "+why)
|
|
return nil
|
|
}
|
|
// A test run's ask keeps §725's bounds; a nil clock arms none.
|
|
if err := c.arm(Asked{Seat: nodebuildgo.Seat, ID: "r1", Run: "run"}); err != nil || len(armed) != 0 {
|
|
t.Fatalf("a test run's ask armed %v (%v)", armed, err)
|
|
}
|
|
if err := (*AskClock)(nil).arm(Asked{Seat: nodebuildgo.Seat, ID: "x"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Every step but app:program's lint has ended; that lint failed, and its rerun's ask is armed before it is put.
|
|
p, rev, _ := store.Get(pkey)
|
|
for i := range p.Steps {
|
|
if open(p.Steps[i]) {
|
|
p.Steps[i].Outcome = seat.StepResultOutcomePassed
|
|
}
|
|
}
|
|
p.Steps[stepIndex(p, "lint", "app:program")].Outcome = seat.StepResultOutcomeFailed
|
|
store.Update(pkey, p, rev)
|
|
r, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ask, key := r.Result.Ask, AskBoundKey(nodebuildgo.Seat, r.Result.Ask)
|
|
if want := []string{key + " 10m0s"}; !slices.Equal(armed, want) || len(asks.ids) != 1 {
|
|
t.Fatalf("armed %v asking %v, want %v before one ask", armed, asks.ids, want)
|
|
}
|
|
if got, _, _ := store.Get(pkey); got.Steps[stepIndex(got, "lint", "app:program")].AskedAt == nil {
|
|
t.Fatal("the step keeps no asked-at")
|
|
}
|
|
if taken {
|
|
// Taken 9 minutes ago: one minute is left of its bound, at its ask-taken as at a start.
|
|
at, err := v.Hearer.Taken(ask, "n1", now.Add(-9*time.Minute))
|
|
if err != nil || at == nil || !at.Equal(now.Add(-9*time.Minute)) {
|
|
t.Fatalf("taken-at %v (%v)", at, err)
|
|
}
|
|
if err := c.Taken(nodebuildgo.Seat, ask, *at, now); err != nil || !slices.Equal(rearmed, []string{key + " 1m0s"}) {
|
|
t.Fatalf("re-armed %v (%v), want one minute left", rearmed, err)
|
|
}
|
|
open, err := v.OpenAsks()
|
|
if err != nil || len(open) != 1 || open[0].Ask != ask || !open[0].Since.Equal(*at) || c.Left(open[0].Since, now) != time.Minute {
|
|
t.Fatalf("open asks %+v (%v), want the ask since its taken-at", open, err)
|
|
}
|
|
if err := c.Progress(nodebuildgo.Seat, ask); err != nil || rearmed[1] != key+" 10m0s" {
|
|
t.Fatalf("a step-progress re-armed %v (%v), want the whole bound", rearmed, err)
|
|
}
|
|
}
|
|
// The bound passes: the step ends could not run and is dropped, the finding raised, the pipeline ended.
|
|
if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _, _ := store.Get(pkey)
|
|
s := got.Steps[stepIndex(got, "lint", "app:program")]
|
|
why, node := UntakenWhy(nodebuildgo.Seat), ""
|
|
if taken {
|
|
why, node = UnansweredWhy(ask), "n1"
|
|
}
|
|
if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != why || s.Ended == nil {
|
|
t.Errorf("the step = %+v, want could not run: %s", s, why)
|
|
}
|
|
if !taken && !strings.Contains(s.Why, "node-build-go's holder takes none") {
|
|
t.Errorf("an untaken ask's why %q names no holder that does not take", s.Why)
|
|
}
|
|
if !slices.Equal(dropped, []string{nodebuildgo.Seat + " " + node + " " + ask + " " + why}) {
|
|
t.Errorf("dropped %v, want the ask dropped through its seat", dropped)
|
|
}
|
|
// The end is one journal line, as every said end (H-A-320 (1), H-A-333).
|
|
if n := countLines(logs, "step ended "+pkey+" app lint could not run in "); n != 1 {
|
|
t.Errorf("the bound's end journaled %d times in %q, want once", n, logs)
|
|
}
|
|
if got.Outcome != seat.PipelineOutcomeFailed || len(asks.ids) != 1 {
|
|
t.Errorf("the pipeline is %s (%s), asked %d, want failed and nothing asked again", got.Outcome, got.Why, len(asks.ids))
|
|
}
|
|
if !slices.Equal(raised, []string{nodebuildgo.Seat + " " + ask}) || !slices.Contains(*said, "pipeline-ended.main.5") {
|
|
t.Errorf("raised %v, said %v", raised, *said)
|
|
}
|
|
// A bound whose step ended asks nothing; the step's end deletes the bound; a late ask-taken clears the finding.
|
|
if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil || len(asks.ids) != 1 || len(dropped) != 1 {
|
|
t.Errorf("a bound of an ended step asked %v, dropped %v (%v)", asks.ids, dropped, err)
|
|
}
|
|
if err := c.Ended(nodebuildgo.Seat, ask); err != nil || !slices.Equal(unbound, []string{key}) {
|
|
t.Errorf("the step's end deleted %v (%v)", unbound, err)
|
|
}
|
|
if _, err := v.Hearer.Taken(ask, "n2", now); err != nil || !slices.Equal(cleared, []string{nodebuildgo.Seat + " " + ask}) {
|
|
t.Errorf("a late ask-taken cleared %v (%v)", cleared, err)
|
|
}
|
|
})
|
|
}
|
|
if s, a, ok := ParseAskBound(AskBoundKey("mesh-wants", "a1")); !ok || s != "mesh-wants" || a != "a1" {
|
|
t.Errorf("ParseAskBound = %s %s %v", s, a, ok)
|
|
}
|
|
if _, _, ok := ParseAskBound(DropBoundKey("node-build-go", "a1")); ok {
|
|
t.Error("a drop's bound read as an ask's")
|
|
}
|
|
}
|
|
|
|
// H-A-252: the pipeline's one validate ask names no mover (H-A-51), and its holder's end names the mover whose body it took:
|
|
// it is matched by its ask alone and ends the validate step of every mover under it, whichever mover it names.
|
|
func TestAValidateEndNamingOneMoverEndsEveryMoversValidate(t *testing.T) {
|
|
h, store, _, _, _ := fixture()
|
|
p, rev, _ := store.Get(pkey)
|
|
p.Movers = []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, {Module: "lib", Commit: "c2", Fingerprint: "src2:bb"}}
|
|
p.Steps = []seat.StepResult{
|
|
{Module: "app", Step: seat.StepResultStepValidate, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "v1", Seat: wants.Seat},
|
|
{Module: "lib", Step: seat.StepResultStepValidate, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "v1", Seat: wants.Seat}}
|
|
store.Update(pkey, p, rev)
|
|
var bs StepSeat
|
|
for _, x := range StepSeats {
|
|
if x.Seat == wants.Seat {
|
|
bs = x
|
|
}
|
|
}
|
|
ev := StepEnded{ID: "v1", Node: "n1", Pipeline: pkey, Module: "lib", Commit: "c2", Fingerprint: "src2:bb", Step: seat.StepResultStepValidate, Outcome: "passed"}
|
|
if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", ev); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _, _ := store.Get(pkey)
|
|
for _, s := range got.Steps {
|
|
if s.Outcome != seat.StepResultOutcomePassed {
|
|
t.Errorf("%s's validate = %s, want passed by the one end", s.Module, s.Outcome)
|
|
}
|
|
}
|
|
if got.Outcome != seat.PipelineOutcomePassed {
|
|
t.Errorf("the pipeline = %s (%s), want passed", got.Outcome, got.Why)
|
|
}
|
|
}
|