Files
mesh-delivery/modules/mesh-delivery-sdk/steprun/outputs_test.go
T
jschoubben fad9f059ee BM4b (sdk): an end over the steps state's value is read through the verb answer
A step's end is an event, not a verb's answer, so an end over what the steps
state's value or step-ended carries has a reader of its own: keepOver keeps it
in the steps objects as answer.<ask>, the step key and step-ended carry
answer-object in place of output-object, and the build seats gain the read
verb answer (ask and call, marked chunks); output stays the run text's reader.
Step.Whole and StepEnded.ReadOutput read through answer.

Builds: design 47 H2 §791; H-A-412 (2) and its addendum
2026-11-22 01:08:58 +01:00

45 lines
1.4 KiB
Go

package steprun
import (
"errors"
"strings"
"testing"
"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")
}
}