diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 7568e156..375454ae 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -3,6 +3,7 @@ package pipeline import ( "errors" "fmt" + "slices" "strings" "time" @@ -296,11 +297,15 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error return -1, err } } + oldAsk := s.Ask *s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat, Outcome: seat.StepResultOutcomeWaiting, By: caller, Rerun: true} if ask != nil { s.Outcome, s.Started, s.Ask = seat.StepResultOutcomeRunning, &now, ask.ID } + if ask != nil && s.Step == seat.StepResultStepValidate && s.Seat == wants.Seat { + rerunValidate(p, i, oldAsk, caller, now) + } // The pipeline runs again; an approval never asked waits again, to be asked when the step passes. if p.Outcome != seat.PipelineOutcomeRunning { p.Outcome, p.Why, p.Ended = seat.PipelineOutcomeRunning, "", nil @@ -479,6 +484,29 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult) return seat.RerunAnswer{Pipeline: in.Pipeline, Result: &res}, nil } +// rerunValidate puts, with the rerun of validate step i, every other mover's validate step under the same ask back to running +// under its one new id, a mover that left the pipeline skipped, so the pipeline keeps one validate ask (H-A-51); and each +// composition its validate held ended not asked waits again, asked once validate passed as at the placing (§745). +func rerunValidate(p *seat.Pipeline, i int, oldAsk, caller string, now time.Time) { + id := p.Steps[i].Ask + for j := range p.Steps { + st := &p.Steps[j] + if slices.Contains(p.Superseded, st.Module) { + continue + } + switch { + case j != i && st.Step == seat.StepResultStepValidate && st.Seat == wants.Seat && oldAsk != "" && + (st.Ask == oldAsk || st.Ask == AgainID(oldAsk)) && st.Outcome != seat.StepResultOutcomeSuperseded && st.Outcome != seat.StepResultOutcomeCancelled: + *st = seat.StepResult{Step: st.Step, Module: st.Module, Artifact: st.Artifact, Status: st.Status, Fingerprint: st.Fingerprint, Seat: st.Seat, + Outcome: seat.StepResultOutcomeRunning, Started: &now, Ask: id, By: caller, Rerun: true} + case st.Step == seat.StepResultStepComposition && st.Seat == wants.Seat && st.Outcome == seat.StepResultOutcomeNotAsked && + strings.HasPrefix(st.Why, "validate ended "): + *st = seat.StepResult{Step: st.Step, Module: st.Module, Artifact: st.Artifact, Status: st.Status, Fingerprint: st.Fingerprint, Seat: st.Seat, + Outcome: seat.StepResultOutcomeWaiting, Why: "asked once validate passed"} + } + } +} + // passedReader says whether reader's step of run passed, or a person accepted it (§30): a step that moves with no new run. func (v Verbs) passedReader(reader RunReader, run string) bool { p, _, err := v.Hearer.Store.Get(reader.Pipeline) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go index ed9a67c3..6b4fbbac 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go @@ -382,3 +382,44 @@ func TestStartAndAskAgain(t *testing.T) { t.Error("an approval running was asked again") } } + +// Review of H-A-236 (H-A-51): a rerun of validate puts every mover's validate step under the old ask back to running under +// the one new id, a mover that left skipped, and the compositions its failed validate ended not asked wait again; the new +// ask's end ends both validates and asks both compositions. +func TestAValidateRerunMovesEveryMoversValidateAndReopensItsCompositions(t *testing.T) { + v, store, _, asks, _, _ := verbsFixture() + p, rev, _ := store.Get(pkey) + p.Outcome = seat.PipelineOutcomeFailed + p.Movers = append(p.Movers, seat.Mover{Module: "lib", Commit: "c2", Fingerprint: "src2:bb"}, seat.Mover{Module: "gone", Commit: "c3", Fingerprint: "src2:cc"}) + p.Superseded = []string{"gone"} + notAsked := "validate ended failed: nothing is composed" + p.Steps = nil + for _, m := range []string{"app", "lib", "gone"} { + p.Steps = append(p.Steps, + seat.StepResult{Module: m, Step: seat.StepResultStepValidate, Status: seat.StepResultStatusRequired, Seat: wants.Seat, Ask: "old", Outcome: seat.StepResultOutcomeFailed}, + seat.StepResult{Module: m, Step: seat.StepResultStepComposition, Status: seat.StepResultStatusRequired, Seat: wants.Seat, Outcome: seat.StepResultOutcomeNotAsked, Why: notAsked}) + } + p.Steps[4].Outcome, p.Steps[5].Outcome = seat.StepResultOutcomeSuperseded, seat.StepResultOutcomeSuperseded + store.Update(pkey, p, rev) + r, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Module: "app", Step: seat.StepResultStepValidate, Why: "again"}) + if err != nil || len(asks.ids) != 1 || r.Result.Ask != asks.ids[0] { + t.Fatalf("the rerun = %+v (%v), asked %v; want one validate ask", r.Result, err, asks.ids) + } + got, _, _ := store.Get(pkey) + for i, want := range []string{"running " + r.Result.Ask, "waiting ", "running " + r.Result.Ask, "waiting ", "superseded old", "superseded "} { + if s := got.Steps[i]; s.Outcome+" "+s.Ask != want { + t.Errorf("%s's %s = %s %q, want %s", s.Module, s.Step, s.Outcome, s.Ask, want) + } + } + bs := StepSeats[len(StepSeats)-1] + ev := StepEnded{ID: r.Result.Ask, Node: "n1", Pipeline: pkey, Module: "lib", Commit: "c2", Fingerprint: "src2:bb", Step: seat.StepResultStepValidate, Outcome: "passed"} + if _, err := v.Hearer.OnStepEnded(bs, bs.Prefix+"n1", ev); err != nil { + t.Fatal(err) + } + got, _, _ = store.Get(pkey) + for _, i := range []int{1, 3} { + if s := got.Steps[i]; s.Outcome != seat.StepResultOutcomeRunning || s.Ask == "" { + t.Errorf("%s's composition = %s %q, want asked once validate passed", s.Module, s.Outcome, s.Ask) + } + } +}