sdk-holder-callers-gone: no holder keeps a callers list; every seat-list tool and first-view tool answers every caller
go/callers.go goes (stdio.Callers, VerbCallers, ParseCallers, ParseVerbCallers, ConfiguredVerbCallers, HoldVerbCallers, AnyPerson, CallerSeatPrefix; ModuleOf stays in caller.go). seatlist.NewPart(prefix), Tools(r, read, again); ToolsWith, Refusal, RefusalWith and Part.Holders go. views.FirstViewTool loses its callers argument; views.ParseCallers and views.Refusal go. approval.ViewCallersPrefix and views.CallersEnv stay until the question of how the gate tells a first-view tool is answered. Builds: design 47 H §752, §764, H-A-41, H-A-66
This commit is contained in:
@@ -3,6 +3,7 @@ package stdio
|
||||
import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -89,3 +90,11 @@ func runAs(t Tool, caller, call string, args map[string]any) (any, error) {
|
||||
defer calls.Delete(key)
|
||||
return t.Run(args)
|
||||
}
|
||||
|
||||
// ModuleOf is the module of a proved module caller, which the runtime names <machine>.<module>.
|
||||
func ModuleOf(proved string) string {
|
||||
if _, module, ok := strings.Cut(proved, "."); ok {
|
||||
return module
|
||||
}
|
||||
return proved
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package stdio
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -108,67 +107,6 @@ func TestACallerInTheArgumentsIsNeverTheCaller(t *testing.T) {
|
||||
if got != "shanks.node-tools" {
|
||||
t.Fatalf("with a caller in the arguments the tool read %q, want the runtime's", got)
|
||||
}
|
||||
// A module's trusted list of callers (issue 774, ADR 0563 §8) grants the callers it names as the runtime proved them:
|
||||
// a module on any machine, <machine>.<module> exactly, person.<name> exactly; no wildcard, never one unproven.
|
||||
callers, err := ParseCallers([]byte(`{"callers":["node-tools","ace.claude-code","person.jo","*"]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for caller, want := range map[string]bool{"shanks.node-tools": true, "ace.claude-code": true, "g14.claude-code": false,
|
||||
"person.jo": true, "person.node-tools": false, Unproven: false, "": false, "novox.mesh-vault": false} {
|
||||
if callers.Allows(caller) != want {
|
||||
t.Errorf("%q allowed: %v, want %v", caller, !want, want)
|
||||
}
|
||||
}
|
||||
if _, err := ParseCallers([]byte(`{"callers":["x"],"more":1}`)); err == nil {
|
||||
t.Error("a list with a field it does not know was read")
|
||||
}
|
||||
// A holder's list per verb (ADR 0627 §2): each verb's entries as above, plus every proved caller (AnyCaller) or
|
||||
// every operator's session (AnyPerson); an unproven caller never, a verb the holder does not serve refused.
|
||||
verbs, err := ParseVerbCallers(`{"publish":["mesh-build-go"],"versions":["*"],"release":["operator","sweep"]}`,
|
||||
[]string{"publish", "versions", "release", "remove"}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
verb, caller string
|
||||
want bool
|
||||
}{{"publish", "ace.mesh-build-go", true}, {"publish", "ace.mesh-build-node", false}, {"versions", "g14.anything", true},
|
||||
{"versions", Unproven, false}, {"release", "person.jo", true}, {"release", "ace.operator", false},
|
||||
{"release", "novox.sweep", true}, {"remove", "novox.sweep", false}} {
|
||||
if got := verbs.Allowed(c.verb, c.caller) == nil; got != c.want {
|
||||
t.Errorf("%s by %q allowed: %v, want %v", c.verb, c.caller, got, c.want)
|
||||
}
|
||||
}
|
||||
// A-295: an entry `seat:<seat>` allows the modules the part's holder function answers for the seat, and
|
||||
// nobody without holders.
|
||||
seats := VerbCallers{"again": {AnyPerson, "seat:node-tool-runner", "seat:mesh-healers"}}
|
||||
holders := func(seat string) []string {
|
||||
return map[string][]string{"node-tool-runner": {"node-tools"}, "mesh-healers": {"mesh-delivery-watchman"}}[seat]
|
||||
}
|
||||
for _, c := range []struct {
|
||||
caller string
|
||||
holders func(string) []string
|
||||
want bool
|
||||
}{{"ace.node-tools", holders, true}, {"g14.mesh-delivery-watchman", holders, true}, {"ace.mesh-build-go", holders, false},
|
||||
{"person.jo", holders, true}, {"ace.node-tools", nil, false}} {
|
||||
if got := seats.AllowedWith("again", c.caller, c.holders) == nil; got != c.want {
|
||||
t.Errorf("again by %q (holders %v) allowed: %v, want %v", c.caller, c.holders != nil, got, c.want)
|
||||
}
|
||||
}
|
||||
if _, err := ParseVerbCallers(`{"mirror":["x"]}`, []string{"publish"}, nil); err == nil {
|
||||
t.Error("a list naming a verb the holder does not serve was read")
|
||||
}
|
||||
if d, _ := ParseVerbCallers(" ", nil, VerbCallers{"publish": {"x"}}); len(d["publish"]) != 1 {
|
||||
t.Error("an empty value is not the holder's defaults")
|
||||
}
|
||||
// As mesh-config resolves the value: the object itself, or written as a string; null is the defaults.
|
||||
for _, raw := range []string{`{"publish":["a"]}`, `"{\"publish\":[\"a\"]}"`, `null`} {
|
||||
c, err := parseConfiguredVerbCallers(json.RawMessage(raw), []string{"publish"}, VerbCallers{"publish": {"a"}})
|
||||
if err != nil || c.Allowed("publish", "ace.a") != nil {
|
||||
t.Errorf("the config value %s read as %v, %v", raw, c, err)
|
||||
}
|
||||
}
|
||||
if ModuleOf("ace.mesh-build-go") != "mesh-build-go" {
|
||||
t.Error("ModuleOf does not read the module of a proved caller")
|
||||
}
|
||||
@@ -200,44 +138,3 @@ func TestArgumentsOfNoCallHaveNoCaller(t *testing.T) {
|
||||
t.Fatalf("CallerOf(nil) answered %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A holder's caller list is held (issue 1966): the runtime is asked once, by a watch; a later call never asks again, so
|
||||
// an ask that timed out refuses no verb, and a change that cannot be read keeps the list last read.
|
||||
func TestAHeldCallerListIsAskedOnceAndSurvivesAnUnreadableChange(t *testing.T) {
|
||||
verbs, defaults := []string{"publish"}, VerbCallers{"publish": {"a"}}
|
||||
var asks int
|
||||
var push func(ProvisionChange) error
|
||||
fail := true
|
||||
read := holdVerbCallers(func(key string, h func(ProvisionChange) error) error {
|
||||
asks++
|
||||
if fail {
|
||||
return errors.New("nats: timeout")
|
||||
}
|
||||
push = h
|
||||
return h(ProvisionChange{Kind: "config", Key: key, Value: json.RawMessage(`{"publish":["b"]}`)})
|
||||
}, "callers", verbs, defaults)
|
||||
if _, err := read(); err == nil {
|
||||
t.Fatal("a list never read was answered")
|
||||
}
|
||||
fail = false
|
||||
c, err := read()
|
||||
if err != nil || c.Allowed("publish", "ace.b") != nil || asks != 2 {
|
||||
t.Fatalf("after the ask answered: %v, %v, asked %d times", c, err, asks)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
if _, err := read(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if asks != 2 {
|
||||
t.Errorf("a held list was asked again: %d asks", asks)
|
||||
}
|
||||
_ = push(ProvisionChange{Kind: "config", Key: "callers", Value: json.RawMessage(`{"nothing":["x"]}`)})
|
||||
if c, err := read(); err != nil || c.Allowed("publish", "ace.b") != nil {
|
||||
t.Errorf("an unreadable change dropped the list last read: %v, %v", c, err)
|
||||
}
|
||||
_ = push(ProvisionChange{Kind: "config", Key: "callers", Value: json.RawMessage(`{"publish":["c"]}`)})
|
||||
if c, _ := read(); c.Allowed("publish", "ace.c") != nil || c.Allowed("publish", "ace.b") == nil {
|
||||
t.Errorf("a change was not held: %v", c)
|
||||
}
|
||||
}
|
||||
|
||||
-207
@@ -1,207 +0,0 @@
|
||||
package stdio
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Callers is a module's trusted list of who may call a verb of its (novox/hq ADR 0459 §2, ADR 0563 §8), as the mesh
|
||||
// writes a list setting into a file the module reads: `{"callers": [...]}`. An entry is a module's name (that module on
|
||||
// any machine), exactly <machine>.<module>, or exactly person.<name>. Each caller is the runtime's proof (CallerOf), never
|
||||
// an argument; nobody beyond the list is granted, a wildcard is no entry, and an unproven caller never matches.
|
||||
type Callers []string
|
||||
|
||||
// ParseCallers reads a callers file: the list under `callers`, and nothing else.
|
||||
func ParseCallers(raw []byte) (Callers, error) {
|
||||
var f struct {
|
||||
Callers Callers `json:"callers"`
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||
dec.DisallowUnknownFields()
|
||||
if err := dec.Decode(&f); err != nil {
|
||||
return nil, fmt.Errorf("the callers setting is not a list of callers: %v", err)
|
||||
}
|
||||
return f.Callers, nil
|
||||
}
|
||||
|
||||
// Allows says whether caller, as the runtime proved it, is one the list names.
|
||||
func (c Callers) Allows(caller string) bool {
|
||||
if caller == "" || caller == Unproven {
|
||||
return false
|
||||
}
|
||||
for _, entry := range c {
|
||||
if entry == "" || strings.ContainsAny(entry, "*> ") {
|
||||
continue
|
||||
}
|
||||
if entry == caller {
|
||||
return true
|
||||
}
|
||||
if !strings.Contains(entry, ".") {
|
||||
if _, module, ok := strings.Cut(caller, "."); ok && module == entry && !strings.HasPrefix(caller, "person.") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// VerbCallers is a holder's trusted list per verb (novox/hq ADR 0627 §2, design 51 *Who may call which verb*): for each
|
||||
// verb of the seats it holds, the callers that may call it, each entry read as Callers reads it. Two entries more stand
|
||||
// for a whole class: AnyCaller lets every proved caller call the verb (a read the mesh keeps open), AnyPerson every
|
||||
// operator's session the runtime proved as person.<name>. It names no seat and no verb: the holder gives its verbs and
|
||||
// its defaults, and keeps any rule of its own seat (who may never be on a list) beside it.
|
||||
type VerbCallers map[string][]string
|
||||
|
||||
// The entries of a VerbCallers list that stand for a class of callers.
|
||||
const (
|
||||
AnyCaller = "*"
|
||||
AnyPerson = "operator"
|
||||
)
|
||||
|
||||
// ParseVerbCallers reads a holder's config value of verb to callers; an empty value is defaults. A verb not among verbs
|
||||
// is refused, so a list that names a verb the holder does not serve is said at once.
|
||||
func ParseVerbCallers(raw string, verbs []string, defaults VerbCallers) (VerbCallers, error) {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return defaults, nil
|
||||
}
|
||||
var c VerbCallers
|
||||
if err := json.Unmarshal([]byte(raw), &c); err != nil {
|
||||
return nil, fmt.Errorf("callers is not a JSON object of verb to callers: %w", err)
|
||||
}
|
||||
for verb := range c {
|
||||
if !slices.Contains(verbs, verb) {
|
||||
return nil, fmt.Errorf("callers names the verb %q, which the holder does not serve", verb)
|
||||
}
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// CallerSeatPrefix opens an entry naming a seat, `seat:<seat>`: every module holding it, so a list names no module (design 47
|
||||
// G A-210, A-295).
|
||||
const CallerSeatPrefix = "seat:"
|
||||
|
||||
// Allowed answers nil when caller, as the runtime proved it, may call verb; else the refusal naming both. An unproven
|
||||
// caller is never allowed, not even by AnyCaller. An entry `seat:<seat>` allows no one here (AllowedWith).
|
||||
func (c VerbCallers) Allowed(verb, caller string) error { return c.AllowedWith(verb, caller, nil) }
|
||||
|
||||
// AllowedWith is Allowed whose entries `seat:<seat>` allow a module caller whose module holders answers for that seat:
|
||||
// the part's holder function, which answers from what it last heard of the assigner's seat-holders view (design 47 G A-295),
|
||||
// so no call is made per check. A nil holders, or a seat it answers none for, allows no one by that entry.
|
||||
func (c VerbCallers) AllowedWith(verb, caller string, holders func(seat string) []string) error {
|
||||
if caller == "" || caller == Unproven {
|
||||
return fmt.Errorf("%s: refused: the request carries no caller the tool runner proved", verb)
|
||||
}
|
||||
person := strings.HasPrefix(caller, "person.")
|
||||
for _, entry := range c[verb] {
|
||||
if seat, ok := strings.CutPrefix(entry, CallerSeatPrefix); ok {
|
||||
if !person && holders != nil && slices.Contains(holders(seat), ModuleOf(caller)) {
|
||||
return nil
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch entry {
|
||||
case AnyCaller:
|
||||
return nil
|
||||
case AnyPerson:
|
||||
if person {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
if (Callers{entry}).Allows(caller) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s: refused for %s: not on the holder's caller list for %s", verb, caller, verb)
|
||||
}
|
||||
|
||||
// ModuleOf is the module of a proved module caller, which the runtime names <machine>.<module>.
|
||||
func ModuleOf(proved string) string {
|
||||
if _, module, ok := strings.Cut(proved, "."); ok {
|
||||
return module
|
||||
}
|
||||
return proved
|
||||
}
|
||||
|
||||
// ConfiguredVerbCallers is the holder's list as mesh-config resolved its config value key for this machine (Config):
|
||||
// a JSON object of verb to callers, or that object written as a string; an unset or empty value is defaults. A value
|
||||
// that cannot be read is an error, never the defaults, so a broken list is said, not widened.
|
||||
func ConfiguredVerbCallers(key string, verbs []string, defaults VerbCallers) (VerbCallers, error) {
|
||||
raw, err := Config(key)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the config value %s cannot be read: %w", key, err)
|
||||
}
|
||||
return parseConfiguredVerbCallers(raw, verbs, defaults)
|
||||
}
|
||||
|
||||
// HoldVerbCallers is ConfiguredVerbCallers held: the returned reader asks the runtime once, by a watch of the config
|
||||
// value key (WatchConfig), and from then on answers the list it holds, which each change of the value replaces. A call
|
||||
// never asks the runtime again, so a runtime that is slow or away for a moment (a timed-out ask) refuses no verb; a
|
||||
// change that cannot be read keeps the list last read and is said on the bundle's standard error, so a broken list is
|
||||
// said and never widened. Only a reader that has not yet read any value answers an error, and its next call asks again.
|
||||
func HoldVerbCallers(key string, verbs []string, defaults VerbCallers) func() (VerbCallers, error) {
|
||||
return holdVerbCallers(WatchConfig, key, verbs, defaults)
|
||||
}
|
||||
|
||||
func holdVerbCallers(watch func(string, func(ProvisionChange) error) error, key string, verbs []string, defaults VerbCallers) func() (VerbCallers, error) {
|
||||
var start, mu sync.Mutex
|
||||
var held VerbCallers
|
||||
var bad error
|
||||
handle := func(c ProvisionChange) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if c.Refused != "" {
|
||||
bad = fmt.Errorf("the config value %s is not answered: %s", key, c.Refused)
|
||||
} else if l, err := parseConfiguredVerbCallers(c.Value, verbs, defaults); err != nil {
|
||||
bad = fmt.Errorf("the config value %s cannot be read: %w", key, err)
|
||||
} else {
|
||||
held, bad = l, nil
|
||||
return nil
|
||||
}
|
||||
if held != nil {
|
||||
sayf("%v: the list last read stays", bad)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
read := func() (VerbCallers, error) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if held != nil {
|
||||
return held, nil
|
||||
}
|
||||
if bad != nil {
|
||||
return nil, bad
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
return func() (VerbCallers, error) {
|
||||
if l, err := read(); l != nil || err != nil {
|
||||
return l, err
|
||||
}
|
||||
start.Lock()
|
||||
defer start.Unlock()
|
||||
if l, err := read(); l != nil || err != nil {
|
||||
return l, err
|
||||
}
|
||||
if err := watch(key, handle); err != nil {
|
||||
return nil, fmt.Errorf("the config value %s cannot be read: %w", key, err)
|
||||
}
|
||||
l, err := read()
|
||||
if l == nil && err == nil {
|
||||
err = fmt.Errorf("the config value %s cannot be read: the runtime handed over no value", key)
|
||||
}
|
||||
return l, err
|
||||
}
|
||||
}
|
||||
|
||||
func parseConfiguredVerbCallers(raw json.RawMessage, verbs []string, defaults VerbCallers) (VerbCallers, error) {
|
||||
var text string
|
||||
if err := json.Unmarshal(raw, &text); err == nil || len(bytes.TrimSpace(raw)) == 0 || string(bytes.TrimSpace(raw)) == "null" {
|
||||
return ParseVerbCallers(text, verbs, defaults)
|
||||
}
|
||||
return ParseVerbCallers(string(raw), verbs, defaults)
|
||||
}
|
||||
+8
-23
@@ -12,33 +12,18 @@ import (
|
||||
// A part that reads the seat list wires its reader one way (novox/hq ADR 0636 §1, §7): started from the bootstrapped
|
||||
// definitions, what it holds given to catalogue at once and at every change, read again when the part's path for the
|
||||
// seat's events becomes live, and its two tools `<prefix>_seat_list` and `<prefix>_seat_list_again` served over whatever
|
||||
// reader the part holds at the call. Part is that wiring, so no part writes it again; the part names its tools' prefix
|
||||
// and the callers that may read again, which are its own to give (stdio.VerbCallers' entries).
|
||||
// reader the part holds at the call. Part is that wiring, so no part writes it again; the part names its tools' prefix.
|
||||
|
||||
// Part is a part's reader of the seat list, set once Follow starts it; before, the list counts as unread and the part
|
||||
// acts on nothing new.
|
||||
type Part struct {
|
||||
prefix string
|
||||
callers []string
|
||||
reader atomic.Pointer[Reader]
|
||||
holders atomic.Pointer[func(seat string) []string]
|
||||
prefix string
|
||||
reader atomic.Pointer[Reader]
|
||||
}
|
||||
|
||||
// Holders gives the part the function that answers a seat's holders, by which its callers' entries `seat:<seat>` are
|
||||
// resolved when a call is checked (design 47 G A-295): the part's follower of the assigner's seat-holders view.
|
||||
func (p *Part) Holders(h func(seat string) []string) { p.holders.Store(&h) }
|
||||
|
||||
func (p *Part) holdersOf(seat string) []string {
|
||||
if h := p.holders.Load(); h != nil && *h != nil {
|
||||
return (*h)(seat)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewPart is the wiring of a part whose tools are named `<prefix>_seat_list` and `<prefix>_seat_list_again`, the second
|
||||
// answered only to callers.
|
||||
func NewPart(prefix string, callers []string) *Part {
|
||||
return &Part{prefix: prefix, callers: append([]string(nil), callers...)}
|
||||
// NewPart is the wiring of a part whose tools are named `<prefix>_seat_list` and `<prefix>_seat_list_again`.
|
||||
func NewPart(prefix string) *Part {
|
||||
return &Part{prefix: prefix}
|
||||
}
|
||||
|
||||
// Follow starts the reader over bus from the bootstrapped definitions: what it holds is given to catalogue at once and at
|
||||
@@ -124,7 +109,7 @@ func (p *Part) ToolNames() (read, again string) {
|
||||
// reader has not started.
|
||||
func (p *Part) Tools() []stdio.Tool {
|
||||
read, again := p.ToolNames()
|
||||
shape := ToolsWith(&Reader{}, read, again, p.callers, p.holdersOf)
|
||||
shape := Tools(&Reader{}, read, again)
|
||||
for i := range shape {
|
||||
run := i
|
||||
shape[i].Run = func(args map[string]any) (any, error) {
|
||||
@@ -132,7 +117,7 @@ func (p *Part) Tools() []stdio.Tool {
|
||||
if r == nil {
|
||||
return nil, errors.New("the seat list reader has not started yet: the runtime has not served this module")
|
||||
}
|
||||
return ToolsWith(r, read, again, p.callers, p.holdersOf)[run].Run(args)
|
||||
return Tools(r, read, again)[run].Run(args)
|
||||
}
|
||||
}
|
||||
return shape
|
||||
|
||||
+5
-30
@@ -466,15 +466,9 @@ func (r *Reader) changed() {
|
||||
}
|
||||
|
||||
// Tools are the reader's two runtime tools (ADR 0636 §7), for a host's bundle: read, which says what the reader holds
|
||||
// (every definition, its source and digest) and what it waits for; and again, which makes it read the list now, and
|
||||
// answers only to the callers the host's list names (the operator and the healers). The host names the tools and the list;
|
||||
// again records nothing but the read it asked.
|
||||
func Tools(r *Reader, read, again string, callers []string) []stdio.Tool {
|
||||
return ToolsWith(r, read, again, callers, nil)
|
||||
}
|
||||
|
||||
// ToolsWith is Tools whose callers' entries `seat:<seat>` are resolved by holders (RefusalWith, design 47 G A-295).
|
||||
func ToolsWith(r *Reader, read, again string, callers []string, holders func(seat string) []string) []stdio.Tool {
|
||||
// (every definition, its source and digest) and what it waits for; and again, which makes it read the list now. Every
|
||||
// caller may call both (design 47 H §752, H-A-66). The host names the tools; again records nothing but the read it asked.
|
||||
func Tools(r *Reader, read, again string) []stdio.Tool {
|
||||
return []stdio.Tool{
|
||||
{Name: read,
|
||||
Description: "The seat list this part holds (novox/hq ADR 0636): each seat's definition with its source (trunk or bootstrap) and " +
|
||||
@@ -486,12 +480,9 @@ func ToolsWith(r *Reader, read, again string, callers []string, holders func(sea
|
||||
}},
|
||||
{Name: again,
|
||||
Description: "Read the seat list again now, from the seat " + Seat + " (a hand act for a part that waits or holds a stale definition), " +
|
||||
"and answer what it holds afterwards. Answered only to the operator and the healers.",
|
||||
"and answer what it holds afterwards.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
if err := RefusalWith(again, callers, stdio.CallerOf(args), holders); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Run: func(map[string]any) (any, error) {
|
||||
err := r.Reload()
|
||||
st := r.Status()
|
||||
out := map[string]any{"status": st, "health": st.Health()}
|
||||
@@ -502,19 +493,3 @@ func ToolsWith(r *Reader, read, again string, callers []string, holders func(sea
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
// Refusal is why caller may not make the reader read again, or nil: the caller's proof, never an argument, against
|
||||
// callers, the entries of a verb's list as VerbCallers reads them, so stdio.AnyPerson names every operator's session
|
||||
// the runtime proved (person.<name>) and a module name its instances (ADR 0636 §7).
|
||||
func Refusal(tool string, callers []string, caller string) error {
|
||||
return RefusalWith(tool, callers, caller, nil)
|
||||
}
|
||||
|
||||
// RefusalWith is Refusal whose entries `seat:<seat>` allow the modules holders answers for the seat (stdio.VerbCallers.
|
||||
// AllowedWith, design 47 G A-295).
|
||||
func RefusalWith(tool string, callers []string, caller string, holders func(seat string) []string) error {
|
||||
if err := (stdio.VerbCallers{tool: callers}).AllowedWith(tool, caller, holders); err != nil {
|
||||
return fmt.Errorf("%s is refused to %q: it answers only %s (novox/hq ADR 0636 §7)", tool, caller, strings.Join(callers, ", "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -236,27 +236,21 @@ func TestTheBootstrapIsHeldAndNothingNewIsActedOnUntilTheSeatAnswers(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
// ADR 0636 §7: the two tools read what is held and read again now, the second to its callers only.
|
||||
func TestTheTwoToolsReadTheHeldListAndReadItAgainForTheirCallers(t *testing.T) {
|
||||
// ADR 0636 §7: the two tools read what is held and read again now, each to every caller.
|
||||
func TestTheTwoToolsReadTheHeldListAndReadItAgain(t *testing.T) {
|
||||
owner := &fakeOwner{down: true, table: map[string]string{"node-b": def("node-b", "node", "put")}}
|
||||
r, err := Start(Config{Bus: owner, Bootstrap: Bootstrapped()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
<-r.Ready()
|
||||
callers := []string{stdio.AnyPerson, "mesh-healers"}
|
||||
tools := Tools(r, "seat_list", "seat_list_again", callers)
|
||||
tools := Tools(r, "seat_list", "seat_list_again")
|
||||
out, err := tools[0].Run(map[string]any{})
|
||||
if err != nil || out.(map[string]any)["health"] == "" || !strings.Contains(fmt.Sprint(out.(map[string]any)["status"]), "bootstrap") {
|
||||
t.Fatalf("read: %v %v", out, err)
|
||||
}
|
||||
for caller, allowed := range map[string]bool{"person.jo": true, "ace.mesh-healers": true, "ace.mesh-other": false, "person.al": true, stdio.Unproven: false} {
|
||||
if err := Refusal("seat_list_again", callers, caller); (err == nil) != allowed {
|
||||
t.Fatalf("%s: %v, allowed %v", caller, err, allowed)
|
||||
}
|
||||
}
|
||||
if _, err := tools[1].Run(map[string]any{}); err == nil || !strings.Contains(err.Error(), "refused") || len(owner.asked) != 1 {
|
||||
t.Fatalf("a call without a proven caller read the list again: %v, asks %v", err, owner.asked)
|
||||
if _, err := tools[1].Run(map[string]any{stdio.MetaCaller: "ace.mesh-other"}); err != nil || len(owner.asked) != 2 {
|
||||
t.Fatalf("again by any caller: %v, asks %v", err, owner.asked)
|
||||
}
|
||||
owner.down = false
|
||||
if err := r.Reload(); err != nil || !r.Status().Heard || len(r.Status().Held) != len(Bootstrapped())+1 {
|
||||
@@ -267,7 +261,7 @@ func TestTheTwoToolsReadTheHeldListAndReadItAgainForTheirCallers(t *testing.T) {
|
||||
// the list counts as unread then, and once followed what the reader holds is the catalogue's and a change wakes the part.
|
||||
saved := catalogue.Seats()
|
||||
t.Cleanup(func() { catalogue.UseSeats(saved) }) // Follow sets the catalogue's seats, a global; given back after
|
||||
part := NewPart("assigner", callers)
|
||||
part := NewPart("assigner")
|
||||
if read, again := part.ToolNames(); read != "assigner_seat_list" || again != "assigner_seat_list_again" {
|
||||
t.Fatalf("tool names %s, %s", read, again)
|
||||
}
|
||||
@@ -289,26 +283,6 @@ func TestTheTwoToolsReadTheHeldListAndReadItAgainForTheirCallers(t *testing.T) {
|
||||
if _, ok := catalogue.SeatNamed("node-b"); !ok {
|
||||
t.Fatal("what the part's reader holds is not the catalogue's")
|
||||
}
|
||||
if _, err := part.Tools()[1].Run(map[string]any{}); err == nil || !strings.Contains(err.Error(), "it answers only operator, mesh-healers") {
|
||||
t.Fatalf("again without a proven caller: %v", err)
|
||||
}
|
||||
// A-295: the part's list names seats, `seat:<seat>`, resolved by the holder function it is given when a call is checked.
|
||||
bySeat := []string{stdio.AnyPerson, "seat:mesh-healers"}
|
||||
if err := RefusalWith("seat_list_again", bySeat, "ace.mesh-delivery-watchman", part.holdersOf); err == nil {
|
||||
t.Fatal("a seat entry allowed a module before the part was given its holders")
|
||||
}
|
||||
// HoldersIn reads the seat-holders view as the part last heard it: a seat held once by `<seat>`, a node seat by
|
||||
// `<seat>.<node>`, and no other seat's key.
|
||||
view := map[string][]byte{"mesh-healers": []byte(`{"seat":"mesh-healers","holders":[{"module":"mesh-delivery-watchman","node":"g14"}]}`),
|
||||
"node-tool-runner.ace": []byte(`{"seat":"node-tool-runner","node":"ace","holders":[{"module":"node-tools","node":"ace"}]}`),
|
||||
"mesh-healers-x": []byte(`{"holders":[{"module":"mesh-build-go"}]}`)}
|
||||
part.Holders(HoldersIn(func() (map[string][]byte, error) { return view, nil }))
|
||||
bySeat = append(bySeat, "seat:node-tool-runner")
|
||||
for caller, allowed := range map[string]bool{"ace.mesh-delivery-watchman": true, "ace.mesh-build-go": false, "person.jo": true, "g14.node-tools": true} {
|
||||
if err := RefusalWith("seat_list_again", bySeat, caller, part.holdersOf); (err == nil) != allowed {
|
||||
t.Errorf("again by %s through the seat entry: %v, want allowed %v", caller, err, allowed)
|
||||
}
|
||||
}
|
||||
owner2.table["node-c"] = def("node-c", "node", "put")
|
||||
if err := owner2.say(ChangedEvent, "node-c", SourceTrunk); err != nil || len(woken) == 0 {
|
||||
t.Fatalf("a change did not wake the part: %v", err)
|
||||
|
||||
+4
-28
@@ -53,50 +53,26 @@ func (k KeptSource) History(key string) ([]Revision, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ParseCallers is a callers list as a manifest writes it into an env value: comma-separated, each a module (on any
|
||||
// machine), <machine>.<module> or person.<name> (stdio.Callers).
|
||||
func ParseCallers(list string) stdio.Callers {
|
||||
var out stdio.Callers
|
||||
for _, c := range strings.Split(list, ",") {
|
||||
if c = strings.TrimSpace(c); c != "" {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// CallersEnv is the env value of a first-view tool's callers list, in the owner's tools bundle: MESH_VIEW_CALLERS_<TOOL>,
|
||||
// the tool's name in capitals, a hyphen an underscore.
|
||||
func CallersEnv(tool string) string {
|
||||
return approval.ViewCallersPrefix + strings.ToUpper(strings.ReplaceAll(tool, "-", "_"))
|
||||
}
|
||||
|
||||
// Refusal is why caller may not ask tool, or nil: the caller's proof, never an argument, against the tool's callers
|
||||
// list holding exactly its readers (ADR 0621 §2, ADR 0622 §1); the owner itself is on no list, so it is refused too.
|
||||
func Refusal(tool string, callers stdio.Callers, caller string) error {
|
||||
if callers.Allows(caller) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%s is refused to %q: the tool answers only %s (novox/hq ADR 0621 §2)", tool, caller, strings.Join(callers, ", "))
|
||||
}
|
||||
|
||||
// FirstViewTool is an owner's first-view tool of one of its states (ADR 0621 §1): each call answers one page of what the
|
||||
// state holds now, at the revision its mark says, to the callers its list names and nobody else. It reads only the
|
||||
// state holds now, at the revision its mark says, to every caller (design 47 H §752, H-A-66). It reads only the
|
||||
// owner's own state, so it answers as soon as the runtime is connected, before the owner has asked anyone anything
|
||||
// (ADR 0621 §3).
|
||||
func FirstViewTool(owner, name, state, words string, callers stdio.Callers, values, marks Source, now func() time.Time) stdio.Tool {
|
||||
func FirstViewTool(owner, name, state, words string, values, marks Source, now func() time.Time) stdio.Tool {
|
||||
return stdio.Tool{
|
||||
Name: name,
|
||||
Description: fmt.Sprintf("The first view of %s's state %s (novox/hq ADR 0615, ADR 0621): %s Each value whole by key, at the revision "+
|
||||
"the owner said its views family up to, so a reader then follows the events on that family and asks again only on a gap in "+
|
||||
"revisions. One page at a time: next is the key to ask after for the rest. Answered only to %s; any other caller is refused.",
|
||||
owner, state, words, strings.Join(callers, ", ")),
|
||||
"revisions. One page at a time: next is the key to ask after for the rest.",
|
||||
owner, state, words),
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"after": map[string]any{"type": "string", "description": "the key the page before ended at (its next); none starts at the first"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
if err := Refusal(name, callers, stdio.CallerOf(args)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
after, _ := args["after"].(string)
|
||||
return FirstView(owner, state, values, marks, strings.TrimSpace(after), now())
|
||||
},
|
||||
|
||||
+5
-11
@@ -138,19 +138,13 @@ func subViews(t *testing.T) {
|
||||
t.Fatalf("fallback answer = %+v, gets %d, %v", a, p.gets, err)
|
||||
}
|
||||
})
|
||||
t.Run("each first-view tool answers its callers alone, never the owner, by the proof and not an argument", func(t *testing.T) {
|
||||
callers := ParseCallers("mesh-grants, node-tools,mesh-delivery-assigner")
|
||||
for caller, allowed := range map[string]bool{"novox.mesh-grants": true, "ace.node-tools": true, "g14.mesh-delivery-assigner": true,
|
||||
"novox.mesh-delivery-indexer": false, "novox.mesh-config": false, "person.jochen": false, stdio.Unproven: false} {
|
||||
if err := Refusal("manifests", callers, caller); (err == nil) != allowed {
|
||||
t.Errorf("%q: err = %v, allowed %v", caller, err, allowed)
|
||||
t.Run("a first-view tool answers every caller, the proof or none (design 47 H 752)", func(t *testing.T) {
|
||||
tool := FirstViewTool("mesh-delivery-indexer", "manifests", "modules", "w.", values, marks, now)
|
||||
for _, args := range []map[string]any{{}, {"caller": "novox.mesh-grants"}} {
|
||||
if _, err := tool.Run(args); err != nil {
|
||||
t.Errorf("a call %v is refused: %v", args, err)
|
||||
}
|
||||
}
|
||||
// A caller argument names nobody: a call with no proof is refused.
|
||||
tool := FirstViewTool("mesh-delivery-indexer", "manifests", "modules", "w.", callers, values, marks, now)
|
||||
if _, err := tool.Run(map[string]any{"caller": "novox.mesh-grants"}); err == nil {
|
||||
t.Errorf("an unproven call naming a caller is answered")
|
||||
}
|
||||
})
|
||||
t.Run("a read tool says the keys and the fill, one key, one key's kept history, or a page of values", func(t *testing.T) {
|
||||
r, err := Read("o", "modules", values, marks, "", false, "", now())
|
||||
|
||||
Reference in New Issue
Block a user