Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go
T
jschoubben 19f06be6c1 Runner's list: each row names its branch, every branch's when none is named
The pipelines page lists every watched branch's pipelines together, the
branch a column of each row, so the short row carries the pipeline's branch;
list already answered every branch when none was named, and its description
now says so. The seat mesh-pipeline-runner's form rises to 11 for the field.

Builds: design 47 H2 H-A-533 (hq 1b1e1984)
2026-11-23 11:09:42 +01:00

378 lines
20 KiB
Go

package pipeline
import (
"encoding/json"
"errors"
"fmt"
"strings"
"testing"
"time"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
)
type memKept map[string]json.RawMessage
func (m memKept) Keys() ([]string, error) {
var out []string
for k := range m {
out = append(out, k)
}
return out, nil
}
func (m memKept) Value(key string) (json.RawMessage, error) { return m[key], nil }
func put(t *testing.T, m memKept, key string, v any) {
t.Helper()
raw, err := json.Marshal(v)
if err != nil {
t.Fatal(err)
}
m[key] = raw
}
// TestReads holds the runner's read verbs to §83 and §306, one row per case (RN15/AC1, test 93's runner case).
func TestReads(t *testing.T) {
t.Run("show and kept carry the stores fill", testShowAndKeptCarryTheStoresFill)
t0 := time.Date(2026, 11, 11, 10, 0, 0, 0, time.UTC)
t1, t2 := t0.Add(time.Minute), t0.Add(2*time.Minute)
pipes, kept := memKept{}, memKept{}
put(t, pipes, "main.7.alpha", seat.Pipeline{Pipeline: "main.7.alpha", Branch: "main",
Source: 7, Outcome: seat.PipelineOutcomeRunning, Started: &t0, Steps: []seat.StepResult{
{Module: "alpha", Step: seat.StepResultStepLint, Artifact: "alpha:program", Status: "required", Outcome: seat.StepResultOutcomePassed,
Started: &t0, Ended: &t1, Seat: "node-build-go", Node: "n1", Ask: "a-lint"},
{Module: "alpha", Step: seat.StepResultStepUnit, Artifact: "alpha:program", Status: "required", Outcome: seat.StepResultOutcomeCarried,
CarriedFrom: "main.6.alpha"},
{Module: "alpha", Step: seat.StepResultStepApproval, Status: "required", Outcome: seat.StepResultOutcomeWaiting, On: seat.WaitOnPerson,
Started: &t1}}, Movers: []seat.Mover{{Module: "alpha", Commit: "c7"}}})
put(t, pipes, "beta.3.alpha", seat.Pipeline{Pipeline: "beta.3.alpha", Branch: "beta",
Outcome: seat.PipelineOutcomePassed, Started: &t2, Movers: []seat.Mover{{Module: "alpha", Commit: "b3"}}})
put(t, pipes, "main.7.gamma", seat.Pipeline{Pipeline: "main.7.gamma", Branch: "main",
Outcome: seat.PipelineOutcomeRunning, Started: &t1, Movers: []seat.Mover{{Module: "gamma", Commit: "c7"}}})
// A pipeline kept as H-A-187 keeps it: its record's steps empty, each mover's under steps.<pipeline>.<mover>.
put(t, pipes, "next.8", seat.Pipeline{Pipeline: "next.8", Branch: "next", Source: 8, Outcome: seat.PipelineOutcomeRunning,
Started: &t0, Steps: []seat.StepResult{}, Movers: []seat.Mover{{Module: "delta", Commit: "n8"}, {Module: "epsilon", Commit: "n8"}}})
// H-A-285, H-A-309: the record carries the runner's own kept-revisions, which show, list and stands read past.
withRevs, err := withKept(pipes["next.8"], map[string]int64{"delta": 7})
if err != nil {
t.Fatal(err)
}
pipes["next.8"] = withRevs
put(t, pipes, "steps.next.8.epsilon", seat.PipelinesByStepsPipelineMoverValue{Steps: []seat.StepResult{{Module: "epsilon",
Step: seat.StepResultStepBuild, Status: "required", Outcome: seat.StepResultOutcomePassed}}})
put(t, pipes, "steps.next.8.delta", seat.PipelinesByStepsPipelineMoverValue{Steps: []seat.StepResult{{Module: "delta",
Step: seat.StepResultStepBuild, Status: "required", Outcome: seat.StepResultOutcomePassed}, {Module: "delta",
Step: seat.StepResultStepApproval, Status: "required", Outcome: seat.StepResultOutcomeWaiting, On: seat.WaitOnPerson, Started: &t2}},
Unlogged: []seat.LogEntry{{Pipeline: "next.8", Module: "delta", Step: seat.StepResultStepBuild, What: seat.LogEntryWhatEnded, At: t1}}})
// A pipeline that failed: list's row names its first failed step (design 47 H2 H-A-376).
put(t, pipes, "gone.2", seat.Pipeline{Pipeline: "gone.2", Branch: "gone", Call: "call-2", Source: 2, Revision: 5, Outcome: seat.PipelineOutcomeFailed, Started: &t0, Ended: &t1,
Movers: []seat.Mover{{Module: "zeta", Commit: "g2"}}, Steps: []seat.StepResult{
{Module: "zeta", Step: seat.StepResultStepLint, Artifact: "zeta:program", Status: "optional", Outcome: seat.StepResultOutcomeFailed},
{Module: "zeta", Step: seat.StepResultStepUnit, Artifact: "zeta:program", Status: "required", Outcome: seat.StepResultOutcomeCouldNotRun, Why: "its node lacks node-build-node"}}})
put(t, kept, "unit.sha256-aa", seat.KeptResult{Level: "unit", Digest: "sha256-aa", Package: "alpha/x"})
put(t, kept, "integration.sha256-bb", seat.KeptResult{Level: "integration", Digest: "sha256-bb", Package: "alpha/y"})
r := Reads{Pipelines: pipes, Kept: kept}
names := func(ps []seat.PipelineRow) string {
var s []string
for _, p := range ps {
s = append(s, p.Pipeline)
}
return strings.Join(s, " ")
}
rows := []struct {
name string
got func() (string, error)
want string
}{
// Design 47 H2 H-A-376: naming no mover, show answers each mover's row and never its steps.
{"show naming no mover answers each mover's row", func() (string, error) {
a, err := r.Show(seat.ShowInput{Pipeline: "main.7.alpha"})
return fmt.Sprint(a.Pipeline.Movers[0].Module, " ", len(a.Pipeline.Steps), " ", a.Movers, " ", a.Total), err
}, "alpha 0 [{<nil> alpha running}] 1"},
{"show's row of a mover names its first failed step", func() (string, error) {
a, err := r.Show(seat.ShowInput{Pipeline: "gone.2"})
return fmt.Sprint(a.Movers[0].Outcome, " ", *a.Movers[0].Failed), err
}, "failed {zeta:program zeta could not run unit its node lacks node-build-node}"},
// design 47 H2 §791: a step's output is read where its build seat's holder keeps it, on the node its step key names.
{"a step's output is where its holder ran its ask", func() (string, error) {
at, err := r.StepOutputs("main.7.alpha", "alpha", seat.StepResultStepLint)
return fmt.Sprint(at), err
}, "[{alpha:program node-build-go n1 a-lint}]"},
{"a step that ran on no node keeps no output", func() (string, error) {
_, err := r.StepOutputs("main.7.alpha", "alpha", seat.StepResultStepUnit)
return "", err
}, "error: no output of the pipeline main.7.alpha's step unit of alpha is kept: unit alpha:program ran on no node (carried)"},
{"show refuses a pipeline it does not hold", func() (string, error) {
_, err := r.Show(seat.ShowInput{Pipeline: "main.9.alpha"})
return "", err
}, `error: no pipeline "main.9.alpha" in pipelines`},
{"show composes its movers' rows from its mover keys, in its movers' order (H-A-187)", func() (string, error) {
a, err := r.Show(seat.ShowInput{Pipeline: "next.8"})
var s []string
for _, m := range a.Movers {
s = append(s, m.Module+" "+m.Outcome)
}
return strings.Join(s, ", "), err
}, "delta running, epsilon passed"},
{"show naming a mover answers its steps alone", func() (string, error) {
a, err := r.Show(seat.ShowInput{Pipeline: "next.8", Mover: "epsilon"})
var s []string
for _, st := range a.Pipeline.Steps {
s = append(s, st.Module+" "+st.Step)
}
return fmt.Sprintf("%s, %d movers", strings.Join(s, ", "), len(a.Pipeline.Movers)), err
}, "epsilon build, 2 movers"},
{"show refuses a mover the pipeline does not move", func() (string, error) {
_, err := r.Show(seat.ShowInput{Pipeline: "next.8", Mover: "alpha"})
return "", err
}, "error: the pipeline next.8 does not move alpha"},
{"list names a pipeline, never a mover key, its record with its movers and steps counted and no step (H-A-191)", func() (string, error) {
a, err := r.List(seat.ListInput{Branch: "next", Full: true, Limit: 5})
var s []string
for _, p := range a.Pipelines {
s = append(s, fmt.Sprintf("%s %d movers %d steps, %d steps and %d unlogged answered", p.Pipeline, p.MoverCount, p.StepCount,
len(p.Steps), len(p.Unlogged)))
}
return strings.Join(s, "; "), err
}, "next.8 2 movers 3 steps, 0 steps and 0 unlogged answered"},
{"list by module, newest first", func() (string, error) {
a, err := r.List(seat.ListInput{Module: "alpha"})
return names(a.Rows), err
}, "beta.3.alpha main.7.alpha"},
{"list by commit", func() (string, error) {
a, err := r.List(seat.ListInput{Commit: "c7"})
return names(a.Rows), err
}, "main.7.gamma main.7.alpha"},
{"list by branch with a limit", func() (string, error) {
a, err := r.List(seat.ListInput{Branch: "main", Limit: 1})
return names(a.Rows), err
}, "main.7.gamma"},
// Design 47 H2 H-A-376, H-A-467: a row is the pipeline's key, call, source, revision, start, end, outcome, movers' count,
// its steps per outcome and first failed step;
// the whole pipelines are answered only with full and a limit; with no limit the rows are the newest 20.
{"list's row of a failed pipeline", func() (string, error) {
a, err := r.List(seat.ListInput{Branch: "gone"})
raw, _ := json.Marshal(a.Rows)
return fmt.Sprint(string(raw), " ", len(a.Pipelines)), err
}, `[{"branch":"gone","call":"call-2","ended":"2026-11-11T10:01:00Z","failed":{"artifact":"zeta:program","module":"zeta","outcome":"could not run","step":"unit","why":"its node lacks node-build-node"},"mover-count":1,"outcome":"failed","pipeline":"gone.2","revision":5,"source":2,"started":"2026-11-11T10:00:00Z","steps":{"could not run":1,"failed":1}}] 0`},
// Design 47 H2 H-A-467: a row counts the steps per outcome, a mover's kept steps (H-A-187) with them.
{"list's row counts its steps per outcome", func() (string, error) {
a, err := r.List(seat.ListInput{Branch: "next"})
return fmt.Sprint(a.Rows[0].Source, " ", a.Rows[0].Steps), err
}, "8 map[passed:2 waiting:1]"},
// Design 47 H2 H-A-533: naming no branch, list answers every branch's pipelines together, each row naming its branch.
{"list with no branch answers every branch's, newest first, each row naming its branch", func() (string, error) {
a, err := r.List(seat.ListInput{})
var s []string
for _, row := range a.Rows {
s = append(s, row.Branch+":"+row.Pipeline)
}
return strings.Join(s, " "), err
}, "beta:beta.3.alpha main:main.7.gamma gone:gone.2 main:main.7.alpha next:next.8"},
{"list's full needs a limit", func() (string, error) {
_, err := r.List(seat.ListInput{Full: true})
return "", err
}, "error: list answers the whole pipelines only with a limit"},
{"list answers the newest 20 rows by default", func() (string, error) {
many := memKept{}
for i := range 25 {
at := t0.Add(time.Duration(i) * time.Minute)
put(t, many, fmt.Sprintf("main.%d", i), seat.Pipeline{Pipeline: fmt.Sprintf("main.%d", i), Branch: "main", Outcome: seat.PipelineOutcomePassed, Started: &at})
}
a, err := Reads{Pipelines: many, Kept: memKept{}}.List(seat.ListInput{})
return fmt.Sprint(len(a.Rows), " ", a.Rows[0].Pipeline, " ", a.Rows[19].Pipeline), err
}, "20 main.24 main.5"},
{"stands names a waiting step and since when", func() (string, error) {
a, err := r.Stands()
var s []string
for _, w := range a.Stands {
s = append(s, w.Pipeline+" "+w.Step+" "+w.On+" "+w.Since.Format("15:04"))
}
return strings.Join(s, ";"), err
}, "main.7.alpha approval person 10:01;next.8 approval person 10:02"},
{"why-carried names where a carried step came from", func() (string, error) {
a, err := r.WhyCarried(seat.WhyCarriedInput{Pipeline: "main.7.alpha", Step: "unit", Artifact: "alpha:program"})
return a.CarriedFrom, err
}, "main.6.alpha"},
{"why-carried refuses a step that ran", func() (string, error) {
_, err := r.WhyCarried(seat.WhyCarriedInput{Pipeline: "main.7.alpha", Step: "lint"})
return "", err
}, `error: step lint of main.7.alpha alpha:program was not carried: it ended "passed"`},
{"kept by level", func() (string, error) {
a, err := r.KeptResults(seat.KeptInput{Level: "unit"})
var s []string
for _, k := range a.Kept {
s = append(s, k.Package)
}
return strings.Join(s, " "), err
}, "alpha/x"},
{"kept by package", func() (string, error) {
a, err := r.KeptResults(seat.KeptInput{Package: "alpha/y"})
var s []string
for _, k := range a.Kept {
s = append(s, k.Digest)
}
return strings.Join(s, " "), err
}, "sha256-bb"},
}
for _, row := range rows {
got, err := row.got()
if err != nil {
got = "error: " + err.Error()
}
if got != row.want {
t.Errorf("%s: got %q, want %q", row.name, got, row.want)
}
}
}
// show carries each store's fill (pipelines, kept, step-log) and kept the kept store's, read through the bundle's state
// call, never counted from the keys; a fill that cannot be read is an error, not an answer without it (design 47 G §366, §623, A-214).
// testShowAndKeptCarryTheStoresFill is a row of TestReads (design 47 H2 §819: the module's tests are folded under its budget).
func testShowAndKeptCarryTheStoresFill(t *testing.T) {
pipes, kept := memKept{}, memKept{}
put(t, pipes, "main.7.alpha", seat.Pipeline{Pipeline: "main.7.alpha", Movers: []seat.Mover{{Module: "alpha"}}})
fills := []seat.Fill{{Store: seat.StatePipelines, Bytes: 10, Cap: 100}, {Store: seat.StateKept, Bytes: 30, Cap: 300},
{Store: seat.StateStepLog, Bytes: 40, Cap: 400}}
r := Reads{Pipelines: pipes, Kept: kept, Fill: func() ([]seat.Fill, error) { return fills, nil }}
shown, err := r.Show(seat.ShowInput{Pipeline: "main.7.alpha"})
if err != nil || len(shown.Fill) != 3 || shown.Fill[1].Store != seat.StateKept || shown.Fill[2].Cap != 400 {
t.Errorf("show: %+v, %v; want the three stores' fill", shown.Fill, err)
}
k, err := r.KeptResults(seat.KeptInput{})
if err != nil || k.Fill == nil || k.Fill.Store != seat.StateKept || k.Fill.Bytes != 30 {
t.Errorf("kept: %+v, %v; want the kept store's fill", k.Fill, err)
}
r.Fill = func() ([]seat.Fill, error) { return nil, errors.New("the bus does not answer") }
if _, err := r.Show(seat.ShowInput{Pipeline: "main.7.alpha"}); err == nil || !strings.Contains(err.Error(), "fill") {
t.Errorf("show with the fill unread: %v", err)
}
}
// A step that reads a test run says its own step-started at every place it is asked, naming the run's key and ask in shared
// and no asker (design 47 G §726, §729; A-469a, A-469q), and stands names each waiting step's own ask and, for a test step,
// the run it waits on (§731; A-469r, A-469v).
func TestStandsAndStepStartedNameWhatAReadingStepWaitsOn(t *testing.T) {
f := newRunFixture()
p := f.start(t, 4, 9)
asker, reader := stepNamed(p, "app:program", "unit"), stepNamed(p, "app:tools", "unit")
started := map[string]seat.StepResult{}
for _, e := range f.said {
started[e.Result.Artifact+" "+e.Result.Step] = e.Result
}
for _, s := range []seat.StepResult{asker, reader} {
got, ok := started[s.Artifact+" unit"]
if !ok || len(got.Shared) != 1 || got.Shared[0] != (seat.Shared{Run: asker.Shared[0].Run, Ask: asker.Ask}) {
t.Errorf("the step-started of %s = %+v (said %v), want the run's key and ask, no asker", s.Artifact, got, ok)
}
}
if _, ok := started[" composition"]; !ok {
t.Error("the composition step's step-started is not said")
}
pipes := memKept{}
put(t, pipes, p.Pipeline, f.pipeline(p))
a, err := Reads{Pipelines: pipes, Kept: memKept{}}.Stands()
if err != nil {
t.Fatal(err)
}
waits := map[string]seat.Wait{}
for _, w := range a.Stands {
waits[w.Artifact+" "+w.Step] = w
}
want := []seat.Shared{{Run: asker.Shared[0].Run, Ask: asker.Ask}}
if w := waits["app:program unit"]; w.Ask != asker.Ask || len(w.Shared) != 1 || w.Shared[0] != want[0] {
t.Errorf("the asking step stands as %+v, want its ask and its run", w)
}
if w := waits["app:tools unit"]; w.Ask != "" || len(w.Shared) != 1 || w.Shared[0] != want[0] {
t.Errorf("the reading step stands as %+v, want no ask of its own and the run's key and ask", w)
}
if w := waits[" composition"]; w.Ask == "" || len(w.Shared) != 0 {
t.Errorf("the composition step stands as %+v, want its own ask and no run", w)
}
// Resume asks the steps again and says their step-started again (A-469a).
n := len(f.said)
if _, err := f.s.Resume(f.store, "main", Half{Entries: map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}); err != nil {
t.Fatal(err)
}
if len(f.said) == n {
t.Error("resume said no step-started")
}
}
// TestAPipelineIsReadInParts holds show and runner_movers to design 47 H2 §789: one mover's steps of a record of 129 movers
// answer under 64 KB; the filters apply while reading; a capped answer continues from its cursor; runner_movers of 1,000
// movers answers under 768 KB with one word per step.
func TestAPipelineIsReadInParts(t *testing.T) {
t0 := time.Date(2026, 11, 22, 1, 0, 0, 0, time.UTC)
record := func(n int) memKept {
pipes := memKept{}
p := seat.Pipeline{Pipeline: "main.9", Branch: "main", Source: 9, Outcome: seat.PipelineOutcomeRunning, Started: &t0,
Steps: []seat.StepResult{}}
for i := 0; i < n; i++ {
m := fmt.Sprintf("module-%04d", i)
p.Movers = append(p.Movers, seat.Mover{Module: m, Commit: "c9", Fingerprint: "src2:" + strings.Repeat("a", 64)})
var steps []seat.StepResult
for _, k := range []string{seat.StepResultStepBuild, seat.StepResultStepLint, seat.StepResultStepUnit,
seat.StepResultStepIntegration, seat.StepResultStepValidate, seat.StepResultStepComposition} {
o := seat.StepResultOutcomePassed
if k == seat.StepResultStepUnit && i%10 == 3 {
o = seat.StepResultOutcomeFailed
}
steps = append(steps, seat.StepResult{Module: m, Step: k, Artifact: m + ":program", Status: "required", Outcome: o,
Ask: "ask-" + m + "-" + k, Started: &t0, Ended: &t0, Why: strings.Repeat("w", 200)})
}
put(t, pipes, "steps.main.9."+m, seat.PipelinesByStepsPipelineMoverValue{Steps: steps})
}
put(t, pipes, "main.9", p)
return pipes
}
r := Reads{Pipelines: record(129), Kept: memKept{}}
a, err := r.Show(seat.ShowInput{Pipeline: "main.9", Mover: "module-0042"})
if raw, _ := json.Marshal(a); err != nil || len(raw) >= 64<<10 || len(a.Pipeline.Steps) != 6 || a.Total != 6 || a.Capped {
t.Fatalf("one mover of 129: %d bytes, %d steps, total %d, capped %v, %v", len(raw), len(a.Pipeline.Steps), a.Total, a.Capped, err)
}
a, err = r.Show(seat.ShowInput{Pipeline: "main.9", Step: seat.StepResultStepUnit, State: seat.StepResultOutcomeFailed})
if err != nil || a.Total != 13 || len(a.Pipeline.Steps) != 13 || a.Pipeline.Steps[0].Module != "module-0003" {
t.Fatalf("the failed unit steps: total %d, %d steps, %v", a.Total, len(a.Pipeline.Steps), err)
}
// The steps a filter holds are larger than one answer: they are read in pages, each under 768 KB, every step once.
big := Reads{Pipelines: record(1000), Kept: memKept{}}
seen, pages, next := 0, 0, ""
for {
a, err := big.Show(seat.ShowInput{Pipeline: "main.9", State: seat.StepResultOutcomePassed, Next: next})
raw, _ := json.Marshal(a)
if err != nil || len(raw) > MaxAnswer || a.Total != 5900 {
t.Fatalf("page %d: %d bytes, total %d, %v", pages, len(raw), a.Total, err)
}
seen, pages = seen+len(a.Pipeline.Steps), pages+1
if !a.Capped {
break
}
next = a.Next
}
if seen != 5900 || pages < 2 {
t.Fatalf("pages %d read %d steps, want every one of 5900 over more than one page", pages, seen)
}
// Design 47 H2 H-A-376: naming no mover and no filter, show answers 1,000 movers' rows in one answer and no step.
if a, err := big.Show(seat.ShowInput{Pipeline: "main.9"}); err != nil || len(a.Movers) != 1000 || len(a.Pipeline.Steps) != 0 || a.Capped ||
a.Movers[3].Outcome != seat.MoverRowOutcomeFailed || a.Movers[3].Failed == nil || a.Movers[3].Failed.Step != seat.StepResultStepUnit {
t.Fatalf("the movers' rows: %d rows, %d steps, capped %v, %v", len(a.Movers), len(a.Pipeline.Steps), a.Capped, err)
}
if _, err := big.Show(seat.ShowInput{Pipeline: "main.9", Next: "not-a-cursor"}); err == nil {
t.Fatal("a cursor show never answered is refused")
}
m, err := big.Movers("main.9")
raw, _ := json.Marshal(m)
if err != nil || len(raw) >= MaxAnswer || len(m.Movers) != 1000 {
t.Fatalf("runner_movers of 1,000: %d bytes, %d movers, %v", len(raw), len(m.Movers), err)
}
if got := m.Movers[3].Steps["unit module-0003:program"] + " " + m.Movers[4].Steps["validate"]; got != "failed passed" {
t.Fatalf("words %q", got)
}
}