Fix 9.7b: one reading of who holds a seat, beside the seat list; operatorask takes it
Builds: design 47 G A-126 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Package operatorask is a module's asking of a person through the seat that routes asks to the operator (design 47 G
|
||||
// A-101, §700, A-74): the seat's holder is found on the seat list, an ask is published under the module's own name, the
|
||||
// A-101, §700, A-74): the seat's holder is read by seatlist.HolderOf, an ask is published under the module's own name, the
|
||||
// router's record of it is read for the warrant, and the router's `decided` is heard. It is shared code, so no module
|
||||
// keeps its own copy; it names no seat, verb or module: the generated contracts' names and types are its parameters.
|
||||
package operatorask
|
||||
@@ -10,45 +10,28 @@ import (
|
||||
"fmt"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
)
|
||||
|
||||
// Caller calls a seat verb or module tool as `seat:<seat>.<verb>` or `<module>.<tool>` and returns its answer
|
||||
// (stdio.Ask is one; so is a process's calls).
|
||||
type Caller func(key string, body any) (json.RawMessage, error)
|
||||
type Caller = seatlist.HolderCaller
|
||||
|
||||
// Contract is what the asker takes from the generated contracts: the verb that answers the seat list with its seats
|
||||
// (`Lists` is its call key, `ListBody` its input) and the asking seat and its state of the router's records.
|
||||
// Contract is what the asker takes from the generated contracts: the asking seat and its state of the router's records.
|
||||
type Contract struct {
|
||||
Lists string
|
||||
ListBody any
|
||||
Seat string
|
||||
Seat string
|
||||
// StateAsks is the seat's state holding the router's record of each ask.
|
||||
StateAsks string
|
||||
}
|
||||
|
||||
// Bucket is the bucket of the router's records: the seat's state in the bucket of the seat's holder on the seat list.
|
||||
// Bucket is the bucket of the router's records: the seat's state in the bucket of the seat's holder, as seatlist reads it
|
||||
// (design 47 G A-126).
|
||||
func Bucket(call Caller, c Contract) (string, error) {
|
||||
raw, err := call(c.Lists, c.ListBody)
|
||||
module, err := seatlist.HolderOf(call, c.Seat)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("who holds the seat %s is not asked of %s: %w", c.Seat, c.Lists, err)
|
||||
return "", fmt.Errorf("the router's record of an ask is not read: %w", err)
|
||||
}
|
||||
var held struct {
|
||||
Seats []struct {
|
||||
Seat string `json:"seat"`
|
||||
Holders []struct {
|
||||
Module string `json:"module"`
|
||||
} `json:"holders"`
|
||||
} `json:"seats"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &held); err != nil {
|
||||
return "", fmt.Errorf("the answer of %s is not the seat list's: %w", c.Lists, err)
|
||||
}
|
||||
for _, s := range held.Seats {
|
||||
if s.Seat == c.Seat && len(s.Holders) > 0 {
|
||||
return s.Holders[0].Module + "_" + c.StateAsks, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no module holds the seat %s on the seat list, so the router's record of an ask is not read", c.Seat)
|
||||
return module + "_" + c.StateAsks, nil
|
||||
}
|
||||
|
||||
// Asker asks as one module. W is the generated contract's warrant type.
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestTheAskerFindsTheHolderPublishesReadsTheWarrantAndHearsDecided(t *testin
|
||||
var published any
|
||||
var heard func(stdio.Envelope) error
|
||||
a := &Asker[warrant]{
|
||||
Module: "me", Contract: Contract{Lists: "seat:lister.list", ListBody: map[string]bool{"seats": true}, Seat: "router-seat", StateAsks: "asks"},
|
||||
Module: "me", Contract: Contract{Seat: "router-seat", StateAsks: "asks"},
|
||||
Call: call,
|
||||
Record: func(b, i string) (*stdio.StateEntry, error) {
|
||||
bucket, id = b, i
|
||||
@@ -39,7 +39,7 @@ func TestTheAskerFindsTheHolderPublishesReadsTheWarrantAndHearsDecided(t *testin
|
||||
t.Errorf("Ask published %v on %q: %v", published, subject, err)
|
||||
}
|
||||
state, w, err := a.Where("a1")
|
||||
if err != nil || state != "chosen" || w == nil || w.Choice != "go" || bucket != "holder_asks" || id != "a1" || len(asked) != 1 || asked[0] != "seat:lister.list" {
|
||||
if err != nil || state != "chosen" || w == nil || w.Choice != "go" || bucket != "holder_asks" || id != "a1" || len(asked) != 1 || asked[0] != "seat:mesh-module-assigner.assignments" {
|
||||
t.Errorf("Where = %q %+v %v, read %q %q after %v", state, w, err, bucket, id, asked)
|
||||
}
|
||||
var got []warrant
|
||||
|
||||
Reference in New Issue
Block a user