A take-in.taken with entries starts one pipeline keyed <branch>.<source> by compare-and-set, its movers the entries; each mover's steps are placed from its own registration and entry, each step and ask id naming its mover; a step end is matched to its mover's commit and fingerprint; the pipeline passes when every mover's required steps passed, a required "nothing to run" counting as passed. The movers get tiers from the delivery edges (kinds 2, 4, 5, 6; a cycle one tier, said). pipeline-started and pipeline-ended are said on <branch>.<source>, the end once with per mover its fingerprint, version, steps and tier, in tier order; waits on <branch>.<source>; step events on <module>.<branch>.<commit>; no group-ended. Approval is one step per mover. A run on request is one pipeline keyed <branch>.run.<id>, its source the branch's newest, members of one branch only. A running pipeline is superseded no more. A composition step names the runner as its asker. The seat's verb place is served, refusing every pipeline until the queue (R11, R14). The seat list part takes no callers (H-A-66). Unit tests 77 to 80, integration 3. Builds: design 47 H §746, §747 (run, start, a publish's key), §748 (a running pipeline runs to its end), §764 (group-ended, the key per module); lead answers H-A-3, H-A-35, H-A-51, H-A-52, H-A-53, H-A-66, H-A-70, H-A-72, H-A-83 (1), H-A-85, H-A-88 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
205 lines
9.0 KiB
Go
205 lines
9.0 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"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) {
|
|
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, Output: "main.7.alpha.lint.alpha:program"},
|
|
{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"}}})
|
|
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.Pipeline) 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
|
|
}{
|
|
{"show answers the pipeline whole and its outputs", func() (string, error) {
|
|
a, err := r.Show(seat.ShowInput{Pipeline: "main.7.alpha"})
|
|
return a.Pipeline.Movers[0].Module + " " + strings.Join(a.Outputs, ","), err
|
|
}, "alpha main.7.alpha.lint.alpha:program"},
|
|
{"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`},
|
|
{"list by module, newest first", func() (string, error) {
|
|
a, err := r.List(seat.ListInput{Module: "alpha"})
|
|
return names(a.Pipelines), err
|
|
}, "beta.3.alpha main.7.alpha"},
|
|
{"list by commit", func() (string, error) {
|
|
a, err := r.List(seat.ListInput{Commit: "c7"})
|
|
return names(a.Pipelines), 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.Pipelines), err
|
|
}, "main.7.gamma"},
|
|
{"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"},
|
|
{"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, step-outputs, 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).
|
|
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.StateStepOutputs, Bytes: 20, Cap: 200},
|
|
{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) != 4 || shown.Fill[1].Store != seat.StateStepOutputs || shown.Fill[3].Cap != 400 {
|
|
t.Errorf("show: %+v, %v; want the four 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")
|
|
}
|
|
}
|