Copy the kept call's ask id from its request header into the call's _meta as mesh/ask
Every tool call and seat verb the tool runner serves hands the bundle the ask id the kept call set in the header x-ask (stdio.AskHeader) under _meta mesh/ask (stdio.MetaAsk), beside mesh/call; a call whose header carries none names none. Builds: design 47 H2 §775, H-A-351
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/approval"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
type saidCaller struct {
|
||||
Caller string `json:"caller"`
|
||||
Call string `json:"call"`
|
||||
Ask *string `json:"ask"`
|
||||
Arguments map[string]any `json:"arguments"`
|
||||
}
|
||||
|
||||
@@ -65,7 +67,39 @@ func TestACallOnTheCallerNamedSubjectReachesTheModuleWithItsCaller(t *testing.T)
|
||||
if got.Arguments["caller"] != "novox.node-tools" {
|
||||
t.Errorf("%s: the arguments did not reach the module as sent: %v", key, got.Arguments)
|
||||
}
|
||||
// A call that carries no ask id in its header names none in `_meta` (design 47 H2 §775, H-A-351).
|
||||
if got.Ask != nil {
|
||||
t.Errorf("%s reached the module with ask %q, want none for a call whose header carries none", key, *got.Ask)
|
||||
}
|
||||
}
|
||||
// **The ask id a kept call sets in its request header is copied into the call's `_meta` as mesh/ask** (design 47 H2 §775,
|
||||
// H-A-351), for a module's tool and for a seat's verb.
|
||||
url := mt.URL(t)
|
||||
t.Run("TheAskIdOfTheHeaderReachesTheModule", func(t *testing.T) {
|
||||
raw, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer raw.Close()
|
||||
for _, subject := range []string{"mesh.mod.ledger.tool.who", "mesh.seat.node-desk.tool.who.anchor"} {
|
||||
msg := nats.NewMsg(subject)
|
||||
msg.Header.Set(stdio.AskHeader, "ask-7f3a")
|
||||
msg.Data = []byte(`{}`)
|
||||
var reply struct {
|
||||
Result saidCaller `json:"result"`
|
||||
}
|
||||
mt.Until(t, func() error {
|
||||
answer, err := raw.RequestMsg(msg, 5*time.Second)
|
||||
if err == nil {
|
||||
err = json.Unmarshal(answer.Data, &reply)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if reply.Result.Ask == nil || *reply.Result.Ask != "ask-7f3a" {
|
||||
t.Errorf("%s reached the module with ask %v, want the header's ask-7f3a under mesh/ask", subject, reply.Result.Ask)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// deskDefined is the seat list's definition of the fixture seat node-desk, its verb who.
|
||||
|
||||
@@ -25,11 +25,11 @@ type Gate interface {
|
||||
}
|
||||
|
||||
// gatedRun is how a handler calls a tool: through the gate where there is one.
|
||||
type gatedRun func(call approval.Call, t launch.Tool, caller string) (any, error)
|
||||
type gatedRun func(call approval.Call, t launch.Tool, caller, ask string) (any, error)
|
||||
|
||||
// gated calls the tool through the gate, or straight where the runner has none.
|
||||
func (c *consumers) gated(call approval.Call, t launch.Tool, caller string) (any, error) {
|
||||
run := func() (any, error) { return t.Run(caller, call.Args) }
|
||||
func (c *consumers) gated(call approval.Call, t launch.Tool, caller, ask string) (any, error) {
|
||||
run := func() (any, error) { return t.Call(caller, ask, call.Args) }
|
||||
if c.gate == nil {
|
||||
return run()
|
||||
}
|
||||
|
||||
@@ -518,10 +518,10 @@ func (r *runner) serve(l *loadedModule) {
|
||||
// Told who called, from the subject the call arrived on, never from its body (novox/hq issue 365).
|
||||
// Through the approval gate, before the bundle or the runner's own tool (design 46 7-approval-mark §20).
|
||||
module, own := reg.module, reg.repairs
|
||||
stop, err := r.conn.HandleCalled(address, func(caller string, body json.RawMessage) (any, error) {
|
||||
stop, err := r.conn.HandleCalled(address, func(caller, ask string, body json.RawMessage) (any, error) {
|
||||
return r.events.gated(approval.Call{Address: module + "." + t.Name, Module: module, Name: t.Name, Own: own,
|
||||
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
|
||||
Description: t.Description}, t, caller)
|
||||
Description: t.Description}, t, caller, ask)
|
||||
})
|
||||
if err != nil {
|
||||
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)
|
||||
@@ -815,7 +815,7 @@ func serveSeats(conn *bus.Conn, modules []string, current func() []registration,
|
||||
// record of the calls its gate holds, by caller, and no bundle names it (lead answers A-265, A-266, A-271).
|
||||
if v.Verb == seatdef.ApprovalsVerb && approvals != nil {
|
||||
seat := v.Seat
|
||||
stop, err := conn.HandleSubjectCalled(v.Subject, func(caller string, _ json.RawMessage) (any, error) {
|
||||
stop, err := conn.HandleSubjectCalled(v.Subject, func(caller, _ string, _ json.RawMessage) (any, error) {
|
||||
return approvals(caller)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -834,9 +834,9 @@ func serveSeats(conn *bus.Conn, modules []string, current func() []registration,
|
||||
// Through the approval gate, for any caller, before the bundle (design 47 H §752; design 46
|
||||
// 7-approval-mark §20).
|
||||
module, v := module, v
|
||||
handle := func(caller string, body json.RawMessage) (any, error) {
|
||||
handle := func(caller, ask string, body json.RawMessage) (any, error) {
|
||||
answer, err := gated(approval.Call{Address: v.Seat + "." + v.Verb, Module: module, Seat: v.Seat, Name: v.Verb,
|
||||
Fingerprint: fingerprintOf(module), Caller: caller, Args: argsOf(body), Description: t.Description}, t.Within(within("seat:"+v.Seat+"."+v.Verb)), caller)
|
||||
Fingerprint: fingerprintOf(module), Caller: caller, Args: argsOf(body), Description: t.Description}, t.Within(within("seat:"+v.Seat+"."+v.Verb)), caller, ask)
|
||||
if err != nil || !chunked("seat:"+v.Seat+"."+v.Verb) {
|
||||
return answer, err
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ func TestANodeScopedSeatVerbIsAlsoAnsweredWithNoMachine(t *testing.T) {
|
||||
return []registration{{module: "node-shelf", owner: "theta", tools: []launch.Tool{{Name: "list",
|
||||
Run: func(string, json.RawMessage) (json.RawMessage, error) { return json.RawMessage(`{"shelf":["x"]}`), nil }}}}}
|
||||
}
|
||||
gated := func(_ approval.Call, tool launch.Tool, caller string) (any, error) {
|
||||
gated := func(_ approval.Call, tool launch.Tool, caller, _ string) (any, error) {
|
||||
return tool.Run(caller, nil)
|
||||
}
|
||||
nodeTools.Follow("theta")
|
||||
|
||||
Reference in New Issue
Block a user