A-373 round 2: grants' account reads back its own objects; withheld is answered from a small key beside the list

Builds: design 47 G A-373 (G-22-lead-answers-2.md)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-13 22:09:21 +01:00
parent e2eb99fc19
commit d6d6bd1891
6 changed files with 53 additions and 11 deletions
+19
View File
@@ -5327,3 +5327,22 @@ func TestAStreamThePartCreatesAndTheBusLacksIsAnEmptyFirstView(t *testing.T) {
})
}
}
type keptObjects map[string][]byte
func (m keptObjects) PutObject(name string, data []byte) error { m[name] = data; return nil }
func (m keptObjects) GetObject(name string) ([]byte, error) { return m[name], nil }
// Design 47 G A-373: with the list kept as an object the tools bundle cannot open, the seat verb withheld still answers, from the small key
// the process keeps beside it.
func TestWithheldIsAnsweredWhileTheListIsAnObject(t *testing.T) {
b := fixture()
process := partOn(b)
process.Store = grants.BigValues(ownStore{b}, keptObjects{})
process.Compose()
tools := partOn(b)
tools.Store = grants.BigValues(ownStore{b}, nil)
if got, err := tools.WithheldOn("a"); err != nil || got.Node != "a" {
t.Errorf("withheld from the tools = %+v, %v", got, err)
}
}
@@ -94,6 +94,11 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
{GrantsModule, "$JS.API.STREAM.CREATE.OBJ_mesh-grants-user-list", true},
{GrantsModule, "$O.mesh-grants-user-list.C.abc", true},
{GrantsModule, "$JS.API.STREAM.PURGE.OBJ_mesh-grants-user-list", true},
// A-373: the part reads back what it keeps in its own bucket, as the node-engine does (an ordered consumer), and no other bucket.
{GrantsModule, "$JS.API.CONSUMER.CREATE.OBJ_mesh-grants-user-list.abc.$O.mesh-grants-user-list.C.abc", true},
{GrantsModule, "$JS.API.CONSUMER.DELETE.OBJ_mesh-grants-user-list.abc", true},
{GrantsModule, "$JS.FC.OBJ_mesh-grants-user-list.abc.def.ghi", true},
{GrantsModule, "$JS.API.CONSUMER.CREATE.OBJ_declaration-files-novox.abc.$O.declaration-files-novox.C.abc", false},
{GrantsModule, "$O.declaration-files-novox.C.abc", false},
{GrantsModule, "$JS.API.STREAM.DELETE.OBJ_mesh-grants-user-list", false},
{"mesh-delivery-builder", "$O.mesh-grants-user-list.C.abc", false},
File diff suppressed because one or more lines are too long
@@ -65,6 +65,11 @@ func GrantsUserListWrites() []string {
"$JS.API.DIRECT.GET." + s + ".>",
"$JS.API.STREAM.MSG.GET." + s,
"$O." + obj + ".>",
// And reads back an object of its own bucket, as the node-engine does (an ordered consumer; design 47 G A-373): what it keeps
// as the objects the keys `list` and `pass` name.
"$JS.API.CONSUMER.CREATE." + s + ".*.$O." + obj + ".C.*",
"$JS.API.CONSUMER.DELETE." + s + ".*",
"$JS.FC." + s + ".>",
}
}
@@ -33,7 +33,9 @@ type bigPointer struct {
// BigValues is store with the keys `list` and `pass` of the state user-list kept in objects. With no objects (the tools') a value is
// kept in the key whole, and a key that names an object is an error saying where the value is.
func BigValues(store Store, objects BigObjects) Store { return bigStore{Store: store, objects: objects} }
func BigValues(store Store, objects BigObjects) Store {
return bigStore{Store: store, objects: objects}
}
type bigStore struct {
Store
+19 -8
View File
@@ -31,6 +31,9 @@ const (
// StateGrants is the part's grants by module and fingerprint, the key layout of the controller's (grants.go).
StateGrants = grantsstate.PartGrantsState
KeyList = "list"
// KeyWithheld is the marked subjects withheld by node, kept small beside the list (which is an object the tools cannot open) for
// the seat verb withheld (design 47 G A-373).
KeyWithheld = "withheld"
// KeyPass is the last pass's result, and KeyAsked a tool's ask to compose again now, both in StateUserList.
KeyPass = "pass"
KeyAsked = "asked"
@@ -421,6 +424,9 @@ func (p *Part) Compose() Result {
}
}
}
if data, err := json.Marshal(st.Withheld); err == nil {
p.changed(&res, StateUserList, KeyWithheld, data)
}
// The accounts the vault mints from, said in the state only it reads (ADR 0561 §2).
if p.Store != nil {
p.writeAccounts(&res, in, listRecs)
@@ -699,15 +705,20 @@ func (p *Part) WithheldOn(node string) (meshgrants.Withheld, error) {
return meshgrants.Withheld{}, errors.New("withheld names a node")
}
out := meshgrants.Withheld{Node: node, Modules: []meshgrants.WithheldModulesItem{}}
raw, _, found, err := p.Store.Get(StateUserList, KeyList)
if err != nil {
return out, fmt.Errorf("its own user list cannot be read: %w", err)
}
if !found {
return out, errors.New("nothing composed yet: grants_compose_now composes it")
}
var st UserListState
if err := json.Unmarshal(raw, &st); err != nil {
raw, _, found, err := p.Store.Get(StateUserList, KeyWithheld)
if err == nil && found {
err = json.Unmarshal(raw, &st.Withheld)
} else if err == nil {
// Before the process kept the small key: the list's own, which only a reader that can open it reads.
if raw, _, found, err = p.Store.Get(StateUserList, KeyList); err == nil {
if !found {
return out, errors.New("nothing composed yet: grants_compose_now composes it")
}
err = json.Unmarshal(raw, &st)
}
}
if err != nil {
return out, fmt.Errorf("its own user list cannot be read: %w", err)
}
for _, w := range st.Withheld[node] {