From faa10642140dfd39aad517a10fb8dde8ce08d39e Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 13 Nov 2026 23:17:54 +0100 Subject: [PATCH] Fill the gate's Call.Env from the bundle's composed environment (A-377) Builds: design 47 G A-377 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- node-tools/internal/runtime/gate_env_test.go | 43 ++++++++++++++++++++ node-tools/internal/runtime/runtime.go | 7 +++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 node-tools/internal/runtime/gate_env_test.go diff --git a/node-tools/internal/runtime/gate_env_test.go b/node-tools/internal/runtime/gate_env_test.go new file mode 100644 index 0000000..abf3bc9 --- /dev/null +++ b/node-tools/internal/runtime/gate_env_test.go @@ -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_ 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) + } + }) + } +} diff --git a/node-tools/internal/runtime/runtime.go b/node-tools/internal/runtime/runtime.go index b29e08e..5dda527 100644 --- a/node-tools/internal/runtime/runtime.go +++ b/node-tools/internal/runtime/runtime.go @@ -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)