S8 unread-away: Unread of a state and a view, the away answers, the start's phase
Builds: design 47 H2 H-A-708 (1) (2), H-A-717 (DQ-54, DQ-58)
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -582,3 +584,54 @@ func TestABundlesLedgerWatchIsHandedItsChangesInOrder(t *testing.T) {
|
||||
}
|
||||
_ = inW.Close()
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-708 (2), H-A-717 DQ-58: a tool's `away` fault is its result in §776's form (error-kind, part, words), no
|
||||
// error; a plain refusal stays an error.
|
||||
func TestAToolsAwayFaultIsItsResultInTheAwayForm(t *testing.T) {
|
||||
servesAlone(t)
|
||||
t.Setenv(ServedAs, "indexer")
|
||||
inR, inW := io.Pipe()
|
||||
outR, outW := io.Pipe()
|
||||
go func() {
|
||||
_ = ServeOn("", []Tool{
|
||||
{Name: "revision", Run: func(map[string]any) (any, error) {
|
||||
return nil, fmt.Errorf("reading: %w", &busretry.Away{Part: "the trunk's revision 512", Words: "not read yet since 23:35:40"})
|
||||
}},
|
||||
{Name: "refuse", Run: func(map[string]any) (any, error) { return nil, errors.New("refused") }},
|
||||
}, inR, outW)
|
||||
}()
|
||||
lines := bufio.NewScanner(outR)
|
||||
for i, row := range []struct {
|
||||
tool, want string
|
||||
isError bool
|
||||
}{
|
||||
{"revision", string(mustJSON(t, busretry.AwayAnswer("the trunk's revision 512", "not read yet since 23:35:40"))), false},
|
||||
{"refuse", "refused", true},
|
||||
} {
|
||||
b, _ := json.Marshal(map[string]any{"jsonrpc": "2.0", "id": i + 1, "method": "tools/call", "params": map[string]any{"name": row.tool}})
|
||||
_, _ = inW.Write(append(b, '\n'))
|
||||
if !lines.Scan() {
|
||||
t.Fatal("the bundle said nothing")
|
||||
}
|
||||
var m struct {
|
||||
Result struct {
|
||||
Content []struct{ Text string }
|
||||
IsError bool `json:"isError"`
|
||||
}
|
||||
}
|
||||
_ = json.Unmarshal(lines.Bytes(), &m)
|
||||
if len(m.Result.Content) != 1 || m.Result.Content[0].Text != row.want || m.Result.IsError != row.isError {
|
||||
t.Errorf("%s answered %s", row.tool, lines.Text())
|
||||
}
|
||||
}
|
||||
_ = inW.Close()
|
||||
}
|
||||
|
||||
func mustJSON(t *testing.T, v any) []byte {
|
||||
t.Helper()
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user