From cf703c2a7bf7184ccfba6dd605c525144e3735ae Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:57:11 +0100 Subject: [PATCH] H-A-101: the hand verbs name the mover's module; a step not asked says its own end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rerun, accept and ask-again take the mover's module beside the pipeline and step (C-R4): a call naming none is taken as the pipeline's one mover and refused on a pipeline of several, and a module the pipeline does not move is refused; the tools runner_rerun, runner_accept and runner_ask_again pass it. A step of a mover whose dependency did not build, placed not asked, now says its own step-ended naming the dependency, so nothing ends silently. Builds: design 47 H §746, §748; lead answer H-A-101 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../cmd/mesh-delivery-pipeline-tools/rerun.go | 3 +- .../mesh-delivery-pipeline-tools/verbtools.go | 8 ++--- .../internal/pipeline/order_test.go | 18 +++++++++- .../internal/pipeline/run.go | 5 +-- .../internal/pipeline/start.go | 34 +++++++++++++++---- .../internal/pipeline/verbs.go | 31 +++++++++++------ .../internal/pipeline/verbs_test.go | 27 +++++++++++++++ 7 files changed, 101 insertions(+), 25 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/rerun.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/rerun.go index 4a43cb54..de1dc8b1 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/rerun.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/rerun.go @@ -15,9 +15,10 @@ import ( // cancelled or superseded pipeline, and runs a failed pipeline again. func RerunTool(ask func(key string, body any) (json.RawMessage, error)) stdio.Tool { return stdio.Tool{Name: Prefix + "_rerun", - Description: "Ask one step of a pipeline again by the seat verb rerun: the pipeline's key, the step (build, lint, unit, integration, composition, review), the artifact where the step is per artifact, and why. A failed pipeline runs again; a running step, or a cancelled or superseded pipeline, is refused by the verb, whole.", + Description: "Ask one step of a pipeline again by the seat verb rerun: the pipeline's key, the step (build, lint, unit, integration, composition, review), the mover's module (needed when the pipeline moves several), the artifact where the step is per artifact, and why. A failed pipeline runs again; a running step, or a cancelled or superseded pipeline, is refused by the verb, whole.", Input: map[string]any{"type": "object", "properties": map[string]any{ "pipeline": map[string]any{"type": "string"}, + "module": map[string]any{"type": "string"}, "step": map[string]any{"type": "string"}, "artifact": map[string]any{"type": "string"}, "why": map[string]any{"type": "string"}, diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/verbtools.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/verbtools.go index 4899f6aa..b089c82f 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/verbtools.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/verbtools.go @@ -37,8 +37,8 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio. return "" }), verbTool[seat.AcceptInput](ask, "accept", seat.VerbAccept, - "Accept one step of a pipeline by hand by the seat verb accept: the pipeline's key, the step, the artifact where the step is per artifact, and why.", - obj([]string{"pipeline", "step", "why"}, map[string]any{"pipeline": str, "step": str, "artifact": str, "why": str}), + "Accept one step of a pipeline by hand by the seat verb accept: the pipeline's key, the mover's module (needed when the pipeline moves several), the step, the artifact where the step is per artifact, and why.", + obj([]string{"pipeline", "step", "why"}, map[string]any{"pipeline": str, "module": str, "step": str, "artifact": str, "why": str}), func(in seat.AcceptInput) string { if in.Pipeline == "" || in.Step == "" { return "accept names the pipeline and the step" @@ -46,8 +46,8 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio. return whyOf(in.Why) }), verbTool[seat.AskAgainInput](ask, "ask_again", seat.VerbAskAgain, - "Ask a declined approval step of a pipeline once more by the seat verb ask-again: the pipeline's key and why.", - obj([]string{"pipeline", "why"}, map[string]any{"pipeline": str, "why": str}), + "Ask a declined approval step of a pipeline once more by the seat verb ask-again: the pipeline's key, the mover's module (needed when the pipeline moves several) and why.", + obj([]string{"pipeline", "why"}, map[string]any{"pipeline": str, "module": str, "why": str}), func(in seat.AskAgainInput) string { if in.Pipeline == "" { return "ask-again names the pipeline" diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go index b9fd84a4..a5dff3bb 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go @@ -99,12 +99,28 @@ func TestAMoversBuildWaitsForItsDependenciesInThePipeline(t *testing.T) { if p, _, _ = mem.Get("main.4"); !placed(p, "tool") || stepsOf(p, "tool")[0].Outcome != seat.StepResultOutcomeRunning { t.Errorf("after builder's build passed, tool's steps = %+v, want placed and asked", stepsOf(p, "tool")) } - // The same pipeline, builder's build failed: tool is placed with every step not asked. + // The same pipeline, builder's build failed: tool is placed with every step not asked, each saying its own step-ended + // naming the dependency (H-A-101 (2)). mem["main.4"] = before + var notAsked []seat.StepEvent + s.Say = func(subject string, body any) error { + if ev, ok := body.(seat.StepEvent); ok && strings.Contains(subject, ".step-ended.tool.") { + notAsked = append(notAsked, ev) + } + return nil + } if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", end("failed")); err != nil { t.Fatal(err) } if p, _, _ = mem.Get("main.4"); !placed(p, "tool") || stepsOf(p, "tool")[0].Outcome != seat.StepResultOutcomeNotAsked { t.Errorf("after builder's build failed, tool's steps = %+v, want placed not asked", stepsOf(p, "tool")) } + if len(notAsked) == 0 || len(notAsked) != len(slices.DeleteFunc(stepsOf(p, "tool"), func(st seat.StepResult) bool { return st.Outcome != seat.StepResultOutcomeNotAsked })) { + t.Fatalf("tool's not-asked steps said %d step-ended, want one each", len(notAsked)) + } + for _, ev := range notAsked { + if ev.Result.Outcome != seat.StepResultOutcomeNotAsked || !strings.Contains(ev.Result.Why, "builder") { + t.Errorf("tool's step-ended = %+v, want not asked naming builder", ev.Result) + } + } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/run.go b/modules/mesh-delivery-pipeline/internal/pipeline/run.go index ceab2baf..02926744 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/run.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/run.go @@ -223,10 +223,10 @@ func (s *Starter) placeRunPipeline(key, id string, ev catalog.CatalogRevisionEve } p.Movers, p.Revision = Tiers(movers, half.Entries, s.logf), ev.Revision var asks []Asked - var ended []int + var ended, notAsked []int if s.Registration != nil { var unregistered []string - asks, unregistered, ended = s.placeMovers(&p, s.Registration, half.Entries, now) + asks, unregistered, ended, notAsked = s.placeMovers(&p, s.Registration, half.Entries, now) for _, m := range unregistered { s.logf("%s: %s has no registration yet: its mover is placed with no step", key, m) } @@ -237,6 +237,7 @@ func (s *Starter) placeRunPipeline(key, id string, ev catalog.CatalogRevisionEve return false, fmt.Errorf("the pipeline %s cannot be written: %w", key, err) } s.sayStartedPipeline(p, now) + s.sayNotAsked(p, notAsked) if len(ended) > 0 { return true, s.endedAtPlacing(p, ended) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index 6ba88aae..97db1618 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -304,11 +304,13 @@ func (s *Starter) sayStartedPipeline(p seat.Pipeline, at time.Time) { } // placeMovers places the steps of each mover of p that has none and whose registration reg names (§746): each mover's from -// its own registration and entry. It answers the asks to put, the movers still without a registration, and the steps the -// placing ended at once (holderless). -func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog.Registration, bool), entries map[string]catalog.CatalogEntry, now time.Time) ([]Asked, []string, []int) { +// its own registration and entry. It answers the asks to put, the movers still without a registration, the steps the +// placing ended at once (holderless), and the steps it placed not asked because a dependency did not build (H-A-101 (2)), +// each said by sayNotAsked once the pipeline is written. +func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog.Registration, bool), entries map[string]catalog.CatalogEntry, now time.Time) ([]Asked, []string, []int, []int) { var asks []Asked var unregistered []string + var notAsked []int for _, m := range p.Movers { if placed(*p, m.Module) { continue @@ -335,6 +337,7 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog } st.Outcome, st.Why, st.Ask, st.Shared, st.Ended = seat.StepResultOutcomeNotAsked, why, "", nil, &now p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now)) + notAsked = append(notAsked, len(p.Steps)+k) } p.Steps = append(p.Steps, steps...) continue @@ -361,7 +364,22 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog more, _ := releaseCompositions(p, now) asks = append(asks, more...) asks, ended := s.holderless(p, asks, now) - return asks, unregistered, ended + return asks, unregistered, ended, notAsked +} + +// sayNotAsked says the step-ended of each step of p placed not asked because its mover's dependency did not build, naming +// the dependency in its why, so no step ends silently (H-A-101 (2)). +func (s *Starter) sayNotAsked(p seat.Pipeline, steps []int) { + if s.Say == nil { + return + } + at := s.now() + for _, i := range steps { + subject, ev := stepEvent(seat.EventStepEnded, p, p.Steps[i], at) + if err := s.Say(subject, ev); err != nil { + s.logf("step-ended of %s's %s %s, not asked, is not said: %v", p.Pipeline, p.Steps[i].Module, p.Steps[i].Step, err) + } + } } // AskSteps puts the asks of pipeline key and says their step-started (askSteps), for the hearer's asks of a step another's @@ -399,12 +417,12 @@ func (s *Starter) Start(b Begin) (bool, error) { } p := newPipeline(b, key, now) var asks []Asked - var ended []int + var ended, notAsked []int if b.unheld { s.logf("%s starts with no step: the catalog half of %s is not held yet, and its steps are placed once it is (A-336)", key, b.Branch) } else if s.Registration != nil { var unregistered []string - asks, unregistered, ended = s.placeMovers(&p, s.Registration, b.Entries, now) + asks, unregistered, ended, notAsked = s.placeMovers(&p, s.Registration, b.Entries, now) for _, m := range unregistered { s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m) } @@ -416,6 +434,7 @@ func (s *Starter) Start(b Begin) (bool, error) { return false, fmt.Errorf("the pipeline %s is not written: %w", key, err) } s.sayStartedPipeline(p, now) + s.sayNotAsked(p, notAsked) if len(ended) > 0 { return true, s.endedAtPlacing(p, ended) } @@ -563,7 +582,7 @@ func (s *Starter) placeWaiting(store Updater, due func(seat.Pipeline) bool, reg continue } before := len(p.Steps) - asks, _, ended := s.placeMovers(&p, reg, half.Entries, now) + asks, _, ended, notAsked := s.placeMovers(&p, reg, half.Entries, now) if len(p.Steps) == before { continue } @@ -576,6 +595,7 @@ func (s *Starter) placeWaiting(store Updater, due func(seat.Pipeline) bool, reg // A pipeline whose steps were never asked is started by this placing (A-446a); the pipeline-started of its start, // said already, is said again harmlessly. s.sayStartedPipeline(p, now) + s.sayNotAsked(p, notAsked) if len(ended) > 0 { if err := s.endedAtPlacing(p, ended); err != nil { note(err) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 614806db..216580f8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -148,11 +148,22 @@ func reviewWaiting(p seat.Pipeline, module string) int { return -1 } -// stepOf is the index of the step named, and of its artifact when one is named. -func stepOf(p seat.Pipeline, step, artifact string) (int, error) { +// stepOf is the index of the step named, of the mover module and of its artifact when one is named (H-A-101 (1)): a call +// naming no module is taken as the pipeline's one mover, and refused on a pipeline of several, so it is never ambiguous. +func stepOf(p seat.Pipeline, module, step, artifact string) (int, error) { + if module == "" { + if len(p.Movers) > 1 { + return -1, fmt.Errorf("%s moves %d modules: name the module whose %s step is meant", p.Pipeline, len(p.Movers), step) + } + if len(p.Movers) == 1 { + module = p.Movers[0].Module + } + } else if !Moves(p, module) { + return -1, fmt.Errorf("%s does not move %s", p.Pipeline, module) + } found := -1 for i, s := range p.Steps { - if s.Step != step || (artifact != "" && s.Artifact != artifact) { + if s.Step != step || (module != "" && s.Module != module) || (artifact != "" && s.Artifact != artifact) { continue } if found >= 0 { @@ -171,7 +182,7 @@ func (v Verbs) Accept(caller string, in seat.AcceptInput) (seat.AcceptAnswer, er p, i, err := v.change(in.Pipeline, seat.EventStepEnded, func() error { return v.record(seat.VerbAccept, fmt.Sprintf("accepted the failed %s step of %s", in.Step, in.Pipeline), in.Why) }, func(p *seat.Pipeline, now time.Time) (int, error) { - i, err := stepOf(*p, in.Step, in.Artifact) + i, err := stepOf(*p, in.Module, in.Step, in.Artifact) if err != nil { return -1, err } @@ -242,7 +253,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error return seat.RerunAnswer{}, errors.New("an approval is asked again by ask-again, not rerun") } if p, _, err := v.Hearer.Store.Get(in.Pipeline); err == nil { - if i, err := stepOf(p, in.Step, in.Artifact); err == nil && v.Hearer.TestRuns != nil && sharedRun(p.Steps[i]) != "" && BoundSeat(p.Steps[i].Seat) { + if i, err := stepOf(p, in.Module, in.Step, in.Artifact); err == nil && v.Hearer.TestRuns != nil && sharedRun(p.Steps[i]) != "" && BoundSeat(p.Steps[i].Seat) { return v.rerunTest(caller, in, p.Steps[i]) } } @@ -255,7 +266,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded: return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome) } - i, err := stepOf(*p, in.Step, in.Artifact) + i, err := stepOf(*p, in.Module, in.Step, in.Artifact) if err != nil { return -1, err } @@ -296,7 +307,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err) } } - res, err := stepOf(p, in.Step, in.Artifact) + res, err := stepOf(p, in.Module, in.Step, in.Artifact) if err != nil { return seat.RerunAnswer{}, err } @@ -351,7 +362,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult) case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded: return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome) } - i, err := stepOf(*p, in.Step, in.Artifact) + i, err := stepOf(*p, in.Module, in.Step, in.Artifact) if err != nil { return -1, err } @@ -443,7 +454,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult) return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err) } } - i, err := stepOf(p, in.Step, in.Artifact) + i, err := stepOf(p, in.Module, in.Step, in.Artifact) if err != nil { return seat.RerunAnswer{}, err } @@ -580,7 +591,7 @@ func (v Verbs) AskAgain(caller string, in seat.AskAgainInput) (seat.AskAgainAnsw case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded: return -1, fmt.Errorf("the pipeline %s is %s: its approval is not asked again", p.Pipeline, p.Outcome) } - i, err := stepOf(*p, seat.StepResultStepApproval, "") + i, err := stepOf(*p, in.Module, seat.StepResultStepApproval, "") if err != nil { return -1, err } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go index 35492562..93db1039 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go @@ -155,6 +155,33 @@ func TestAcceptRerunAndCancelWriteByCompareAndSetAndRecordTheirHandAct(t *testin if n := len(*acts); n != 3 { t.Errorf("%d hand acts recorded, want accept, rerun, cancel (3): %v", n, *acts) } + + // H-A-101 (1): on a pipeline of two movers a verb names the mover's module; one naming none, or a module the pipeline + // does not move, is refused, and the module named picks that mover's step. + two, store2, _, _, _, _ := verbsFixture() + reg, entries := placeFixture() + entries["lib"] = catalog.CatalogEntry{Module: "lib", Commit: "c0", Fp: "src2:lib", Repository: "o/lib", Artifacts: entries["app"].Artifacts} + p2, rev2, _ := store2.Get(pkey) + lib := seat.Mover{Module: "lib", Commit: "c0", Fingerprint: "src2:lib", Repository: "o/lib"} + p2.Movers = append(p2.Movers, lib) + libSteps, _ := Place(p2, lib, reg, entries, time.Unix(1, 0), "the-runner") + art := "" + for i := range libSteps { + if libSteps[i].Step == "unit" && art == "" { + libSteps[i].Outcome, art = seat.StepResultOutcomeFailed, libSteps[i].Artifact + } + } + p2.Steps = append(p2.Steps, libSteps...) + store2.Update(pkey, p2, rev2) + if _, err := two.Accept("operator", seat.AcceptInput{Pipeline: pkey, Step: "unit", Artifact: art, Why: "flaky"}); err == nil || !strings.Contains(err.Error(), "name the module") { + t.Errorf("an accept naming no module on two movers = %v, want refused", err) + } + if _, err := two.Accept("operator", seat.AcceptInput{Pipeline: pkey, Module: "other", Step: "unit", Artifact: art, Why: "flaky"}); err == nil { + t.Error("an accept naming a module the pipeline does not move was taken") + } + if a, err := two.Accept("operator", seat.AcceptInput{Pipeline: pkey, Module: "lib", Step: "unit", Artifact: art, Why: "flaky"}); err != nil || a.Result.Module != "lib" || a.Result.Outcome != "accepted" { + t.Errorf("an accept of lib's unit = %+v, %v", a.Result, err) + } } // A-222: a rerun of a run's step asks with the candidate's catalog half (its entries, here the directory), never the branch's,