diff --git a/modules/mesh-delivery-sdk/steprun/askrun.go b/modules/mesh-delivery-sdk/steprun/askrun.go index 935ad7b6..93f18ec5 100644 --- a/modules/mesh-delivery-sdk/steprun/askrun.go +++ b/modules/mesh-delivery-sdk/steprun/askrun.go @@ -3,6 +3,7 @@ package steprun import ( "context" "encoding/json" + "errors" "fmt" "maps" "path" @@ -56,6 +57,20 @@ type AskSteps struct { SayStep func(end sdkstep.StepEnded) error } +// SaysItsEnds is nil when these steps can be asked a pipeline step and say its end: a node to name in the end and a SayStep to +// publish it (design 47 G *Asked on a work queue, ended by an event*, §24). A build module whose steps cannot is refused where +// it is built (conformance.StepEnds, which every build module's test runs, and the catalogue check failurekit), never +// discovered live as a step ask refused with "says no step's end". +func (s AskSteps) SaysItsEnds() error { + switch { + case s.SayStep == nil: + return errors.New("its AskSteps has no SayStep, so a step ask is refused: set it to SayStepOn the seat's language and node") + case s.Node == "": + return errors.New("its AskSteps names no Node, so the end of a step ask names no node") + } + return nil +} + // RunAsk runs ask's job with steps and answers a sdkstep.BuildAnswer or a sdkstep.CheckAnswer. func RunAsk(ctx context.Context, steps AskSteps, ask sdkstep.StepAsk) (any, error) { if ask.Build != nil { diff --git a/modules/mesh-delivery-sdk/steprun/conformance/conformance.go b/modules/mesh-delivery-sdk/steprun/conformance/conformance.go index f04eadbb..05d3a4f1 100644 --- a/modules/mesh-delivery-sdk/steprun/conformance/conformance.go +++ b/modules/mesh-delivery-sdk/steprun/conformance/conformance.go @@ -12,6 +12,7 @@ package conformance import ( "embed" "fmt" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" "slices" "strings" "testing" @@ -277,3 +278,13 @@ func judgePassing(c PassingCase, failed Failed) string { } return "" } + +// StepEnds is the case every build module runs on the steps it asks with: a pipeline step ask must be able to say its end +// (steprun.AskSteps.SaysItsEnds), or the module would refuse every step ask the runner sends, as mesh-build-node did on its +// first live pipeline (design 47 G §24). A catalogue check (failurekit) refuses a build module whose tests do not call it. +func StepEnds(t *testing.T, steps steprun.AskSteps) { + t.Helper() + if err := steps.SaysItsEnds(); err != nil { + t.Errorf("the build module's steps cannot say a step's end: %v", err) + } +} diff --git a/modules/mesh-delivery-sdk/steprun/conformance/conformance_test.go b/modules/mesh-delivery-sdk/steprun/conformance/conformance_test.go index 159c5acc..e24f65bd 100644 --- a/modules/mesh-delivery-sdk/steprun/conformance/conformance_test.go +++ b/modules/mesh-delivery-sdk/steprun/conformance/conformance_test.go @@ -181,3 +181,18 @@ func TestTheFailureContract(t *testing.T) { } }) } + +// A build module whose steps cannot say a step's end fails the case; one that can passes. +func TestStepEndsRefusesStepsThatCannotSayTheirEnd(t *testing.T) { + say := func(sdkstep.StepEnded) error { return nil } + for _, c := range []struct { + name string + s steprun.AskSteps + bad bool + }{{"no SayStep", steprun.AskSteps{Node: "n"}, true}, {"no node", steprun.AskSteps{SayStep: say}, true}, {"both", steprun.AskSteps{Node: "n", SayStep: say}, false}} { + if (c.s.SaysItsEnds() != nil) != c.bad { + t.Errorf("%s: SaysItsEnds = %v, want refused %v", c.name, c.s.SaysItsEnds(), c.bad) + } + } + StepEnds(t, steprun.AskSteps{Node: "n", SayStep: say}) +}