A test step takes the level's text out of its test answers (their member output) and keeps it in the holder's outputs objects as <node>.<ask id>, a header of its size and the failing tests with their words from the level's results beside the text; a check ask's answer keeps none. The verb output at the part's form 2 takes the ask and answers the text's last 64 KB, its size and the failing tests from the header; no-longer-kept only when this node's steps key shows the ask ended more than the max-age (7 days) ago, an ask never run here refused naming it. Builds: design 47 H2 §791, §820; H-A-367 (1), H-A-412 (1) and its second and third addenda
103 lines
4.0 KiB
Go
103 lines
4.0 KiB
Go
package steprun
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
)
|
|
|
|
type fakeOutputs struct{ m map[string][]byte }
|
|
|
|
func (f fakeOutputs) Put(name string, data []byte, _ string) (buscalls.ObjectInfo, error) {
|
|
f.m[name] = data
|
|
return buscalls.ObjectInfo{}, nil
|
|
}
|
|
func (f fakeOutputs) Get(name string) (buscalls.ObjectData, error) {
|
|
d, ok := f.m[name]
|
|
if !ok {
|
|
return buscalls.ObjectData{}, errors.New("object not found")
|
|
}
|
|
return buscalls.ObjectData{Data: d}, nil
|
|
}
|
|
|
|
// Design 47 G A-254: what a holder keeps through KeepAnswerIn it reads again through ReadAnswerFrom; with no store both refuse by name.
|
|
func TestOutputsKeptAreRead(t *testing.T) {
|
|
st := fakeOutputs{m: map[string][]byte{}}
|
|
if err := KeepAnswerIn(st)("answer.a1", []byte("x")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := ReadAnswerFrom(st)("answer.a1"); err != nil || string(got) != "x" {
|
|
t.Fatalf("read %q, %v", got, err)
|
|
}
|
|
if _, err := ReadAnswerFrom(st)("answer.none"); err == nil {
|
|
t.Fatal("an absent answer was read")
|
|
}
|
|
// Design 47 H2 H-A-412 addendum: a kept end is in the steps state's own objects, not in the `outputs` objects.
|
|
if err := KeepAnswerIn(nil)("o", nil); err == nil || !strings.Contains(err.Error(), "no steps-objects store") {
|
|
t.Fatalf("no store kept an answer, or did not name the steps objects: %v", err)
|
|
}
|
|
if _, err := ReadAnswerFrom(nil)("o"); err == nil {
|
|
t.Fatal("no store read an answer")
|
|
}
|
|
|
|
// Design 47 H2 §791, H-A-412: the verb output answers a run's output `<node>.<ask>` from its header and its text's last
|
|
// 64 KB; with no object, no longer kept once this node's steps key shows the ask ended more than the max-age ago, and
|
|
// refused for an ask never run here or one whose output this node did not keep.
|
|
was := now
|
|
defer func() { now = was }()
|
|
at := time.Date(2026, 11, 22, 1, 0, 0, 0, time.UTC)
|
|
now = func() time.Time { return at }
|
|
long := strings.Repeat("x", OutputTail) + "the end\n"
|
|
failing := []sdkstep.FailingTest{{Test: "x/b TestU", Words: "got 1, want 2"}}
|
|
out := fakeOutputs{m: map[string][]byte{}}
|
|
if err := keepOutput(out, "ace", "a1", long, failing); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
step := func(ended time.Time) json.RawMessage {
|
|
raw, _ := sdkstep.EncodeStep(sdkstep.Step{ID: "a2", Tool: "step", Node: "ace", State: sdkstep.StepPassed, Started: ended, Ended: ended})
|
|
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))}
|
|
keys := func() ([]string, error) {
|
|
return slices.Collect(func(y func(string) bool) {
|
|
for k := range steps {
|
|
y(k)
|
|
}
|
|
}), nil
|
|
}
|
|
tool := OutputTool("node-build-go", "ace", out, EndedHere("ace", keys, func(k string) (json.RawMessage, error) { return steps[k], nil }))
|
|
if tool.Name != "node-build-go.output" {
|
|
t.Fatalf("name %q", tool.Name)
|
|
}
|
|
for _, c := range []struct {
|
|
ask, fail string
|
|
want sdkstep.OutputAnswer
|
|
}{
|
|
{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: "a4", fail: "never ran on ace"},
|
|
{ask: "a5", fail: "never ran on ace"},
|
|
{fail: "asked for no ask"},
|
|
} {
|
|
got, err := tool.Run(map[string]any{"ask": c.ask})
|
|
if c.fail != "" {
|
|
if err == nil || !strings.Contains(err.Error(), c.fail) {
|
|
t.Errorf("output of %q: %+v, %v; want refused saying %q", c.ask, got, err, c.fail)
|
|
}
|
|
continue
|
|
}
|
|
o, _ := got.(sdkstep.OutputAnswer)
|
|
if err != nil || o.Ask != c.want.Ask || o.Output != c.want.Output || o.Size != c.want.Size || !slices.Equal(o.Failing, c.want.Failing) || o.NoLongerKept != c.want.NoLongerKept {
|
|
t.Errorf("output of %q: %+v, %v; want %+v", c.ask, got, err, c.want)
|
|
}
|
|
}
|
|
}
|