The runner's tools bundle serves the seat mesh-pipeline-runner's read verbs as tools named <seat>.<verb>, answered from its own states pipelines and kept, never another part's: show one pipeline whole with its steps and their outputs' names, list by module, branch, commit or run newest first, stands every step started and not ended with what it waits on and since when, why-carried the pipeline a carried step came from, kept the kept results by level, digest or package. Builds: design 47 G §83, §306, §75 (stands), §25 (why-carried) Not built, waiting on design answers: show's step log (Q-RN6, the step log's section form) and each store's fill against its cap in show and kept (Q-RN2, where the caps are declared). Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
130 lines
4.8 KiB
Go
130 lines
4.8 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
seat "git.novox.be/novox/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", Module: "alpha", Branch: "main", Commit: "c7",
|
|
Source: 7, Outcome: seat.PipelineOutcomeRunning, Started: &t0, Steps: []seat.StepResult{
|
|
{Step: seat.StepResultStepLint, Artifact: "alpha:program", Status: "required", Outcome: seat.StepResultOutcomePassed,
|
|
Started: &t0, Ended: &t1, Output: "main.7.alpha.lint.alpha:program"},
|
|
{Step: seat.StepResultStepUnit, Artifact: "alpha:program", Status: "required", Outcome: seat.StepResultOutcomeCarried,
|
|
CarriedFrom: "main.6.alpha"},
|
|
{Step: seat.StepResultStepApproval, Status: "required", Outcome: seat.StepResultOutcomeWaiting, On: seat.WaitOnPerson,
|
|
Started: &t1},
|
|
}})
|
|
put(t, pipes, "beta.3.alpha", seat.Pipeline{Pipeline: "beta.3.alpha", Module: "alpha", Branch: "beta", Commit: "b3",
|
|
Outcome: seat.PipelineOutcomePassed, Started: &t2})
|
|
put(t, pipes, "main.7.gamma", seat.Pipeline{Pipeline: "main.7.gamma", Module: "gamma", Branch: "main", Commit: "c7",
|
|
Outcome: seat.PipelineOutcomeRunning, Started: &t1})
|
|
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.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)
|
|
}
|
|
}
|
|
}
|