diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/read.go b/modules/mesh-delivery-pipeline/internal/pipeline/read.go index 584ed38b4..160796b11 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/read.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/read.go @@ -74,7 +74,9 @@ func (r Reads) Show(in seat.ShowInput) (seat.ShowAnswer, error) { // Naming neither a mover nor a filter, show answers each mover's row, never every step of every mover (design 47 H2 // H-A-376), in pages as the steps are. rows := MoverRows(p) - p.Steps = []seat.StepResult{} + moverCount, stepCount := int64(len(p.Movers)), int64(len(p.Steps)) + p.Steps, p.Movers, p.Unlogged = []seat.StepResult{}, []seat.Mover{}, nil // the page's mover rows name each mover (design 47 H2 H-A-709 (1)) + p.MoverCount, p.StepCount = moverCount, stepCount a := seat.ShowAnswer{Pipeline: p, Fill: fills, Total: int64(len(rows)), Movers: []seat.MoverRow{}} size := sizeOf(a) for i := from; i < len(rows); i++ { @@ -88,17 +90,30 @@ func (r Reads) Show(in seat.ShowInput) (seat.ShowAnswer, error) { } return a, nil } + p0steps := len(p.Steps) held := []seat.StepResult{} for _, s := range p.Steps { if (m == "" || s.Module == m) && (in.Step == "" || s.Step == in.Step) && (in.State == "" || s.Outcome == in.State) { held = append(held, s) } } - p.Steps = []seat.StepResult{} + // The answer names only the movers its page holds: the named mover, or those whose steps the page holds (design 47 H2 H-A-709 (1)). + all := p.Movers + p.Steps, p.Movers, p.Unlogged = []seat.StepResult{}, []seat.Mover{}, nil + p.MoverCount, p.StepCount = int64(len(all)), int64(p0steps) a := seat.ShowAnswer{Pipeline: p, Fill: fills, Total: int64(len(held))} size := sizeOf(a) + named := map[string]bool{} for i := from; i < len(held); i++ { n := sizeOf(held[i]) + 1 + if !named[held[i].Module] { // the mover the page's step belongs to is on the page too + named[held[i].Module] = true + for _, mv := range all { + if mv.Module == held[i].Module { + n += sizeOf(mv) + 1 + } + } + } if size+n > MaxAnswer && len(a.Pipeline.Steps) > 0 { a.Capped, a.Next = true, pageCursor(i) break @@ -106,6 +121,11 @@ func (r Reads) Show(in seat.ShowInput) (seat.ShowAnswer, error) { size += n a.Pipeline.Steps = append(a.Pipeline.Steps, held[i]) } + for _, mv := range all { + if mv.Module == m || slices.ContainsFunc(a.Pipeline.Steps, func(s seat.StepResult) bool { return s.Module == mv.Module }) { + a.Pipeline.Movers = append(a.Pipeline.Movers, mv) + } + } return a, nil } @@ -223,7 +243,7 @@ func MoverRows(p seat.Pipeline) []seat.MoverRow { out := make([]seat.MoverRow, 0, len(p.Movers)) for _, m := range p.Movers { steps := stepsOf(p, m.Module) - row := seat.MoverRow{Module: m.Module, Outcome: seat.MoverRowOutcomePassed, Failed: firstFailed(steps)} + row := seat.MoverRow{Module: m.Module, Outcome: seat.MoverRowOutcomePassed, Failed: firstFailed(steps), Fingerprint: m.Fingerprint, Version: m.Version, Tier: m.Tier} running, failed := false, false for _, s := range steps { switch { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go index 430eeb04d..cb9e3aeb3 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/read_test.go @@ -46,7 +46,7 @@ func TestReads(t *testing.T) { {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"}}}) + Started: &t1}}, Movers: []seat.Mover{{Module: "alpha", Commit: "c7", Tier: 2}}}) 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", @@ -90,8 +90,10 @@ func TestReads(t *testing.T) { // 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 [{ alpha running}] 1"}, + // design 47 H2 H-A-709 (1): the answer's pipeline names no mover of its own, the rows do, each with its fingerprint, version and + // tier; mover-count and step-count count the record's + return fmt.Sprint(len(a.Pipeline.Movers), " ", len(a.Pipeline.Steps), " ", a.Movers, " ", a.Total, " ", a.Pipeline.MoverCount, " ", a.Pipeline.StepCount), err + }, "0 0 [{ alpha running 2 }] 1 1 3"}, {"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 @@ -124,7 +126,7 @@ func TestReads(t *testing.T) { 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"}, + }, "epsilon build, 1 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 @@ -336,10 +338,17 @@ func TestAPipelineIsReadInParts(t *testing.T) { 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) } + if len(a.Pipeline.Movers) != 1 || a.Pipeline.Movers[0].Module != "module-0042" || a.Pipeline.MoverCount != 129 || a.Pipeline.StepCount != 129*6 { + t.Fatalf("one mover named: the answer's movers %d, counts %d and %d; want that mover alone and the record's counts", len(a.Pipeline.Movers), a.Pipeline.MoverCount, a.Pipeline.StepCount) + } 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) } + // H2 H-A-709 (1): with step and state the movers are those whose steps the page holds, 13 of 129 + if len(a.Pipeline.Movers) != 13 || a.Pipeline.Movers[0].Module != "module-0003" { + t.Fatalf("the filters' answer names %d movers, want the 13 whose steps the page holds", len(a.Pipeline.Movers)) + } // 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, "" diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go index 3ac122550..5938011b7 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -290,7 +290,7 @@ func TestAKeptMoverWaitingOnItsRevisionSaysSo(t *testing.T) { said++ } } - shown, err := Reads{Pipelines: rawKept{store.Raw.(*memRaw)}, Kept: memKept{}}.Show(seat.ShowInput{Pipeline: key}) + shown, err := Reads{Pipelines: rawKept{store.Raw.(*memRaw)}, Kept: memKept{}}.Show(seat.ShowInput{Pipeline: key, Mover: "app"}) // the mover named: the answer holds that mover alone (H-A-709 (1)) if err != nil || said != 1 || shown.Pipeline.Movers[0].Unplaced != seat.MoverUnplacedKeptRevisionUnread || shown.Pipeline.Movers[0].Revision != 11 { t.Fatalf("said %d times, show %+v (%v)", said, shown.Pipeline.Movers, err) }