diff --git a/go/approval/approval_test.go b/go/approval/approval_test.go index 03d235d0..f513c4f6 100644 --- a/go/approval/approval_test.go +++ b/go/approval/approval_test.go @@ -9,6 +9,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/operatorask" "git.novox.be/novox/mesh-sdk/go/seatdef" + "git.novox.be/novox/mesh-sdk/go/seatlist" ) // call is a fixture call of the marked tool wipe. @@ -82,21 +83,27 @@ func TestTheActAndItsAsk(t *testing.T) { } } -// unread is a catalog half whose first view is not read yet. -type unread struct{} +// unread is a catalog half whose first view is not read yet, beside the seat definitions the runner holds. +type unread struct{ defs map[string]seatdef.Definition } -func (unread) Ready() error { return errors.New("the registrations are not answered") } -func (unread) Revision() string { return "" } -func (unread) Served(string) (Entry, bool, string) { return Entry{}, false, "not read" } -func (unread) Newest(string) (Entry, bool) { return Entry{}, false } -func (unread) Definitions() map[string]seatdef.Definition { return nil } -func (unread) Entries() []Entry { return nil } +func (unread) Ready() error { return errors.New("the registrations are not answered") } +func (unread) Revision() string { return "" } +func (unread) Served(string) (Entry, bool, string) { return Entry{}, false, "not read" } +func (unread) Newest(string) (Entry, bool) { return Entry{}, false } +func (u unread) Definitions() map[string]seatdef.Definition { return u.defs } +func (unread) Entries() []Entry { return nil } -// Design 47 G lead answers A-353, A-359: while its catalog half is unread, the gate lets through the seat verbs and first-view tools that -// half is read by, told from the call's seat and verb, and holds every other call as before. +// Design 47 G lead answers A-387, A-388 (and A-377): while its catalog half is unread, the gate lets through every seat +// verb the definition the runner holds (here the bootstrapped list) classes `read` explicitly and does not mark +// needs-approval, and a module's own first-view tools, and holds every other call as before. func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) { + defs := map[string]seatdef.Definition{} + for _, d := range seatlist.Bootstrapped() { + defs[d.Seat] = d + } + defs["marked"] = seatdef.Definition{Seat: "marked", Verbs: []seatdef.Verb{{Name: "look", Class: seatdef.ClassRead, NeedsApproval: true}}} waited := 0 - g := New(Deps{Node: "n1", Runner: "node-tools", Catalog: unread{}, Wait: func(time.Duration) error { + g := New(Deps{Node: "n1", Runner: "node-tools", Catalog: unread{defs: defs}, Wait: func(time.Duration) error { waited++ return errors.New("still unread") }}) @@ -110,6 +117,15 @@ func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) { {"mesh-catalog", "entry", true, nil}, {"mesh-delivery", "source", true, nil}, {"mesh-broker", "list", true, nil}, + {"mesh-catalog", "seat-definitions", true, nil}, + {"mesh-catalog", "modules", true, nil}, + {"git", "pull", true, nil}, + {"git", "merge-pull", false, nil}, // an act + {"mesh-broker", "create", false, nil}, // an act + {"mesh-delivery-checker", "try", false, nil}, // names no class, so no read (A-388) + {"operator-channel", "tell", false, nil}, // names no class + {"marked", "look", false, nil}, // a read marked needs-approval + {"unheld", "list", false, nil}, // a seat the runner holds no definition of {"mesh-broker", "events", false, nil}, // A-377: a module's own first-view tool runs unread, an ordinary tool of the same module stays held. {"", "modules", true, map[string]string{"MESH_VIEW_CALLERS_MODULES": "grants"}}, @@ -134,7 +150,7 @@ func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) { t.Errorf("%s: refused with %v, want the marks not read yet", address, err) } } - if waited != 6 { - t.Errorf("the other calls waited for the catalog half %d times, want 6 (the start reads wait for nothing)", waited) + if waited != 12 { + t.Errorf("the other calls waited for the catalog half %d times, want 12 (the start reads wait for nothing)", waited) } } diff --git a/go/approval/run.go b/go/approval/run.go index 59eeeecc..d11be7aa 100644 --- a/go/approval/run.go +++ b/go/approval/run.go @@ -7,6 +7,7 @@ import ( "strings" "git.novox.be/novox/mesh-sdk/go/operatorask" + "git.novox.be/novox/mesh-sdk/go/seatdef" ) // Run is a call through the gate (§20): an unmarked call runs; a marked one runs only on the operator's approval of that @@ -68,34 +69,36 @@ func (g *Gate) Run(c Call, run func() (any, error)) (any, error) { // Binding is a Store that says whether the runner's membership binds the state now (§13). type Binding interface{ Bound() bool } -// startReads are the seat verbs the catalog half is read by, as `.`: while it is unread the gate lets them -// through, so the runner that serves them answers the reads its own catalog half waits on (design 47 G lead answers -// A-353, A-359, A-375), and so is a module's own first-view tool (A-377): the tool whose callers list its -// bundle's environment carries, a list that still limits who may call it. -var startReads = []string{"mesh-catalog.registrations", "mesh-catalog.revision", "mesh-catalog.entry", "mesh-delivery.source", "mesh-broker.list"} - // ViewCallersPrefix starts the name of the env value that holds a first-view tool's callers list in its owner's bundle // (views.CallersEnv adds the tool's name), by which the gate tells a first-view tool. const ViewCallersPrefix = "MESH_VIEW_CALLERS_" -// startRead says the call is one of startReads, told from its seat and verb. -func startRead(c Call) bool { +// startRead says the call runs while the catalog half is unread (design 47 G lead answers A-387, A-388): a seat verb the +// seat definition the runner holds classes `read` explicitly and does not mark needs-approval, so the runner that serves +// them answers the reads its own catalog half and the first take-in wait on; and a module's own first-view tool (A-377), +// the tool whose callers list its bundle's environment carries, a list that still limits who may call it. +func (g *Gate) startRead(c Call) bool { if c.Seat == "" { _, first := c.Env[ViewCallersPrefix+strings.ToUpper(strings.ReplaceAll(c.Name, "-", "_"))] return first } - return c.Seat != "" && slices.Contains(startReads, c.Seat+"."+c.Name) + def, ok := g.d.Catalog.Definitions()[c.Seat] + if !ok { + return false + } + i := slices.IndexFunc(def.Verbs, func(v seatdef.Verb) bool { return v.Name == c.Name }) + return i >= 0 && def.Verbs[i].Class == seatdef.ClassRead && !def.Verbs[i].NeedsApproval } -// marksOf is the module's marks as the catalog half has them now; before its first view, a call of startReads runs -// unmarked (A-353, A-359) and any other waits for it within RecordWithin and is then judged, refused naming +// marksOf is the module's marks as the catalog half has them now; before its first view, a start read runs unmarked +// (A-387) and any other waits for it within RecordWithin and is then judged, refused naming // mesh_first_views when it is still unread (§19). func (g *Gate) marksOf(c Call) (Marks, error) { if g.d.Catalog == nil { return Marks{}, g.refused(c, "", "the tool runner reads no catalog half, so its marks are not read") } if err := g.d.Catalog.Ready(); err != nil { - if startRead(c) { + if g.startRead(c) { return Marks{Module: c.Module}, nil } if g.d.Wait != nil {