Design 47 G start: tool runner fixes placed by hand #72

Merged
mesh-tools merged 10 commits from fix/47-G-start-3 into main 2026-11-16 14:15:10 +00:00
2 changed files with 49 additions and 1 deletions
Showing only changes of commit faa1064214 - Show all commits
@@ -0,0 +1,43 @@
package runtime
import (
"testing"
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
)
// Design 47 G lead answers A-377: the call a module's tool reaches the gate by carries the module's composed
// environment, so the gate tells a first-view tool (the one whose MESH_VIEW_CALLERS_<TOOL> the bundle holds) from an
// ordinary one while its catalog half is unread.
func TestAModuleToolsCallCarriesItsBundlesComposedEnvironment(t *testing.T) {
for name, tc := range map[string]struct {
envs map[string]map[string]string
want bool
}{
"a first-view tool": {map[string]map[string]string{"ledger": {"MESH_VIEW_CALLERS_WHO": "grants"}}, true},
"an ordinary tool": {nil, false},
} {
t.Run(name, func(t *testing.T) {
mesh := mt.New(t)
mesh.Issue(t, mt.MembershipOf("ledger", "anchor", true, map[string][]string{"node-desk": {"who"}}))
nodeTools := connect(t, "node-tools", "anchor")
gate := &gateHolding{}
stop, err := Run(nodeTools, []Served{{"ledger", []string{mt.Fixture("caller-echo.py")}}}, tc.envs, func(string, ...any) {}, deskDefined, WithGate(gate))
if err != nil {
t.Fatal(err)
}
defer stop()
asker := connect(t, "node-tools", "anchor")
mt.Until(t, func() error { _, err := asker.Ask("ledger.who@anchor", map[string]any{}, ""); return err })
var found bool
for _, c := range gate.calls {
if c.Seat == "" && c.Name == "who" {
_, found = c.Env["MESH_VIEW_CALLERS_WHO"]
}
}
if found != tc.want {
t.Errorf("the gate saw the first-view word: %v, want %v (calls %+v)", found, tc.want, gate.calls)
}
})
}
}
+6 -1
View File
@@ -241,6 +241,9 @@ type runner struct {
// §424, §618), never the runner's own.
fingerprintOf func(module string) string
// envOf is a module's composed environment, the words the gate tells a first-view tool by (lead answers A-377).
envOf func(module string) map[string]string
seatsAgain func()
stops []func() // the watch, the announcement and the seats, in the order they began
}
@@ -275,6 +278,7 @@ func Run(conn *bus.Conn, served []Served, envs map[string]map[string]string, log
base := os.Environ()
r.envFor = func(module string) []string { return BundleEnv(base, envs[module], module, node) }
r.fingerprintOf = func(module string) string { return envs[module][FingerprintWord] }
r.envOf = func(module string) map[string]string { return envs[module] }
// The module's events, for every child of it that subscribes (ADR 0198): one consumer per module,
// bound the first time any of its children subscribes, each event handed to every child that did.
@@ -479,7 +483,8 @@ func (r *runner) serve(l *loadedModule) {
module, own := reg.module, reg.repairs
stop, err := r.conn.HandleCalled(reg.module+"."+t.Name, func(caller 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), Caller: caller, Args: argsOf(body), Description: t.Description}, t, caller)
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
Description: t.Description}, t, caller)
})
if err != nil {
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)