Resolution: a requirement nothing in the mesh answers holds its consumers too; optional ones stay absent (A-452)

The mesh-wide refusal ("nothing in this mesh provides") holds its consumers as the
node-wide one does; a module that wants the name only optionally is left absent
(ADR 0330 §3), never held. A held why still names the nodes that offer nothing
here. The two tests of the first commit are folded as rows into one table test
that replaces two existing ones.

Builds: design 47 G A-452
This commit is contained in:
2026-11-17 00:25:30 +01:00
parent 310ff0cabc
commit c6d893e141
5 changed files with 124 additions and 97 deletions
+68 -25
View File
@@ -53,31 +53,74 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
}
}
func TestARequirementWithSeveralAnswersIsRefusedAndNamed(t *testing.T) {
// The mesh does not pick. A default would be a choice made for somebody who finds out later,
// and naming the candidates is the whole remedy.
_, err := Resolve(shelf(
mod("editor", nil, []string{"shell"}, nil),
mod("bash", []string{"shell"}, nil, nil),
mod("zsh", []string{"shell"}, nil, nil),
mod("fish", []string{"shell"}, nil, nil),
), []string{"editor"}, workstation(), mcat.World{})
if err == nil {
t.Fatal("a requirement with three answers was resolved without asking")
}
for _, want := range []string{"bash", "fish", "zsh", "choose one"} {
if !strings.Contains(err.Error(), want) {
t.Errorf("the refusal does not mention %q: %v", want, err)
}
}
}
func TestARequirementWithNoAnswerIsRefused(t *testing.T) {
_, err := Resolve(shelf(mod("i3", nil, []string{"xorg"}, nil)), []string{"i3"}, workstation(), mcat.World{})
if err == nil || !strings.Contains(err.Error(), "nothing provides") {
t.Fatalf("a requirement nothing satisfies gave %v", err)
// A requirement nothing answers costs the modules that want it, not the machine (A-452; ace, 2026-11-16 23:11: ten unanswered
// requirements refused the whole composition), whether nothing on the node or nothing in the whole mesh answers it; one that
// only optional consumers want is left absent (ADR 0330 §3); several answers are still the node's refusal, naming them (the
// mesh does not pick: a default would be a choice made for somebody who finds out later); and a node whose every module is held,
// or an assigned name nobody wants, is still refused.
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
optional := mod("viewer", nil, []string{"codec"}, nil)
optional.OptionalRequires = map[string]bool{"codec": true}
meshDB := mcat.Manifest{Module: "postgres", Provides: []mcat.Offer{{Name: "postgres-database", Scope: mcat.ScopeMesh}}}
for _, c := range []struct {
name string
shelf map[string]mcat.Manifest
assigned []string
held map[string]string // module -> words in its why
refused []string // words of the node's refusal
absent bool
}{
{name: "on the node", assigned: []string{"ca-trust", "baserow", "sheet-viewer", "editor"},
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil),
mod("baserow", []string{"spreadsheet"}, []string{"route"}, nil),
mod("sheet-viewer", nil, []string{"spreadsheet"}, nil), mod("editor", nil, nil, nil)),
held: map[string]string{"ca-trust": `nothing provides "internal-acme-ca"`, "baserow": `nothing provides "route"`}},
{name: "in the whole mesh", assigned: []string{"baserow", "editor"},
shelf: shelf(meshDB, mod("baserow", nil, []string{"postgres-database"}, nil), mod("editor", nil, nil, nil)),
held: map[string]string{"baserow": `nothing in this mesh provides "postgres-database", wanted by baserow`}},
{name: "wanted only optionally", assigned: []string{"viewer", "editor"},
shelf: shelf(optional, mod("editor", nil, nil, nil)), absent: true},
{name: "every module held", assigned: []string{"ca-trust"},
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
refused: []string{"nothing provides", "every one is held"}},
{name: "nobody wants it", assigned: []string{"ghost"}, shelf: shelf(mod("editor", nil, nil, nil)),
refused: []string{"nothing provides"}},
{name: "several answers", assigned: []string{"editor"},
shelf: shelf(mod("editor", nil, []string{"shell"}, nil), mod("bash", []string{"shell"}, nil, nil),
mod("zsh", []string{"shell"}, nil, nil), mod("fish", []string{"shell"}, nil, nil)),
refused: []string{"bash", "fish", "zsh", "choose one"}},
} {
t.Run(c.name, func(t *testing.T) {
got, held, err := ResolveHolding(c.shelf, c.assigned, workstation(), mcat.World{})
if c.refused != nil {
if err == nil {
t.Fatal("the node was composed, not refused")
}
for _, w := range c.refused {
if !strings.Contains(err.Error(), w) {
t.Errorf("the refusal does not mention %q: %v", w, err)
}
}
return
}
if err != nil {
t.Fatalf("the node was refused whole: %v", err)
}
if len(held) != len(c.held) {
t.Errorf("held %v, want modules %v", held, c.held)
}
for m, w := range c.held {
if !strings.Contains(held[m], w) {
t.Errorf("%s is held with %q, want %q", m, held[m], w)
}
}
if c.absent && (len(held) != 0 || len(got.Absent) == 0) {
t.Errorf("an optional requirement was held or not left absent: held %v absent %v", held, got.Absent)
}
if len(got.Modules) != len(c.assigned) {
t.Errorf("the node does not keep every module of its set: %v", names(got))
}
})
}
}