assigner: say an unlisted module on every path; no registration, no branches (H-A-144)

Review round 1: an unlisted module was lost where the composer blamed a module.
It is now said in the failed or could-not-run words where one is set, else as a
warning. Once registrations are held, a module none names has no watched
branches and is unlisted, never composed from the branches the client follows;
before the first registrations the gate's source's branches stand in, in its
order. A module is judged unlisted by its own watched branches.

Builds: design 47 H H-A-143, H-A-144, G §532
This commit is contained in:
2026-11-20 15:35:59 +01:00
parent f98d5ec748
commit 27e96a2a1b
4 changed files with 112 additions and 46 deletions
@@ -301,9 +301,26 @@ const notTried = "not tried: the search reached its bound"
// it, on the node's own account; a verdict with no `blamed` (a composer before §721) is judged as before, with the warning "the
// composer names no culprits"; otherwise the machine passes, with a warning for each other module blamed there.
//
// unlisted are the modules the machine is assigned that no watched branch lists: each is said in the machine's reason, or as a
// warning where it composes, never dropped in silence (H-A-143).
// unlisted are the modules the machine is assigned that none of their watched branches lists: each is said on every path, in the
// machine's failed or could-not-run words where one is set, else as a warning, never dropped in silence (H-A-143, H-A-144).
func judgeRun(module string, run meshwants.CompositionRun, unlisted []string) machineEnd {
end := judgeVerdict(module, run)
for _, u := range unlisted {
said := run.Machine + " is assigned " + u + ", which no watched branch lists (H-A-143)"
switch {
case end.failed != "":
end.failed += "; " + said
case end.couldNot != "":
end.couldNot += "; " + said
default:
end.warnings = append(end.warnings, said)
}
}
return end
}
// judgeVerdict is judgeRun before the unlisted modules are said.
func judgeVerdict(module string, run meshwants.CompositionRun) machineEnd {
node := run.Machine
if run.Ended == nil {
return machineEnd{couldNot: node + ": the step stopped before its composition run " + runKeyOf(run.Candidate, node) + " ended"}
@@ -319,14 +336,6 @@ func judgeRun(module string, run meshwants.CompositionRun, unlisted []string) ma
return machineEnd{couldNot: node + " was not judged: " + m.NotJudged}
}
why := strings.Join(appendSome(append(slices.Clone(m.Problems), m.Refusals...), m.Reason), "; ")
var notListed []string
for _, u := range unlisted {
notListed = append(notListed, node+" is assigned "+u+", which no watched branch lists (H-A-143)")
}
if !m.Composes && len(notListed) > 0 {
why = strings.Join(appendSome(notListed, why), "; ")
notListed = nil
}
switch {
case m.Blamed == nil && !m.Composes: // an old composer (§721)
return machineEnd{judged: true, failed: node + " does not compose: " + why, warnings: []string{node + ": the composer names no culprits"}}
@@ -348,7 +357,7 @@ func judgeRun(module string, run meshwants.CompositionRun, unlisted []string) ma
if len(own) > 0 {
end.failed, end.couldNot = node+" holds "+module+": "+strings.Join(own, "; "), ""
}
end.warnings = append(others, notListed...)
end.warnings = others
return end
}
@@ -525,8 +534,9 @@ func caseOf(half mcc.Half) (map[string]composer.Manifest, map[string]string, err
return manifests, none, nil
}
// acrossBranches is the catalog half a machine's composition reads (design 47 H-A-143, G §532): each module's entry from the newest
// revision of the first of its watched branches, in its registration's order, that lists it; the candidate's revision replaces its
// acrossBranches is the catalog half a machine's composition reads (design 47 H-A-143, H-A-144, G §532): each module's entry from
// the newest revision of the first of its watched branches, in its registration's order, that lists it, none for a module with no
// watched branches; the candidate's revision replaces its
// branch's newest for the modules it moves (its movers and the step's module), and the whole of it where it is that branch's newest
// or the branch's is not held. The half keeps the candidate's revision, its definitions with it.
func acrossBranches(step meshwants.StepRun, candidate mcc.Half, newest map[string]mcc.Half, watched func(module string) []string) mcc.Half {
@@ -557,11 +567,7 @@ func acrossBranches(step meshwants.StepRun, candidate mcc.Half, newest map[strin
if _, done := out.Entries[name]; done {
continue
}
order := watched(name)
if len(order) == 0 { // no branch is followed yet: the step's own
order = []string{step.Branch}
}
for _, b := range order {
for _, b := range watched(name) { // none: no watched branch lists it, it is unlisted (H-A-144)
if e, ok := halves[b].Entries[name]; ok {
out.Entries[name] = e
break
@@ -572,17 +578,18 @@ func acrossBranches(step meshwants.StepRun, candidate mcc.Half, newest map[strin
return out
}
// unlistedOn is the modules the assignments place on node that no watched branch's newest revision lists (H-A-143), by name.
// unlistedOn is the modules the assignments place on node that the newest revision of none of their watched branches lists, a
// module with no watched branches among them (H-A-143, H-A-144), by name.
func (r *compositionRun) unlistedOn(node string) []string {
if r.assigned == nil || r.newest == nil {
if r.assigned == nil || r.newest == nil || r.watched == nil {
return nil
}
newest := r.newest()
var out []string
for _, m := range r.assigned(node) {
listed := false
for _, h := range newest {
if _, ok := h.Entries[m]; ok {
for _, b := range r.watched(m) {
if _, ok := newest[b].Entries[m]; ok {
listed = true
break
}
@@ -267,13 +267,20 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
return map[string]mcc.Half{"master": {Revision: meshcatalog.CatalogRevision{Branch: "master", Revision: 2},
Entries: map[string]meshcatalog.CatalogEntry{"f1-circuits": {Module: "f1-circuits", Fp: "f1", Manifest: map[string]any{"module": "f1-circuits"}}}}}
}
across.r.watched = func(module string) []string { return []string{"main", "master"} }
across.r.assigned = func(node string) []string { return []string{"m", "f1-circuits", "checker"} }
across.r.watched = func(module string) []string {
if module == "checker" || module == "lidarr" { // no registration names them; lidarr is on main's revision all the same (H-A-144)
return nil
}
return []string{"main", "master"}
}
across.r.assigned = func(node string) []string { return []string{"m", "f1-circuits", "checker", "lidarr"} }
if out := across.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeFailed ||
!strings.Contains(out.Said, "g14 is assigned checker, which no watched branch lists (H-A-143)") {
!strings.Contains(out.Said, "g14 is assigned checker, which no watched branch lists (H-A-143)") ||
!strings.Contains(out.Said, "g14 is assigned lidarr, which no watched branch lists (H-A-143)") {
t.Errorf("the step across the watched branches came to %+v", out)
}
if c := across.requests["ace"].Cases[0]; string(c.Manifests["f1-circuits"].Raw) != `{"module":"f1-circuits"}` || len(c.Manifests) != 5 {
if c := across.requests["ace"].Cases[0]; string(c.Manifests["f1-circuits"].Raw) != `{"module":"f1-circuits"}` || len(c.Manifests) != 4 ||
c.Manifests["lidarr"].Raw != nil {
t.Errorf("the case across the watched branches holds %v", slices.Sorted(maps.Keys(c.Manifests)))
}
@@ -471,7 +478,13 @@ func TestAMachineIsJudgedByTheModulesItBlames(t *testing.T) {
{"could not run", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"}, "", "ace: gone", nil, nil},
// H-A-143: a module assigned there that no watched branch lists is said in the reason, or as a warning where it composes.
{"an unlisted module in the reason", "b", runOf(`{"composes":false,"reason":"nothing provides \"photos\"","blamed":[]}`),
"ace does not compose and blames no module: ace is assigned photos, which no watched branch lists (H-A-143); nothing provides \"photos\"", "", nil, []string{"photos"}},
"ace does not compose and blames no module: nothing provides \"photos\"; ace is assigned photos, which no watched branch lists (H-A-143)", "", nil, []string{"photos"}},
{"does not compose, blames a module, an unlisted module", "a", runOf(`{"composes":false,"reason":"nothing provides \"photos\"","blamed":[{"module":"a","problem":"nothing provides \"photos\""}]}`),
"ace holds a: nothing provides \"photos\"; ace is assigned photos, which no watched branch lists (H-A-143)", "", nil, []string{"photos"}},
{"another module blamed, an unlisted module", "b", runOf(`{"composes":false,"blamed":[{"module":"a","problem":"x"}]}`), "", "",
[]string{"ace holds a: x", "ace is assigned photos, which no watched branch lists (H-A-143)"}, []string{"photos"}},
{"could not run, an unlisted module", "a", meshwants.CompositionRun{Machine: "ace", Ended: &at, Outcome: meshwants.CompositionRunOutcomeCouldNotRun, Said: "ace: gone"},
"", "ace: gone; ace is assigned photos, which no watched branch lists (H-A-143)", nil, []string{"photos"}},
{"an unlisted module where it composes", "b", runOf(`{"composes":true,"blamed":[]}`), "", "",
[]string{"ace is assigned photos, which no watched branch lists (H-A-143)"}, []string{"photos"}},
} {
@@ -605,7 +618,8 @@ func TestACompositionTakesEachModuleAcrossTheWatchedBranches(t *testing.T) {
return meshcatalog.CatalogEntry{Module: module, Fp: fp, Manifest: map[string]any{"module": module}}
}
half := func(branch string, revision int64, movers []string, entries ...meshcatalog.CatalogEntry) mcc.Half {
h := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: branch, Revision: revision}, Entries: map[string]meshcatalog.CatalogEntry{}}
h := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: branch, Revision: revision, Definitions: []meshcatalog.CatalogRevisionDefinitionsItem{{Seat: "s1", Digest: branch}}},
Entries: map[string]meshcatalog.CatalogEntry{}}
for _, m := range movers {
h.Revision.Movers = append(h.Revision.Movers, meshcatalog.TakeInEntry{Module: m})
}
@@ -620,12 +634,8 @@ func TestACompositionTakesEachModuleAcrossTheWatchedBranches(t *testing.T) {
"nox-mesh": half("nox-mesh", 3, nil, entry("link2pay", "l1"), entry("photos", "p1"), entry("both", "nox")),
}
registrations := map[string][]string{"both": {"nox-mesh", "main"}, "f1-circuits": {"master"}, "link2pay": {"nox-mesh"}, "photos": {"nox-mesh"}}
watched := func(module string) []string {
if b, ok := registrations[module]; ok {
return b
}
return []string{"main", "master", "nox-mesh"}
}
registrations["engine"], registrations["a"] = []string{"main"}, []string{"main"}
watched := func(module string) []string { return registrations[module] } // a module no registration names has none (H-A-144)
for _, tc := range []struct {
name string
step meshwants.StepRun
@@ -644,13 +654,11 @@ func TestACompositionTakesEachModuleAcrossTheWatchedBranches(t *testing.T) {
map[string]string{"engine": "e1", "a": "a1", "both": "main", "f1-circuits": "f0"}},
{"no view held yet: the candidate alone", meshwants.StepRun{Branch: "main", Module: "a", Revision: 5},
half("main", 5, nil, entry("a", "a2")), nil, map[string]string{"a": "a2"}},
{"a module no registration names is not composed", meshwants.StepRun{Branch: "main", Module: "a", Revision: 5},
half("main", 5, nil, entry("a", "a2"), entry("checker", "c1")), nil, map[string]string{"a": "a2"}},
} {
t.Run(tc.name, func(t *testing.T) {
w := watched
if tc.newest == nil {
w = func(string) []string { return nil }
}
got := acrossBranches(tc.step, tc.candidate, tc.newest, w)
got := acrossBranches(tc.step, tc.candidate, tc.newest, watched)
fps := map[string]string{}
for name, e := range got.Entries {
fps[name] = e.Fp
@@ -658,8 +666,9 @@ func TestACompositionTakesEachModuleAcrossTheWatchedBranches(t *testing.T) {
if !maps.Equal(fps, tc.want) {
t.Errorf("composed from %v, want %v", fps, tc.want)
}
if got.Revision.Revision != tc.candidate.Revision.Revision {
t.Errorf("the half keeps revision %d, want the candidate's %d", got.Revision.Revision, tc.candidate.Revision.Revision)
if got.Revision.Revision != tc.candidate.Revision.Revision || len(got.Revision.Definitions) != 1 || got.Revision.Definitions[0].Digest != tc.step.Branch {
t.Errorf("the half keeps revision %d with definitions %v, want the candidate's %d with its own", got.Revision.Revision, got.Revision.Definitions,
tc.candidate.Revision.Revision)
}
})
}
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"slices"
"strings"
"sync"
"time"
@@ -13,6 +14,7 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/views"
)
@@ -193,8 +195,9 @@ func (h *halves) views() map[string]mcc.Half {
}
// watchedOf is module's watched branches in its registration's order (the branch `register` named first, then each branch in the
// order `watch` added it), as the follower's registrations hold it; before its registration is held, the branches followed, in
// the order they came, the gate's source's before the first registrations (design 47 G §532, H-A-143).
// order `watch` added it). Once registrations are held, a module none names has none: it is unlisted (H-A-144). Only before the
// first registrations are held do the gate's source's branches stand in (the branches followed then), in the order the source
// gives them, by their names escaped as its keys are (design 47 G §532, H-A-143, H-A-144).
func (h *halves) watchedOf(module string) []string {
h.mu.Lock()
b := h.branches
@@ -202,10 +205,13 @@ func (h *halves) watchedOf(module string) []string {
if b == nil {
return nil
}
if b.Registrations != nil {
if reg, ok := b.Registrations.Registration(module); ok && len(reg.Branches) > 0 {
if b.Registrations != nil && len(b.Registrations.All()) > 0 {
if reg, ok := b.Registrations.Registration(module); ok {
return slices.Clone(reg.Branches)
}
return nil
}
return b.Followed()
out := b.Followed()
slices.SortStableFunc(out, func(x, y string) int { return strings.Compare(keys.EscapeName(x), keys.EscapeName(y)) })
return out
}
@@ -3,6 +3,8 @@ package main
import (
"context"
"encoding/json"
"errors"
"slices"
"testing"
"time"
@@ -48,3 +50,45 @@ func TestAMeshThatNamesNoBranchSettlesTheAssignersFirstPass(t *testing.T) {
}
}
}
// Design 47 H-A-143, H-A-144, G §532: a module's watched branches are its registration's, in its order; once registrations are held a
// module none names has none; before the first registrations the gate's source's branches stand in, in the source's order.
func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
for _, tc := range []struct {
name string
regs []seat.Registration
module string
want []string
}{
{"its registration's order", []seat.Registration{{Module: "link2pay", Branches: []string{"nox-mesh", "main"}}}, "link2pay", []string{"nox-mesh", "main"}},
{"no registration names it", []seat.Registration{{Module: "link2pay", Branches: []string{"nox-mesh", "main"}}}, "checker", nil},
{"before the first registrations, the source's", []seat.Registration{}, "checker", []string{"main", "master"}},
} {
t.Run(tc.name, func(t *testing.T) {
call := func(key string, _ any) (json.RawMessage, error) {
switch key {
case mcc.RegistrationsVerb:
return json.Marshal(seat.RegistrationsAnswer{Registrations: tc.regs})
case mcc.SourceVerb:
return json.Marshal(map[string][]string{"branches": {"master", "main"}})
}
return nil, errors.New("not answered here")
}
reader := &views.ProcessReader{Module: "mesh-delivery-assigner", Call: call, Logf: t.Logf}
h := &halves{w: newWorld(), call: call, reader: reader, wake: func() {}, logf: t.Logf, ctx: ctx}
if err := h.follow(); err != nil {
t.Fatal(err)
}
for _, f := range reader.Followers()[:2] { // the registrations and the gate's source
if err := f.Start(ctx); err != nil {
t.Fatal(err)
}
}
if got := h.watchedOf(tc.module); !slices.Equal(got, tc.want) {
t.Errorf("the watched branches of %s are %v, want %v", tc.module, got, tc.want)
}
})
}
}