diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go index 54e1c8224..69464e34c 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go @@ -176,3 +176,31 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) { t.Errorf("pipeline-ended names %+v, want app at 0.4.1", got) } } + +// Design 47 H2 §785: a pipeline of two movers ends with its taken, placed and ended times and each step kind's span, the +// earliest start and the latest end across its movers; a kind none of whose steps started has none. +func TestPipelineEndedCarriesEachStepKindsSpan(t *testing.T) { + at := func(m int) *time.Time { v := time.Date(2026, 11, 22, 1, m, 0, 0, time.UTC); return &v } + p := seat.Pipeline{Pipeline: "main.7", Started: at(0), Ended: at(30), Outcome: seat.PipelineOutcomePassed, + Movers: []seat.Mover{{Module: "lib", Tier: 1}, {Module: "app", Tier: 2}}, + Steps: []seat.StepResult{ + {Module: "lib", Step: seat.StepResultStepBuild, Started: at(2), Ended: at(6)}, + {Module: "app", Step: seat.StepResultStepBuild, Started: at(1), Ended: at(9)}, + {Module: "lib", Step: seat.StepResultStepUnit, Started: at(7), Ended: at(12)}, + {Module: "app", Step: seat.StepResultStepUnit, Started: at(10)}, + {Module: "app", Step: seat.StepResultStepComposition}, + }} + ph := pipelineEnded(p).Phases + if ph == nil || !ph.Taken.Equal(*at(0)) || !ph.Placed.Equal(*at(1)) || !ph.Ended.Equal(*at(30)) { + t.Fatalf("phases %+v, want taken 01:00, placed 01:01, ended 01:30", ph) + } + if ph.Build == nil || !ph.Build.Start.Equal(*at(1)) || !ph.Build.End.Equal(*at(9)) { + t.Errorf("build span %+v, want 01:01 to 01:09", ph.Build) + } + if ph.Unit == nil || !ph.Unit.Start.Equal(*at(7)) || !ph.Unit.End.Equal(*at(12)) { + t.Errorf("unit span %+v, want 01:07 to 01:12", ph.Unit) + } + if ph.Composition != nil || ph.Lint != nil || ph.Validate != nil || ph.Integration != nil { + t.Errorf("a kind with no started step has a span: %+v", ph) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index b78093104..a9736389e 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -674,7 +674,56 @@ func pipelineEnded(p seat.Pipeline) seat.PipelineEnded { } sort.SliceStable(movers, func(i, j int) bool { return movers[i].Tier < movers[j].Tier }) return seat.PipelineEnded{V: 1, Pipeline: p.Pipeline, Branch: p.Branch, Source: p.Source, Call: p.Call, Revision: p.Revision, - Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers} + Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers, + Phases: phasesOf(p)} +} + +// phasesOf is p's phases (design 47 H2 §785): taken, when the runner wrote the pipeline at its take-in; placed, the +// earliest start of any of its steps; ended, its end; and for each step kind the earliest start and the latest end across +// its movers. A kind none of whose steps started has no span. +func phasesOf(p seat.Pipeline) *seat.PipelineEndedPhases { + type span struct{ start, end *time.Time } + spans := map[string]*span{} + var placed *time.Time + for _, st := range p.Steps { + if st.Started == nil { + continue + } + if placed == nil || st.Started.Before(*placed) { + placed = st.Started + } + sp := spans[st.Step] + if sp == nil { + sp = &span{} + spans[st.Step] = sp + } + if sp.start == nil || st.Started.Before(*sp.start) { + sp.start = st.Started + } + if st.Ended != nil && (sp.end == nil || st.Ended.After(*sp.end)) { + sp.end = st.Ended + } + } + ph := &seat.PipelineEndedPhases{Taken: p.Started, Placed: placed, Ended: p.Ended} + if sp := spans[seat.StepResultStepBuild]; sp != nil { + ph.Build = &seat.PipelineEndedPhasesBuild{Start: sp.start, End: sp.end} + } + if sp := spans[seat.StepResultStepLint]; sp != nil { + ph.Lint = &seat.PipelineEndedPhasesLint{Start: sp.start, End: sp.end} + } + if sp := spans[seat.StepResultStepUnit]; sp != nil { + ph.Unit = &seat.PipelineEndedPhasesUnit{Start: sp.start, End: sp.end} + } + if sp := spans[seat.StepResultStepIntegration]; sp != nil { + ph.Integration = &seat.PipelineEndedPhasesIntegration{Start: sp.start, End: sp.end} + } + if sp := spans[seat.StepResultStepValidate]; sp != nil { + ph.Validate = &seat.PipelineEndedPhasesValidate{Start: sp.start, End: sp.end} + } + if sp := spans[seat.StepResultStepComposition]; sp != nil { + ph.Composition = &seat.PipelineEndedPhasesComposition{Start: sp.start, End: sp.end} + } + return ph } func endOutcome(o string) bool {