Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go
T
jschoubben 5db642e161 Merge branch 'feat/47-G-fix11-b1f' into feat/47-G-join11
# Conflicts:
#	modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/main.go
#	modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/main_test.go
#	modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/findingwriter.go
#	modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go
#	modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/views.go
#	modules/mesh-delivery-pipeline/go.mod
#	modules/mesh-delivery-pipeline/internal/pipeline/read_test.go
#	modules/mesh-delivery-pipeline/internal/pipeline/start.go
#	modules/mesh-delivery-pipeline/manifest_test.go
#	modules/mesh-delivery-pipeline/module.json
2026-11-12 10:30:22 +01:00

169 lines
7.2 KiB
Go

package pipeline
import (
"encoding/json"
"errors"
"strings"
"testing"
"time"
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", 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)
}
}
}
// runner_waits lists the pipelines held for the runner's new version as waits of step `pipeline` (design 47 G §276, A-195).
func TestWaitsListTheHeldPipelines(t *testing.T) {
since := time.Date(2026, 11, 12, 6, 0, 0, 0, time.UTC)
held := seat.Pipeline{Pipeline: "main.4.app", Module: "app", Branch: "main", Commit: "c1", Source: 4, Outcome: seat.PipelineOutcomeRunning,
Held: &seat.Held{Since: since, Fingerprint: "src2:new"}}
plain := seat.Pipeline{Pipeline: "main.3.app", Module: "app", Branch: "main", Outcome: seat.PipelineOutcomeRunning}
pipes := memKept{}
put(t, pipes, held.Pipeline, held)
put(t, pipes, plain.Pipeline, plain)
r := Reads{Pipelines: pipes, Kept: memKept{}}
got, err := r.Waits()
if err != nil || len(got.Stands) != 1 || got.Stands[0].Step != seat.WaitStepPipeline || got.Stands[0].Fingerprint != "src2:new" || !got.Stands[0].Since.Equal(since) {
t.Fatalf("waits = %+v, %v", got, err)
}
}
// 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", 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)
}
}