T1a verb-timeout-ask: a bundle's ask waits the timeout its verb's definition names
The runner reads the `timeout` (whole seconds) of a seat's verb from the seat list's definitions beside `chunked` and hands it to the bus connection's ask (AskWithin, AskAsWithin, AskAsChunkedWithin); a verb that names none, a seat the definitions do not hold and a module's tool wait the runner's own bound, RequestTimeout. Builds: design 47 H §760, H-A-43 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -152,6 +152,45 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
|
||||
t.Error("a runner that holds no seat definitions asks no chunks")
|
||||
}
|
||||
})
|
||||
// Design 47 H §760: a bundle's ask waits the `timeout` its verb's definition names, whole seconds; a verb that names none, a
|
||||
// seat the definitions do not hold, a module's tool and a runner that holds no definitions wait the runner's own bound (zero).
|
||||
t.Run("AVerbsTimeoutIsTheBoundItsAskWaits", func(t *testing.T) {
|
||||
forty, six := 40, 600
|
||||
defs := map[string]seatdef.Definition{"mesh-broker": {Verbs: []seatdef.Verb{{Name: "rates", Timeout: &forty}, {Name: "slow", Chunks: true, Timeout: &six}, {Name: "plain"}}}}
|
||||
for _, row := range []struct {
|
||||
key string
|
||||
want time.Duration
|
||||
way string
|
||||
}{
|
||||
{"seat:mesh-broker.rates", 40 * time.Second, "plain"},
|
||||
{"seat:mesh-broker.rates@home-server", 40 * time.Second, "plain"},
|
||||
{"seat:mesh-broker.slow", 600 * time.Second, "chunked"},
|
||||
{"seat:mesh-broker.plain", 0, "plain"},
|
||||
{"seat:mesh-unread.rates", 0, "plain"},
|
||||
{"mesh-delivery-indexer.indexer", 0, "plain"},
|
||||
} {
|
||||
var got time.Duration
|
||||
var way string
|
||||
c := &consumers{definitions: func() map[string]seatdef.Definition { return defs },
|
||||
askPlain: func(_, _ string, _ any, within time.Duration) (bus.Answered, error) {
|
||||
got, way = within, "plain"
|
||||
return bus.Answered{}, nil
|
||||
},
|
||||
askChunked: func(_, _ string, _ any, within time.Duration) (bus.Answered, error) {
|
||||
got, way = within, "chunked"
|
||||
return bus.Answered{}, nil
|
||||
}}
|
||||
if _, err := (&moduleBus{all: c, module: "m"}).Ask(json.RawMessage(`{"key":"` + row.key + `","body":{}}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != row.want || way != row.way {
|
||||
t.Errorf("Ask %s waited %s (%s), want %s (%s)", row.key, got, way, row.want, row.way)
|
||||
}
|
||||
}
|
||||
if got := (&consumers{}).withinOf("seat:mesh-broker.rates"); got != 0 {
|
||||
t.Errorf("a runner that holds no definitions waits %s, want its own bound", got)
|
||||
}
|
||||
})
|
||||
// Design 47 G A-490m: a verb of a seat the list defines whose definition does not name it is read again once and never asked
|
||||
// without its call; a seat the list does not define, a module's tool and a bundle asking through moduleBus.Ask behave as before.
|
||||
t.Run("AVerbTheDefinitionDoesNotNameIsReadAgainAndNeverAskedWithoutItsCall", func(t *testing.T) {
|
||||
@@ -175,8 +214,14 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
held, reads, way := stale, 0, ""
|
||||
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { reads++; return row.again(&held) },
|
||||
askPlain: func(_, _ string, _ any) (bus.Answered, error) { way = "plain"; return bus.Answered{}, nil },
|
||||
askChunked: func(_, _ string, _ any) (bus.Answered, error) { way = "chunked"; return bus.Answered{}, nil }}
|
||||
askPlain: func(_, _ string, _ any, _ time.Duration) (bus.Answered, error) {
|
||||
way = "plain"
|
||||
return bus.Answered{}, nil
|
||||
},
|
||||
askChunked: func(_, _ string, _ any, _ time.Duration) (bus.Answered, error) {
|
||||
way = "chunked"
|
||||
return bus.Answered{}, nil
|
||||
}}
|
||||
_, err := (&moduleBus{all: c, module: "m"}).Ask(json.RawMessage(`{"key":"` + row.key + `","body":{}}`))
|
||||
if way != row.wantWay || reads != row.wantReads || (row.wantErr == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), row.wantErr)) {
|
||||
t.Errorf("Ask %s: asked %q, %v after %d reads, want %q, %q after %d", row.key, way, err, reads, row.wantWay, row.wantErr, row.wantReads)
|
||||
|
||||
@@ -3,6 +3,7 @@ package runtime
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/approval"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
@@ -179,3 +180,23 @@ func (c *consumers) chunked(key string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// withinOf is how long a call of key waits for its answer: the `timeout` the verb's definition names, in whole seconds (design 47
|
||||
// H §760, H-A-43); zero, which the bus reads as the tool runner's own bound, for a key that is no seat's verb, a seat the
|
||||
// definitions do not hold, a verb they do not name and a verb that names none.
|
||||
func (c *consumers) withinOf(key string) time.Duration {
|
||||
if c.definitions == nil || !strings.HasPrefix(key, "seat:") {
|
||||
return 0
|
||||
}
|
||||
name, _, _ := strings.Cut(key, "@")
|
||||
seat, verb, ok := strings.Cut(strings.TrimPrefix(name, "seat:"), ".")
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for _, v := range c.definitions()[seat].Verbs {
|
||||
if v.Name == verb && v.Timeout != nil {
|
||||
return time.Duration(*v.Timeout) * time.Second
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -876,7 +876,7 @@ type consumers struct {
|
||||
rereadMu sync.Mutex
|
||||
rereading *rereadFlight
|
||||
// askPlain and askChunked are how a bundle's ask is sent (the bus connection's AskAs and AskAsChunked); a test gives its own.
|
||||
askPlain, askChunked func(module, key string, body any) (bus.Answered, error)
|
||||
askPlain, askChunked func(module, key string, body any, within time.Duration) (bus.Answered, error)
|
||||
}
|
||||
|
||||
type moduleEvents struct {
|
||||
@@ -1007,7 +1007,7 @@ func (b *moduleBus) Ask(params json.RawMessage) (json.RawMessage, error) {
|
||||
}
|
||||
ask := b.all.askPlain
|
||||
if ask == nil {
|
||||
ask = b.all.conn.AskAs
|
||||
ask = b.all.conn.AskAsWithin
|
||||
}
|
||||
chunks, err := b.all.chunkedAsked(asked.Key)
|
||||
if err != nil {
|
||||
@@ -1015,11 +1015,11 @@ func (b *moduleBus) Ask(params json.RawMessage) (json.RawMessage, error) {
|
||||
}
|
||||
if chunks {
|
||||
if ask = b.all.askChunked; ask == nil {
|
||||
ask = b.all.conn.AskAsChunked
|
||||
ask = b.all.conn.AskAsChunkedWithin
|
||||
}
|
||||
// the runner receives the chunks of the answer; the bundle receives none (design 47 G A-249)
|
||||
}
|
||||
answered, err := ask(b.module, asked.Key, body)
|
||||
answered, err := ask(b.module, asked.Key, body, b.all.withinOf(asked.Key))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user