diff --git a/modules/mesh-delivery-sdk/steprun/askrun.go b/modules/mesh-delivery-sdk/steprun/askrun.go index c37dae07d..c0ab6fc7e 100644 --- a/modules/mesh-delivery-sdk/steprun/askrun.go +++ b/modules/mesh-delivery-sdk/steprun/askrun.go @@ -84,7 +84,14 @@ func RunAsk(ctx context.Context, steps AskSteps, ask sdkstep.StepAsk) (any, erro if ask.Build != nil { job := *ask.Build job.Fetch = withPackages(job.Fetch, ask.Packages) - return steps.build(ctx, job, ask.Version) + out, err := steps.build(ctx, job, ask.Version) + var dec *Declining + if err != nil && !sdkstep.IsPassing(err) && !errors.As(err, &dec) && ctx.Err() == nil { + // A failed build keeps its error text, as the build module bounded it, as the ask's output object, header and + // text as a test step's, so the verb output answers why after the fact (design 47 H2 H-A-482 and its addendum (a)). + steps.keepRunOutput(ask.ID, err.Error(), nil) + } + return out, err } if ask.Step != nil || ask.Install != nil { return steps.runStep(ctx, ask) diff --git a/modules/mesh-delivery-sdk/steprun/askrun_test.go b/modules/mesh-delivery-sdk/steprun/askrun_test.go index 3ebd439ac..8e35229b7 100644 --- a/modules/mesh-delivery-sdk/steprun/askrun_test.go +++ b/modules/mesh-delivery-sdk/steprun/askrun_test.go @@ -117,6 +117,23 @@ imports {"module":"modules/m","workspace":"/w/1"}` if !slices.Equal(answer.Imports, []string{"git.novox.be/novox/mesh-sdk/go/announce", "git.novox.be/novox/mesh-sdk/go/health"}) { t.Errorf("the answer's imports are %v", answer.Imports) } + + // Design 47 H2 H-A-482 addendum (a): a failed build keeps its error text, as the build module bounded it, as the ask's + // output object, which the verb output answers. + outputs := fakeOutputs{m: map[string][]byte{}} + steps.Outputs, steps.Node = outputs, "ace" + steps.Build = func(context.Context, map[string]any) (any, error) { + return nil, errors.New("esbuild for code: status 1 | ✘ [ERROR] Could not resolve \"./missing\" … 812 bytes left out … main.js:1:1)") + } + failed := ask(sdkstep.BuildJob{Module: "m", Path: "modules/m", Fetch: &sdkstep.Fetch{Repository: "novox/x", Commit: runCommit}, + Artifacts: []sdkstep.AskArtifact{{Artifact: "bundle"}}}) + if _, err := RunAsk(context.Background(), steps, failed); err == nil { + t.Fatal("a failed build answered no error") + } + got2, err := readOutput(outputs, "ace", failed.ID, nil) + if err != nil || !strings.Contains(got2.Output, `bundle: esbuild for code: status 1 | ✘ [ERROR] Could not resolve "./missing"`) || got2.Size != len(got2.Output) { + t.Errorf("the failed build's output = %+v, %v; want its error text kept", got2, err) + } } // A build ask for another toolchain is declined (ADR 0584 clause 2), so the node sits out and the asker puts it again. diff --git a/modules/mesh-delivery-sdk/steprun/outputs.go b/modules/mesh-delivery-sdk/steprun/outputs.go index d7a4323cd..ca1188639 100644 --- a/modules/mesh-delivery-sdk/steprun/outputs.go +++ b/modules/mesh-delivery-sdk/steprun/outputs.go @@ -125,7 +125,8 @@ func EndedHere(node string, keys func() ([]string, error), get func(key string) // readOutput answers the verb output for ask (design 47 H2 §791, H-A-412): from the object `.`, the text's last // OutputTail bytes, its size and failing tests from the header; with no object, no longer kept when this node's steps key // shows the ask ended here more than OutputsMaxAge ago, and refused otherwise, naming why (an ask never run here, or one -// whose output this node did not keep). +// that kept no output). An empty object is no object (H-A-482): the runtime's object read answers an absent object as +// empty data without an error, which is not a header fault. func readOutput(o OutputObjects, node, ask string, ended func(ask string) (time.Time, bool, error)) (sdkstep.OutputAnswer, error) { if o == nil { return sdkstep.OutputAnswer{}, fmt.Errorf("this module keeps no %s store", OutputsStore) @@ -135,11 +136,14 @@ func readOutput(o OutputObjects, node, ask string, ended func(ask string) (time. return sdkstep.OutputAnswer{}, err } got, gerr := o.Get(name) - if gerr == nil { + if gerr == nil && len(got.Data) > 0 { return outputOf(ask, got.Data) } + if gerr == nil { + gerr = fmt.Errorf("the object %s in the %s store is empty", name, OutputsStore) + } if ended == nil { - return sdkstep.OutputAnswer{}, fmt.Errorf("the output %s in the %s store: %w", name, OutputsStore, gerr) + return sdkstep.OutputAnswer{}, fmt.Errorf("the ask %s kept no output: %w", ask, gerr) } at, here, err := ended(ask) switch { @@ -150,7 +154,7 @@ func readOutput(o OutputObjects, node, ask string, ended func(ask string) (time. case !at.IsZero() && now().Sub(at) > OutputsMaxAge: return sdkstep.OutputAnswer{Ask: ask, NoLongerKept: true}, nil default: - return sdkstep.OutputAnswer{}, fmt.Errorf("the ask %s ran on %s, and its output is not in the %s store: %w", ask, node, OutputsStore, gerr) + return sdkstep.OutputAnswer{}, fmt.Errorf("the ask %s ran on %s, and the ask kept no output: %w", ask, node, gerr) } } diff --git a/modules/mesh-delivery-sdk/steprun/outputs_test.go b/modules/mesh-delivery-sdk/steprun/outputs_test.go index 7e26a5e03..d83bc6acb 100644 --- a/modules/mesh-delivery-sdk/steprun/outputs_test.go +++ b/modules/mesh-delivery-sdk/steprun/outputs_test.go @@ -64,7 +64,9 @@ func TestOutputsKeptAreRead(t *testing.T) { return raw } steps := map[string]json.RawMessage{"mesh-delivery-pipeline.ace.a2": step(at.Add(-OutputsMaxAge - time.Hour)), "mesh-delivery-pipeline.ace.a3": step(at.Add(-time.Hour)), - "mesh-delivery-pipeline.g14.a4": step(at.Add(-OutputsMaxAge - time.Hour))} + "mesh-delivery-pipeline.g14.a4": step(at.Add(-OutputsMaxAge - time.Hour)), "mesh-delivery-pipeline.ace.a6": step(at.Add(-time.Hour))} + // H-A-482: the runtime's object read answers an absent object as empty data, no error; that is no output, not a header fault. + out.m["ace.a6"] = []byte{} keys := func() ([]string, error) { return slices.Collect(func(y func(string) bool) { for k := range steps { @@ -82,7 +84,8 @@ func TestOutputsKeptAreRead(t *testing.T) { }{ {ask: "a1", want: sdkstep.OutputAnswer{Ask: "a1", Output: long[len(long)-OutputTail:], Size: len(long), Failing: failing}}, {ask: "a2", want: sdkstep.OutputAnswer{Ask: "a2", NoLongerKept: true}}, - {ask: "a3", fail: "ran on ace, and its output is not in the outputs store"}, + {ask: "a3", fail: "ran on ace, and the ask kept no output"}, + {ask: "a6", fail: "ran on ace, and the ask kept no output: the object ace.a6 in the outputs store is empty"}, {ask: "a4", fail: "never ran on ace"}, {ask: "a5", fail: "never ran on ace"}, {fail: "asked for no ask"}, diff --git a/modules/mesh-delivery-sdk/steprun/steprun.go b/modules/mesh-delivery-sdk/steprun/steprun.go index ac8029b0f..19c615b4d 100644 --- a/modules/mesh-delivery-sdk/steprun/steprun.go +++ b/modules/mesh-delivery-sdk/steprun/steprun.go @@ -267,8 +267,9 @@ func (s AskSteps) testStep(ctx context.Context, ask sdkstep.StepAsk, end *sdkste return nil } -// keepRunOutput keeps a test step's level text as the run's output `.` in the outputs objects, with the -// header of the failing tests and their words from the level's results (design 47 H2 §791, H-A-412 (1)). A holder that +// keepRunOutput keeps a test step's level text, or a failed build's error text (H-A-482), as the run's output `.` in the outputs objects, with the header of the failing tests and their words from the level's results (design 47 +// H2 §791, H-A-412 (1)). A holder that // keeps no outputs, or a write that fails, is said in the journal: the step's end stands on the results. func (s AskSteps) keepRunOutput(ask, text string, failed []sdkstep.Failure) { var failing []sdkstep.FailingTest