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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user