Let another module's call of a module tool run unmarked before the catalog half is read
The take-in's call of the forge bridge's tool was refused while the runner's catalog half was unread: a module tool names no class, and its marks live only in the half the take-in makes. A module tool whose proven caller is another module's account now runs unmarked then, logged once per tool with its caller; the console's account (the runner's own), a person, the controller and an unproven caller still wait and are judged as before. Builds: design 47 G lead answers A-389 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -3,6 +3,7 @@ package approval
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -93,9 +94,10 @@ func (unread) Newest(string) (Entry, bool) { return Entry{}, fa
|
||||
func (u unread) Definitions() map[string]seatdef.Definition { return u.defs }
|
||||
func (unread) Entries() []Entry { return nil }
|
||||
|
||||
// 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.
|
||||
// Design 47 G lead answers A-387, A-388, A-389 (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, a module's own first-view tools, and a module tool another module's account calls, logged once per tool;
|
||||
// it holds every other call as before.
|
||||
func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) {
|
||||
defs := map[string]seatdef.Definition{}
|
||||
for _, d := range seatlist.Bootstrapped() {
|
||||
@@ -103,46 +105,65 @@ func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) {
|
||||
}
|
||||
defs["marked"] = seatdef.Definition{Seat: "marked", Verbs: []seatdef.Verb{{Name: "look", Class: seatdef.ClassRead, NeedsApproval: true}}}
|
||||
waited := 0
|
||||
var logged []string
|
||||
g := New(Deps{Node: "n1", Runner: "node-tools", Catalog: unread{defs: defs}, Wait: func(time.Duration) error {
|
||||
waited++
|
||||
return errors.New("still unread")
|
||||
}})
|
||||
}, Logf: func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }})
|
||||
for _, tc := range []struct {
|
||||
seat, name string
|
||||
runs bool
|
||||
env map[string]string
|
||||
caller string
|
||||
own bool
|
||||
}{
|
||||
{"mesh-catalog", "registrations", true, nil},
|
||||
{"mesh-catalog", "revision", true, nil},
|
||||
{"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},
|
||||
{"mesh-catalog", "registrations", true, nil, "", false},
|
||||
{"mesh-catalog", "revision", true, nil, "", false},
|
||||
{"mesh-catalog", "entry", true, nil, "", false},
|
||||
{"mesh-delivery", "source", true, nil, "", false},
|
||||
{"mesh-broker", "list", true, nil, "", false},
|
||||
{"mesh-catalog", "seat-definitions", true, nil, "", false},
|
||||
{"mesh-catalog", "modules", true, nil, "", false},
|
||||
{"git", "pull", true, nil, "", false},
|
||||
{"git", "merge-pull", false, nil, "", false}, // an act
|
||||
{"mesh-broker", "create", false, nil, "", false}, // an act
|
||||
{"mesh-delivery-checker", "try", false, nil, "", false}, // names no class, so no read (A-388)
|
||||
{"operator-channel", "tell", false, nil, "", false}, // names no class
|
||||
{"marked", "look", false, nil, "", false}, // a read marked needs-approval
|
||||
{"unheld", "list", false, nil, "", false}, // a seat the runner holds no definition of
|
||||
{"mesh-broker", "events", false, nil, "", false},
|
||||
// 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"}},
|
||||
{"", "first-things", true, map[string]string{"MESH_VIEW_CALLERS_FIRST_THINGS": "grants"}},
|
||||
{"", "read_modules", false, map[string]string{"MESH_VIEW_CALLERS_MODULES": "grants"}},
|
||||
{"mesh-catalog", "register", false, nil},
|
||||
{"mesh-delivery", "registrations", false, nil},
|
||||
{"", "registrations", false, nil}, // a module's tool of that name is no seat verb
|
||||
{"", "revision", false, nil},
|
||||
{"", "modules", true, map[string]string{"MESH_VIEW_CALLERS_MODULES": "grants"}, "", false},
|
||||
{"", "first-things", true, map[string]string{"MESH_VIEW_CALLERS_FIRST_THINGS": "grants"}, "", false},
|
||||
{"", "read_modules", false, map[string]string{"MESH_VIEW_CALLERS_MODULES": "grants"}, "", false},
|
||||
{"mesh-catalog", "register", false, nil, "", false},
|
||||
{"mesh-delivery", "registrations", false, nil, "", false},
|
||||
{"", "registrations", false, nil, "", false}, // a module's tool of that name is no seat verb
|
||||
{"", "revision", false, nil, "", false},
|
||||
// A-389: a module tool another module's account calls runs unmarked; called otherwise it is held.
|
||||
{"", "bridge_merged_message", true, nil, "n2.mesh-delivery-forge-bridge", false},
|
||||
{"", "bridge_merged_message", true, nil, "n1.mesh-delivery-forge-bridge", false}, // logged once
|
||||
{"", "read_modules", true, nil, "n1.mesh-delivery-runner", false},
|
||||
{"", "bridge_merged_message", false, nil, "n1.node-tools", false}, // the console's and its sessions' account
|
||||
{"", "bridge_merged_message", false, nil, "n2.node-tools", false}, // another machine's console
|
||||
{"", "bridge_merged_message", false, nil, "person.operator", false}, // a person
|
||||
{"", "bridge_merged_message", false, nil, "controller", false},
|
||||
{"", "bridge_merged_message", false, nil, "unproven", false},
|
||||
{"", "bridge_merged_message", false, nil, "n1.mesh-delivery-indexer", false}, // the tool's own module
|
||||
{"", "ledger_repair", false, nil, "n1.mesh-delivery-runner", true}, // the runner's own tool
|
||||
{"git", "merge-pull", false, nil, "n1.mesh-delivery-runner", false}, // a seat verb's act is no module tool
|
||||
} {
|
||||
ran := false
|
||||
address := tc.seat + "." + tc.name
|
||||
if tc.seat == "" {
|
||||
address = "mesh-delivery-indexer." + tc.name
|
||||
}
|
||||
caller := tc.caller
|
||||
if caller == "" {
|
||||
caller = "node-tools"
|
||||
}
|
||||
_, err := g.Run(Call{Address: address, Module: "mesh-delivery-indexer", Seat: tc.seat, Name: tc.name, Fingerprint: "fp1",
|
||||
Caller: "node-tools", Env: tc.env}, func() (any, error) { ran = true; return "ok", nil })
|
||||
Caller: caller, Env: tc.env, Own: tc.own}, func() (any, error) { ran = true; return "ok", nil })
|
||||
if ran != tc.runs || (err == nil) != tc.runs {
|
||||
t.Errorf("%s: ran %v (%v), want ran %v", address, ran, err, tc.runs)
|
||||
}
|
||||
@@ -150,7 +171,14 @@ func TestAnUnreadCatalogHalfLetsItsOwnReadsThrough(t *testing.T) {
|
||||
t.Errorf("%s: refused with %v, want the marks not read yet", address, err)
|
||||
}
|
||||
}
|
||||
if waited != 12 {
|
||||
t.Errorf("the other calls waited for the catalog half %d times, want 12 (the start reads wait for nothing)", waited)
|
||||
if waited != 20 {
|
||||
t.Errorf("the other calls waited for the catalog half %d times, want 20 (the start reads wait for nothing)", waited)
|
||||
}
|
||||
want := []string{
|
||||
"[approval] mesh-delivery-indexer.bridge_merged_message called by n2.mesh-delivery-forge-bridge: run unmarked before the catalog half is read",
|
||||
"[approval] mesh-delivery-indexer.read_modules called by n1.mesh-delivery-runner: run unmarked before the catalog half is read",
|
||||
}
|
||||
if strings.Join(logged, "\n") != strings.Join(want, "\n") {
|
||||
t.Errorf("logged %q, want each module tool run unmarked once with its caller %q", logged, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ type Gate struct {
|
||||
unserved map[string][]string
|
||||
// unmarkedAt is each caller's address it last called unmarked, so a mark added since is named (§12).
|
||||
unmarkedAt map[string]bool
|
||||
// unmarkedLogged is each module tool already logged as run unmarked before the catalog half is read (A-389).
|
||||
unmarkedLogged map[string]bool
|
||||
// inFlight is each ask whose recording runs now.
|
||||
inFlight map[string]bool
|
||||
// failingSince is when the state approvals began to fail; zero while it is read.
|
||||
|
||||
+28
-2
@@ -90,15 +90,41 @@ func (g *Gate) startRead(c Call) bool {
|
||||
return i >= 0 && def.Verbs[i].Class == seatdef.ClassRead && !def.Verbs[i].NeedsApproval
|
||||
}
|
||||
|
||||
// calledByModule says a module tool runs unmarked while the catalog half is unread (design 47 G lead answers A-389): one
|
||||
// whose proven caller is another module's account, `<node>.<module>` naming neither the tool's module nor the runner's
|
||||
// own, which is the account the console and the sessions through it call as; a person's, the controller's or an unproven
|
||||
// caller is none. The runner's own tools served under a module's name are no module tool. Each such tool is logged once,
|
||||
// with its caller.
|
||||
func (g *Gate) calledByModule(c Call) bool {
|
||||
if c.Seat != "" || c.Own || strings.HasPrefix(c.Caller, "person.") {
|
||||
return false
|
||||
}
|
||||
node, module, ok := strings.Cut(c.Caller, ".")
|
||||
if !ok || node == "" || module == "" || strings.Contains(module, ".") || module == c.Module || module == g.d.Runner {
|
||||
return false
|
||||
}
|
||||
g.mu.Lock()
|
||||
if g.unmarkedLogged == nil {
|
||||
g.unmarkedLogged = map[string]bool{}
|
||||
}
|
||||
first := !g.unmarkedLogged[c.Address]
|
||||
g.unmarkedLogged[c.Address] = true
|
||||
g.mu.Unlock()
|
||||
if first {
|
||||
g.d.Logf("[approval] %s called by %s: run unmarked before the catalog half is read", c.Address, c.Caller)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 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
|
||||
// (A-387), and so does a module tool another module calls (A-389); 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 g.startRead(c) {
|
||||
if g.startRead(c) || g.calledByModule(c) {
|
||||
return Marks{Module: c.Module}, nil
|
||||
}
|
||||
if g.d.Wait != nil {
|
||||
|
||||
Reference in New Issue
Block a user