From e5a79db912b2a301e84ea843726f49c05fa9e07a Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:42:31 +0100 Subject: [PATCH] R9: validate comes before composition, one run per pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each mover gets a validate step on the seat mesh-wants before its composition, its status from the policy; one ask per pipeline that every mover's validate step reads (a mover placed later reads it, its result too). A mover's composition waits until validate ends: asked once it passed, ended not asked when it did not, so a manifest the validator refuses is never composed. The step runs name the runner's seat as their asker. Unit tests 81 to 82. Builds: design 47 H §745 (the runner's order); lead answers H-A-51, H-A-88 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../cmd/mesh-delivery-pipeline/main.go | 1 + .../run_integration_test.go | 2 +- .../testruns_integration_test.go | 2 +- .../internal/pipeline/place.go | 83 ++++++++++++++++--- .../internal/pipeline/place_test.go | 72 ++++++++++++++-- .../internal/pipeline/registrations.go | 2 + .../internal/pipeline/start.go | 39 ++++++++- .../internal/pipeline/steps.go | 34 ++++++++ .../internal/pipeline/testruns_test.go | 6 +- 9 files changed, 219 insertions(+), 22 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index 4a93fee1..ae42a3a5 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -151,6 +151,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, js: js, cred: cred}, Name: cred.Module, Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains), Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing} + hearer.AskSteps = starter.AskSteps placeHalf := func(ev catalog.CatalogRevisionEvent, half pipeline.Half) error { n, err := starter.PlaceRun(ev, half, rv.Catalog.View) logger.Printf("the candidate %s's revision %d placed %d pipelines of its run", ev.Group, ev.Revision, n) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go index 62813996..807c8c0f 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go @@ -88,7 +88,7 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes } // The seats the runner calls, answered as their holders do. - reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Composition: "bypass", Approval: "bypass"}}} + reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Validate: "bypass", Composition: "bypass", Approval: "bypass"}}} answer := func(subject string, body any) { if _, err := nc.Subscribe(subject, func(m *nats.Msg) { raw, _ := json.Marshal(map[string]any{"result": body}) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go index 09e20273..c40874b0 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns_integration_test.go @@ -101,7 +101,7 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { // The registrations: app tests its program and tools bundle from one directory, its unit step required and its // integration step optional; web is built by node-build-node. - policy := catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", Integration: "optional", Composition: "bypass", Review: "bypass", Approval: "bypass"}} + policy := catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", Integration: "optional", Validate: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass"}} regs := []catalog.Registration{{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: policy}, {Module: "web", Branches: []string{"main"}, Origin: "o/web", Policy: policy}} answer := func(subject string, body any) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place.go b/modules/mesh-delivery-pipeline/internal/pipeline/place.go index 1778a40f..cd3b8a93 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place.go @@ -49,9 +49,9 @@ var acceptRecovery = map[string]string{ // buildSteps are the steps an artifact's build seat runs, in the order they are asked (design 47 G §22). var buildSteps = []string{seat.StepResultStepLint, seat.StepResultStepUnit, seat.StepResultStepIntegration} -// moduleSteps are the steps of the whole module: composition (the assigner's), review (the runner's own verb) and the -// approval, asked last (§22, §26). -var moduleSteps = []string{seat.StepResultStepComposition, seat.StepResultStepReview, seat.StepResultStepApproval} +// moduleSteps are the steps of the whole module: validate and composition (the assigner's, validate before composition, +// design 47 H §745), review (the runner's own verb) and the approval, asked last (§22, §26). +var moduleSteps = []string{seat.StepResultStepValidate, seat.StepResultStepComposition, seat.StepResultStepReview, seat.StepResultStepApproval} // AskID is a step's ask id in the usual ask id form the holders accept (buildstep.CheckAskID): base 36 of started in // milliseconds, then six hex digits of the sha256 of the pipeline, the mover, the artifact and the step, so the same @@ -163,6 +163,7 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ asks = append(asks, ask) } } + validating := false for _, step := range moduleSteps { status := Status(reg, "", step) if status == "" { @@ -171,17 +172,31 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ s := seat.StepResult{Step: step, Module: m.Module, Status: status, Outcome: seat.StepResultOutcomeWaiting} if status == seat.StepResultStatusBypass { s.Outcome, s.Why = seat.StepResultOutcomeBypassed, "bypassed by the module's policy" + steps = append(steps, s) + continue } - // Composition is the assigner's, an accepted kind step of the seat mesh-wants (§22): it is asked with the others, - // running at once, and its end is heard from that seat as the build seats' are; the ask names the runner's seat as its - // asker (H-A-88). Review and approval wait. - if step == seat.StepResultStepComposition && status != seat.StepResultStatusBypass { + switch step { + case seat.StepResultStepValidate: + // validate is the assigner's, an accepted kind step of the seat mesh-wants, run once per take-in revision: every + // mover's validate step reads the one ask, its id naming no mover (§745, H-A-51). s.Seat, s.Outcome, s.Started, s.Fingerprint = wants.Seat, seat.StepResultOutcomeRunning, &now, m.Fingerprint + s.Ask = ValidateAskID(p, now) + asks = append(asks, wantsAsk(p, m, s.Ask, wants.StepRunStepValidate)) + validating = true + case seat.StepResultStepComposition: + // Composition is the assigner's (§22): its end is heard from that seat as the build seats' are; the ask names the + // runner's seat as its asker (H-A-88). It is asked once the mover's validate passed, at once when it has none + // (§745). + s.Seat, s.Fingerprint = wants.Seat, m.Fingerprint s.Ask = AskID(startOf(p, now), p.Pipeline, m.Module, "", step) - asks = append(asks, Asked{Seat: wants.Seat, ID: s.Ask, Commit: m.Commit, Ask: wants.StepRun{Branch: p.Branch, Commit: m.Commit, Fingerprint: m.Fingerprint, - Module: m.Module, Pipeline: p.Pipeline, Revision: p.Revision, Source: p.Source, Run: p.Run, Step: wants.StepRunStepComposition, - Asker: seat.Seat}}) + if validating { + s.Ask, s.Why = "", "asked once validate passed" + break + } + s.Outcome, s.Started = seat.StepResultOutcomeRunning, &now + asks = append(asks, wantsAsk(p, m, s.Ask, wants.StepRunStepComposition)) } + // Review and approval wait. steps = append(steps, s) } return steps, asks @@ -249,3 +264,51 @@ func artifactPaths(e catalog.CatalogEntry, ref string) []string { _, name, _ := strings.Cut(ref, ":") return e.Inputs.Paths[name] } + +// ValidateAskID is the one ask id of a pipeline's validate run (design 47 H §745, H-A-51): every mover's validate step reads +// it. +func ValidateAskID(p seat.Pipeline, now time.Time) string { + return AskID(startOf(p, now), p.Pipeline, "", "", seat.StepResultStepValidate) +} + +// wantsAsk is the ask of a step the seat mesh-wants serves, validate or composition, for mover m (§745, §22; H-A-88). +func wantsAsk(p seat.Pipeline, m seat.Mover, id, step string) Asked { + return Asked{Seat: wants.Seat, ID: id, Commit: m.Commit, Ask: wants.StepRun{Branch: p.Branch, Commit: m.Commit, Fingerprint: m.Fingerprint, + Module: m.Module, Pipeline: p.Pipeline, Revision: p.Revision, Source: p.Source, Run: p.Run, Step: step, Asker: seat.Seat}} +} + +// releaseCompositions asks the composition of each mover whose validate ended passed, and ends `not asked` the composition +// of each whose validate did not pass, so a manifest the validator refuses is never composed (design 47 H §745). It answers +// the asks to put and the indexes of the steps it ended. +func releaseCompositions(p *seat.Pipeline, now time.Time) ([]Asked, []int) { + var asks []Asked + var ended []int + for _, m := range p.Movers { + v, c := -1, -1 + for i, st := range p.Steps { + if st.Module != m.Module { + continue + } + switch { + case st.Step == seat.StepResultStepValidate && st.Ask != "": + v = i + case st.Step == seat.StepResultStepComposition && st.Seat == wants.Seat && st.Ask == "" && st.Outcome == seat.StepResultOutcomeWaiting: + c = i + } + } + if v < 0 || c < 0 || open(p.Steps[v]) { + continue + } + s := &p.Steps[c] + if !stepPassed(p.Steps[v]) { + s.Outcome, s.Why, s.Ended = seat.StepResultOutcomeNotAsked, "validate ended "+p.Steps[v].Outcome+": nothing is composed", &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *s, now)) + ended = append(ended, c) + continue + } + s.Ask = AskID(startOf(*p, now), p.Pipeline, m.Module, "", seat.StepResultStepComposition) + s.Outcome, s.Started, s.Why = seat.StepResultOutcomeRunning, &now, "" + asks = append(asks, wantsAsk(*p, m, s.Ask, wants.StepRunStepComposition)) + } + return asks, ended +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go index c4e693e3..d54f44a8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place_test.go @@ -40,7 +40,7 @@ func (s *stepAsks) AskStep(accept, id string, body any) error { func placeFixture() (catalog.Registration, map[string]catalog.CatalogEntry) { reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{ - Steps: catalog.StepStatuses{Lint: "required", Unit: "optional", Approval: "required"}, + Steps: catalog.StepStatuses{Lint: "required", Unit: "optional", Approval: "required", Validate: "bypass"}, Artifacts: map[string]catalog.StepStatuses{"tools": {Lint: "bypass"}}, }} return reg, map[string]catalog.CatalogEntry{ @@ -74,7 +74,7 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { want := []string{" build running", "app:program lint running", "app:program unit running", "app:program integration running", "app:tools lint bypassed", "app:tools unit running", "app:tools integration running", "app:web lint could not run", "app:web unit could not run", "app:web integration could not run", - " composition running", " review waiting", " approval waiting"} + " validate bypassed", " composition running", " review waiting", " approval waiting"} if strings.Join(got, "|") != strings.Join(want, "|") { t.Errorf("steps = %q, want %q", got, want) } @@ -120,7 +120,7 @@ func TestStartPlacesTheStepsThePolicyNamesAndAsksEachBuildSeat(t *testing.T) { // not due at its start (A-99, §26). func TestTheBuildHoldsTheApprovalWhateverThePolicyNames(t *testing.T) { reg, entries := placeFixture() - reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Approval: "required"}} + reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Approval: "required", Validate: "bypass"}} store := created{} s := &Starter{Pipelines: store, Say: func(string, any) error { return nil }, Steps: &stepAsks{}, Registration: func(string) (catalog.Registration, bool) { return reg, true }} @@ -161,7 +161,7 @@ func TestTheBuildStepsEndIsTakenOnItsOneEntry(t *testing.T) { // end is heard from that seat (design 47 G §22, §24; H H-A-88): a pipeline whose policy names it places it running with its own ask, a bypassed one asks no one. func TestCompositionIsAskedOfTheAssignerAndItsEndIsTaken(t *testing.T) { reg, entries := placeFixture() - reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Composition: "required", Approval: "required"}} + reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Composition: "required", Approval: "required", Validate: "bypass"}} p := seat.Pipeline{Pipeline: "main.4", Branch: "main", Revision: 7, Source: 4, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}} steps, asked := Place(p, p.Movers[0], reg, entries, time.Unix(1, 0), "the-runner") var comp seat.StepResult @@ -303,7 +303,7 @@ func TestAStepAskCarriesTheKeptResultsAndTheToolchain(t *testing.T) { // artifact's lint, unit and integration are bypassed whatever the policy says, asked of no one; an artifact whose language no // build seat serves stays could not run, naming it (§535). func TestAnArtifactWithoutALanguageIsPlacedByItsKind(t *testing.T) { - reg := catalog.Registration{Module: "app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required"}}} + reg := catalog.Registration{Module: "app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required", Validate: "bypass"}}} entries := map[string]catalog.CatalogEntry{ "app": {Module: "app", Artifacts: []catalog.Artifact{{Ref: "app:server", Kind: "image"}, {Ref: "app:files", Kind: "archive"}, {Ref: "app:mirror", Kind: "upstream"}, {Ref: "app:web", Language: "rust"}, {Ref: "app:lib", Language: "typescript"}, {Ref: "app:cli", Language: "go"}}}, @@ -557,7 +557,7 @@ func TestASeatWithNoHolderIsReadFromTheSeatHoldersView(t *testing.T) { // step naming its mover, and each ask id names its mover, so the same step of two movers is two asks. func TestEachMoverIsPlacedFromItsOwnRegistrationAndEntry(t *testing.T) { reg, entries := placeFixture() - lib := catalog.Registration{Module: "lib", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required"}}} + lib := catalog.Registration{Module: "lib", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", Validate: "bypass"}}} entries["lib"] = catalog.CatalogEntry{Module: "lib", Path: "lib", Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go"}}} store := created{} asks := &stepAsks{} @@ -599,3 +599,63 @@ func TestEachMoverIsPlacedFromItsOwnRegistrationAndEntry(t *testing.T) { } } } + +// R9/AC1 (design 47 H §745, H-A-51, acceptance test 117's runner half): validate is placed before composition, one ask of +// the seat mesh-wants for the pipeline that every mover's validate step reads; a mover's composition is asked only once +// validate passed; validate ending failed asks no composition and ends each not asked, so a required one fails the pipeline. +func TestValidateComesBeforeCompositionAndAFailureAsksNone(t *testing.T) { + for _, outcome := range []string{seat.StepResultOutcomePassed, seat.StepResultOutcomeFailed} { + reg, entries := placeFixture() + reg.Policy = catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "bypass", Integration: "bypass", Validate: "required", Composition: "required"}} + entries["lib"] = catalog.CatalogEntry{Module: "lib", Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go"}}} + mem := memStore{} + asks := &stepAsks{} + s := &Starter{Pipelines: memCreated{mem}, Store: mem, Say: func(string, any) error { return nil }, Steps: asks, Name: "the-runner", + Registration: func(string) (catalog.Registration, bool) { return reg, true }} + if ok, err := s.Start(Begin{Branch: "main", Source: 4, Revision: 7, Entries: entries, Movers: []seat.Mover{ + {Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, {Module: "lib", Commit: "c2", Fingerprint: "src2:bb"}}}); !ok || err != nil { + t.Fatalf("start = %v, %v", ok, err) + } + validates, compositions := 0, 0 + var validateAsk string + for i, a := range asks.asks { + if r, ok := a.(wants.StepRun); ok { + switch r.Step { + case wants.StepRunStepValidate: + validates, validateAsk = validates+1, asks.ids[i] + case wants.StepRunStepComposition: + compositions++ + } + } + } + p, _, _ := mem.Get("main.4") + if validates != 1 || compositions != 0 || stepNamed(p, "", seat.StepResultStepComposition).Outcome != seat.StepResultOutcomeWaiting { + t.Fatalf("placed: %d validate and %d composition asks, steps %+v; want one validate, no composition yet", validates, compositions, p.Steps) + } + h := &Hearer{Store: mem, Name: "the-runner", Say: func(string, any) error { return nil }, AskSteps: s.AskSteps} + bs := stepSeatOf(t, wants.Seat) + raw := `{"id":"` + validateAsk + `","pipeline":"main.4","step":"validate","module":"app","commit":"c1","fingerprint":"src2:aa","node":"n1","outcome":"` + outcome + `","said":"manifest-refused: app names an unknown field"}` + ev, err := bs.Decode([]byte(raw)) + if err != nil { + t.Fatal(err) + } + before := len(asks.asks) + if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", ev); err != nil { + t.Fatal(err) + } + p, _, _ = mem.Get("main.4") + for _, st := range p.Steps { + if st.Step == seat.StepResultStepValidate && st.Outcome != outcome { + t.Errorf("%s: %s's validate is %s, want every mover's read from the one run", outcome, st.Module, st.Outcome) + } + } + asked := len(asks.asks) - before + comp := stepNamed(p, "", seat.StepResultStepComposition) + if outcome == seat.StepResultOutcomePassed && (asked != 2 || comp.Outcome != seat.StepResultOutcomeRunning || comp.Ask == "") { + t.Errorf("validate passed: %d asks, composition %+v; want both movers' compositions asked", asked, comp) + } + if outcome == seat.StepResultOutcomeFailed && (asked != 0 || comp.Outcome != seat.StepResultOutcomeNotAsked || !strings.Contains(comp.Why, "validate ended failed")) { + t.Errorf("validate failed: %d asks, composition %+v; want none asked and it ended not asked", asked, comp) + } + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/registrations.go b/modules/mesh-delivery-pipeline/internal/pipeline/registrations.go index 0016e988..751fbf9a 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/registrations.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/registrations.go @@ -32,6 +32,8 @@ func Status(reg catalog.Registration, artifact, step string) string { func statusOf(s catalog.StepStatuses, step string) string { switch step { + case seat.StepResultStepValidate: + return s.Validate case seat.StepResultStepLint: return s.Lint case seat.StepResultStepUnit: diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index a6f68a8d..8d3f13a6 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -318,13 +318,50 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog continue } steps, a := Place(*p, m, r, entries, now, s.Name) + // The pipeline's validate is one run (§745, H-A-51): a mover placed after it was asked reads it, its result too + // when it ended. + if j := validateStep(*p); j >= 0 { + a = slices.DeleteFunc(a, func(x Asked) bool { return x.ID == p.Steps[j].Ask }) + for k := range steps { + if steps[k].Step == seat.StepResultStepValidate && steps[k].Ask == p.Steps[j].Ask && !open(p.Steps[j]) { + v := p.Steps[j] + steps[k].Outcome, steps[k].Why, steps[k].Node, steps[k].Ended = v.Outcome, v.Why, v.Node, v.Ended + } + } + } p.Steps = append(p.Steps, steps...) - asks = append(asks, a...) + for _, x := range a { + if !slices.ContainsFunc(asks, func(y Asked) bool { return y.ID == x.ID }) { + asks = append(asks, x) + } + } } + // A mover placed after the validate ended has its composition asked, or not asked, at once (§745). + more, _ := releaseCompositions(p, now) + asks = append(asks, more...) asks, ended := s.holderless(p, asks, now) return asks, unregistered, ended } +// AskSteps puts the asks of pipeline key and says their step-started (askSteps), for the hearer's asks of a step another's +// end made due: a mover's composition once validate passed (§745). +func (s *Starter) AskSteps(key string, asks []Asked) error { + if s.Steps == nil || len(asks) == 0 { + return nil + } + return s.askSteps(key, asks) +} + +// validateStep is the index of p's first validate step that names its ask, -1 when it has none. +func validateStep(p seat.Pipeline) int { + for i, st := range p.Steps { + if st.Step == seat.StepResultStepValidate && st.Ask != "" { + return i + } + } + return -1 +} + // Start writes b's pipeline, running, and says pipeline-started; false, nil when its key was written already (the second // start writes nothing, §746). func (s *Starter) Start(b Begin) (bool, error) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index aa09ff98..81b7ae21 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -149,6 +149,9 @@ type Hearer struct { DropRun Drop // RunOutputs keeps a test run's output in test-runs-objects (§725, A-466v). RunOutputs RunObjects + // AskSteps puts the asks a step's end made due, a mover's composition once validate passed (§745; Starter.AskSteps); + // nil asks none. + AskSteps func(key string, asks []Asked) error } // EndReaders ends each of readers' steps of run with r's result (§725, §726): a step that read an ended run, or the steps @@ -254,6 +257,15 @@ func (h *Hearer) OnStepEndedShared(bs StepSeat, subject string, ev StepEnded, sh p.Unlogged = append(p.Unlogged, unlogged) // The steps of this pipeline reading the run end in the same write, so the pipeline ends once (§726, §727). readers := h.sameRunReaders(&p, i, ev, now) + // Every mover's validate reads the one run (§745, H-A-51); its end asks each mover's composition, or ends it not + // asked when validate did not pass. + var due []Asked + if s.Step == seat.StepResultStepValidate { + readers = append(readers, sameValidate(&p, i, now)...) + var notAsked []int + due, notAsked = releaseCompositions(&p, now) + readers = append(readers, notAsked...) + } from := now if ev.Ended != nil { from = ev.Ended.UTC() @@ -294,6 +306,11 @@ func (h *Hearer) OnStepEndedShared(bs StepSeat, subject string, ev StepEnded, sh return p, fmt.Errorf("pipeline %s's %s is written but not said: %w", ev.Pipeline, seat.EventStepEnded, err) } } + if h.AskSteps != nil && len(due) > 0 { + if err := h.AskSteps(ev.Pipeline, due); err != nil { + h.logf("the compositions of %s are written running and not asked, asked again at the next start: %v", ev.Pipeline, err) + } + } // The step's end is written and said before its log entry is appended, so a log that refuses ends no step (§486, §606). h.appendUnlogged(ev.Pipeline) h.Ager.Age() @@ -607,3 +624,20 @@ func (h *Hearer) EndedAtPlacing(p seat.Pipeline, steps []int) error { } return first } + +// sameValidate ends, in p, every other mover's validate step reading the ask step i's end ended, with its result (§745, +// H-A-51). It answers their indexes. +func sameValidate(p *seat.Pipeline, i int, now time.Time) []int { + v := p.Steps[i] + var out []int + for j := range p.Steps { + s := &p.Steps[j] + if j == i || s.Step != seat.StepResultStepValidate || s.Ask != v.Ask || !open(*s) { + continue + } + s.Outcome, s.Why, s.Node, s.Ended = v.Outcome, v.Why, v.Node, &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *s, now)) + out = append(out, j) + } + return out +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index ba8ed993..780009af 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -88,7 +88,7 @@ type runFixture struct { func newRunFixture() *runFixture { f := &runFixture{store: memStore{}, runs: testRunsMem{}, objects: objectsMem{}, asks: &stepAsks{}} f.clock = &clockMem{runs: f.runs, bound: map[string]time.Duration{}} - reg := catalog.Registration{Module: "app", Branches: []string{"main"}} + reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Validate: "bypass"}}} say := func(_ string, body any) error { if e, ok := body.(seat.StepEvent); ok { f.said = append(f.said, e) @@ -353,7 +353,7 @@ func TestARerunOfATestRunMovesEveryReaderThatDidNotPass(t *testing.T) { accepted := c.accepted f := newRunFixture() reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", - Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass"}}} + Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass", Validate: "bypass"}}} f.s.Registration = func(string) (catalog.Registration, bool) { return reg, true } p := f.start(t, 4, 9) e := f.store[p.Pipeline] @@ -615,7 +615,7 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) { t.Run("the run ends before the step's finding is written", func(t *testing.T) { f := newRunFixture() reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", - Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass"}}} + Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass", Validate: "bypass"}}} f.s.Registration = func(string) (catalog.Registration, bool) { return reg, true } p := f.start(t, 4, 9) unit := stepNamed(p, "app:program", "unit")