Every account may call every verb: the grants part reads no definition's callers (callerOf, the verb and accept callers, admits) and grants every module's account every verb of every seat (mesh.seat.*.tool.> and its caller-named form), a sent store to every module invoking a verb of its claimant's seat, and every queue's named ask to every asker. grants_callers goes; grants_why_refused answers the bus's own verdict. The indexer keeps no verdicts: their first view, events, invoke and the engine's read go, and a want names its build alone (no newest). internal/... and cmd/... tests are green; the root package's grants_test.go still reads the verdicts (rows at grants_test.go:303-307, 741, 1184, 3700-3870, 4560-4615) and does not compile. Builds: design 47 H §745, §750, §752, §764 (every seat contract: the callers lists); lead answers H-A-37, H-A-66, H-A-79, H-A-113 (hq f599b761) Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package grants
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
|
)
|
|
|
|
type defsGate struct{ defs map[string]seatdef.Definition }
|
|
|
|
func (defsGate) MayAct(...string) bool { return true }
|
|
func (g defsGate) Definitions() map[string]seatdef.Definition { return g.defs }
|
|
|
|
type canCall struct {
|
|
allowed bool
|
|
asked map[string]any
|
|
}
|
|
|
|
func (c *canCall) Call(key string, body any) (json.RawMessage, error) {
|
|
c.asked = body.(map[string]any)
|
|
return json.Marshal(map[string]any{"allowed": c.allowed})
|
|
}
|
|
|
|
// grants_why_refused answers the bus's own verdict on an account's call subject, naming no callers (design 47 H §752,
|
|
// H-A-113): a refused account is told the subject it lacks; grants_callers is gone.
|
|
func TestWhyRefusedIsTheBussVerdict(t *testing.T) {
|
|
defs := map[string]seatdef.Definition{"mesh-wants": {Seat: "mesh-wants", Scope: "mesh", Verbs: []seatdef.Verb{
|
|
{Name: "upgrade", Class: seatdef.ClassAct},
|
|
{Name: "entry", Class: seatdef.ClassRead},
|
|
}}}
|
|
can := &canCall{}
|
|
p := &Part{SeatList: defsGate{defs}, Call: can}
|
|
got, err := p.WhyRefused("one.shop", "mesh-wants.upgrade", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := got.(map[string]any)
|
|
if out["lacks"] != "mesh.seat.mesh-wants.call.upgrade.one~shop" || can.asked["subject"] != out["lacks"] || out["definition"] != nil ||
|
|
out["admitted_by"] != nil || strings.Contains(out["says"].(string), "definition") {
|
|
t.Errorf("a refused caller: %+v", out)
|
|
}
|
|
can.allowed = true
|
|
got, _ = p.WhyRefused("one.shop", "mesh-wants.upgrade", "")
|
|
if _, lacks := got.(map[string]any)["lacks"]; lacks {
|
|
t.Errorf("an allowed caller lacks a grant: %+v", got)
|
|
}
|
|
if _, err := p.WhyRefused("one.shop", "mesh-wants.nothing", ""); err == nil {
|
|
t.Error("a verb no definition names was explained")
|
|
}
|
|
if slices.Contains(Tools, "grants_callers") {
|
|
t.Error("the tool grants_callers is still listed")
|
|
}
|
|
}
|