package runtime import ( "testing" mt "github.com/novox/mesh-tools/node-tools/internal/meshtest" ) // The call a module's tool reaches the gate by carries the module's composed environment. The gate no longer tells a first-view tool // by an environment word: it knows one by its name forms _first_views and _first_view_again (H-A-69), and the runner // sets no view-callers word. func TestAModuleToolsCallCarriesItsBundlesComposedEnvironment(t *testing.T) { for name, tc := range map[string]struct { envs map[string]map[string]string want bool }{ "a module with an environment": {map[string]map[string]string{"ledger": {"LEDGER_WORD": "x"}}, true}, "a module with none": {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["LEDGER_WORD"] } } if found != tc.want { t.Errorf("the gate saw the composed word: %v, want %v (calls %+v)", found, tc.want, gate.calls) } }) } }