Assigner review 1: the drop tool judges every watched branch; the pass row runs the pass
The tool now reads every watched branch's catalog half through the seat mesh-catalog's verbs registrations and revision, as the pass's world.trunk holds them; the pass table drives p.wants, so it fails without the clean state's call; the manifest test names assigner_assignment_drop. Builds: design 47 H2 H-A-509 (and the lead's answer of review round 1)
This commit is contained in:
@@ -4,12 +4,16 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
)
|
||||
|
||||
// assignmentDropTool drops one assignment key of a module no manifest names any more by hand (design 47 H2 H-A-509): a
|
||||
@@ -18,14 +22,15 @@ import (
|
||||
const assignmentDropTool = "assigner_assignment_drop"
|
||||
|
||||
// assignmentLeft is why a module key `<node>.<module>` is not dropped, "" when it may be (H-A-509 and its second
|
||||
// addendum): only when no manifest the trunk holds names the module and the node key does not name it, since the node key
|
||||
// is the commit of a write and a hand act never leaves one node's keys disagreeing; nothing while the trunk is empty.
|
||||
// addendum, and the lead's answer of review round 1): only when no watched branch's catalog half holds the module (trunk, as
|
||||
// world.trunk is) and the node key does not name it, since the node key is the commit of a write and a hand act never leaves
|
||||
// one node's keys disagreeing; nothing while no half holds any module.
|
||||
func assignmentLeft(node, module string, trunk map[string]bool, nodeRaw []byte, nodeFound bool) string {
|
||||
switch {
|
||||
case len(trunk) == 0:
|
||||
return "the trunk holds no manifest yet, so no module is known to be retired"
|
||||
return "no watched branch's catalog half holds a module yet, so no module is known to be retired"
|
||||
case trunk[module]:
|
||||
return "a manifest the trunk holds names " + module
|
||||
return "a watched branch's catalog half holds " + module
|
||||
case !nodeFound:
|
||||
return ""
|
||||
}
|
||||
@@ -40,7 +45,7 @@ func assignmentLeft(node, module string, trunk map[string]bool, nodeRaw []byte,
|
||||
}
|
||||
|
||||
// dropAssignment deletes the module key of module on node, the act first recorded through the seat mesh-hand-acts; trunk
|
||||
// answers the modules the trunk holds.
|
||||
// answers every module a watched branch's catalog half holds.
|
||||
func dropAssignment(st seatStore, ask func(string, any) (json.RawMessage, error), trunk func() (map[string]bool, error), node, module, why, by string) (any, error) {
|
||||
switch {
|
||||
case node == "" || module == "":
|
||||
@@ -67,7 +72,7 @@ func dropAssignment(st seatStore, ask func(string, any) (json.RawMessage, error)
|
||||
}
|
||||
modules, err := trunk()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the trunk's modules cannot be read, so %s stays: %w", key, err)
|
||||
return nil, fmt.Errorf("the watched branches' modules cannot be read, so %s stays: %w", key, err)
|
||||
}
|
||||
nodeRaw, _, nodeFound, err := st.get(mma.StateAssignments, nodeKey)
|
||||
if err != nil {
|
||||
@@ -86,16 +91,47 @@ func dropAssignment(st seatStore, ask func(string, any) (json.RawMessage, error)
|
||||
return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil
|
||||
}
|
||||
|
||||
// trunkModules is the modules the trunk holds, asked of the indexer's first view of modules (ADR 0596, ADR 0621).
|
||||
func trunkModules(ask func(string, any) (json.RawMessage, error)) func() (map[string]bool, error) {
|
||||
// watchedModules is every module any watched branch's catalog half holds, as the pass's world.trunk is (design 47 H2 H-A-509,
|
||||
// the lead's answer of review round 1): the watched branches of the seat mesh-catalog's registrations, each branch's revision
|
||||
// read whole through the verb revision, page by page; a branch with none yet holds none.
|
||||
func watchedModules(call mcc.Call) func() (map[string]bool, error) {
|
||||
return func() (map[string]bool, error) {
|
||||
mods, err := indexerView(ask, indexerModules)
|
||||
raw, err := call(mcc.RegistrationsVerb, meshcatalog.RegistrationsInput{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make(map[string]bool, len(mods))
|
||||
for name := range mods {
|
||||
out[name] = true
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s answered: %s", mcc.RegistrationsVerb, said)
|
||||
}
|
||||
var regs meshcatalog.RegistrationsAnswer
|
||||
if err := json.Unmarshal(answer, ®s); err != nil || regs.Registrations == nil {
|
||||
return nil, fmt.Errorf("%s answered no registrations: %v", mcc.RegistrationsVerb, err)
|
||||
}
|
||||
branches := map[string]bool{}
|
||||
for _, reg := range regs.Registrations {
|
||||
for _, b := range reg.Branches {
|
||||
branches[b] = true
|
||||
}
|
||||
}
|
||||
out := map[string]bool{}
|
||||
for _, branch := range slices.Sorted(maps.Keys(branches)) {
|
||||
for after := ""; ; {
|
||||
a, err := askCandidatePage(call, meshcatalog.RevisionInput{Branch: branch, After: after})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the catalog half of %s cannot be read: %w", branch, err)
|
||||
}
|
||||
if a.NoneYet {
|
||||
break
|
||||
}
|
||||
for _, e := range a.Entries {
|
||||
out[e.Module] = true
|
||||
}
|
||||
if a.Next == "" {
|
||||
break
|
||||
}
|
||||
after = a.Next
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -104,9 +140,9 @@ func trunkModules(ask func(string, any) (json.RawMessage, error)) func() (map[st
|
||||
// assignmentDropTools is the tool over the runtime's states.
|
||||
func assignmentDropTools(st seatStore, ask func(string, any) (json.RawMessage, error), trunk func() (map[string]bool, error)) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: assignmentDropTool, Description: "Drop one assignment key by hand (design 47 H2 H-A-509): the module " +
|
||||
"key <node>.<module> of the seat mesh-module-assigner's assignments, for a module no manifest the trunk holds names any more " +
|
||||
"key <node>.<module> of the seat mesh-module-assigner's assignments, for a module no watched branch's catalog half holds any more " +
|
||||
"(a retired module's key, which may predate the value's version), as the clean state of the pass drops it. Refused while a " +
|
||||
"manifest of the trunk names the module, while the node key <node>.node still names it, or with no key there. Recorded as a " +
|
||||
"watched branch's catalog half holds the module, while the node key <node>.node still names it, or with no key there. Recorded as a " +
|
||||
"hand act first.",
|
||||
Input: schema(map[string]string{"node": "the node's name", "module": "the module's name", "why": "why the key is dropped"},
|
||||
[]string{"node", "module", "why"}),
|
||||
|
||||
+32
-3
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
plc "mesh-delivery-assigner/internal/assignment"
|
||||
@@ -83,6 +84,33 @@ func TestARetiredModulesAssignmentKeyIsDropped(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// The tool judges against every watched branch's half, as the pass does (the lead's answer of review round 1): the branches
|
||||
// of the registrations, each read page by page; a branch with none yet holds none.
|
||||
t.Run("every watched branch", func(t *testing.T) {
|
||||
call := func(verb string, body any) (json.RawMessage, error) {
|
||||
switch verb {
|
||||
case meshcatalogclient.RegistrationsVerb:
|
||||
return json.Marshal(meshcatalog.RegistrationsAnswer{Registrations: []meshcatalog.Registration{{Module: "web", Branches: []string{"main", "feature"}}, {Module: "db", Branches: []string{"fresh"}}}})
|
||||
case meshcatalogclient.RevisionVerb:
|
||||
in := body.(meshcatalog.RevisionInput)
|
||||
switch {
|
||||
case in.Branch == "main" && in.After == "":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "web"}}, Next: "web"})
|
||||
case in.Branch == "main":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "db"}}})
|
||||
case in.Branch == "feature":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "new"}}})
|
||||
}
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{NoneYet: true})
|
||||
}
|
||||
return nil, errors.New("no such verb " + verb)
|
||||
}
|
||||
got, err := watchedModules(call)()
|
||||
if err != nil || len(got) != 3 || !got["web"] || !got["db"] || !got["new"] {
|
||||
t.Errorf("watchedModules = %v, %v; want web, db and new", got, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("at the pass", func(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
@@ -99,12 +127,13 @@ func TestARetiredModulesAssignmentKeyIsDropped(t *testing.T) {
|
||||
for k, v := range kv.values {
|
||||
p.w.put(plc.AssignmentsBucket(), k, v)
|
||||
}
|
||||
trunk := map[string]meshcatalog.ModulesByModuleValue{}
|
||||
// web is held by a watched branch that is not the trunk's first: the pass judges against every watched branch's half.
|
||||
for _, n := range c.trunk {
|
||||
trunk[n] = meshcatalog.ModulesByModuleValue{}
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fpTest, Repository: "novox/" + n, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, "feature", n, mod)
|
||||
}
|
||||
for range 2 {
|
||||
p.retiredAssignments(context.Background(), trunk)
|
||||
p.wants(context.Background())
|
||||
}
|
||||
for _, key := range []string{checker, web, old, "novox.node"} {
|
||||
_, there := kv.values[key]
|
||||
|
||||
@@ -417,7 +417,7 @@ func serveTools() error {
|
||||
tools = append(tools, whyTools(runtimeStore{})...)
|
||||
tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...)
|
||||
tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...)
|
||||
tools = append(tools, assignmentDropTools(runtimeStore{}, stdio.Ask, trunkModules(stdio.Ask))...) // a retired module's assignment key (H-A-509)
|
||||
tools = append(tools, assignmentDropTools(runtimeStore{}, stdio.Ask, watchedModules(stdio.Ask))...) // a retired module's assignment key (H-A-509)
|
||||
tools = append(tools, asksTools(stdio.QueueWaiting, stdio.State(process.TakenState), stdio.Ask)...) // the seat's work queue (§777)
|
||||
tools = append(tools, keepNowTools(stdio.Ask)...)
|
||||
tools = append(tools, validateBeforeTools(runtimeStore{})...) // what a validate step did not count (§814) // the keeping by hand (§813 (2))
|
||||
|
||||
@@ -116,8 +116,8 @@ func TestManifest(t *testing.T) {
|
||||
// which lists and asks again what each node's engine reads.
|
||||
if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks",
|
||||
"assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies",
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5) and assigner_why (design 47 G A-439)", m.Tools)
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5), assigner_why (design 47 G A-439) and assigner_assignment_drop after assigner_want_drop (design 47 H2 H-A-509)", m.Tools)
|
||||
}
|
||||
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
||||
t.Errorf("runs-as = %q: the bundle runs on the assigner's own account (ADR 0621 §1)", m.RunsAs)
|
||||
|
||||
Reference in New Issue
Block a user