Resolution: an unanswered requirement holds its consumers, not the node (A-452)
A requirement nothing answers no longer refuses the whole composition: each module that wants it is held with the "nothing provides" words, as a refused claim's claimant is, and the node composes the rest. Held modules stay in the set, so what they provide still counts. The node is refused when every module is held or no module of the set wants the name. Tests that used an unanswered requirement to make a node's own set fail now use an ambiguous one. Builds: design 47 G A-452 (extends A-405, A-407; ADR 0636 §3)
This commit is contained in:
@@ -151,6 +151,9 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
// once, and saying the same thing twice makes a person hunt for the difference between two
|
||||
// identical lines before realising there is none.
|
||||
reported := map[string]bool{}
|
||||
// A requirement nothing answers costs the modules that want it, not the machine (A-452, ADR 0636 §3): said once per name,
|
||||
// each consumer is held after the walk, when the set is known.
|
||||
var unanswered []string
|
||||
|
||||
// **An optional requirement is settled last** (novox/hq ADR 0330). Whether a name is optional is
|
||||
// a question about every module that wants it, and a module pulled in later may want it hard; so
|
||||
@@ -483,8 +486,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
continue
|
||||
}
|
||||
reported[want] = true
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"nothing provides %q, wanted by %s", want, because[want]))
|
||||
unanswered = append(unanswered, want)
|
||||
continue
|
||||
case 1:
|
||||
// No choice to make, so none is made. This is the case that lets `install i3` bring
|
||||
@@ -599,6 +601,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
|
||||
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
||||
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
||||
held, unheld := holdUnanswered(resolution.Modules, unanswered, because, held)
|
||||
problems = append(problems, unheld...)
|
||||
problems = append(problems, checkResources(resolution.Modules)...)
|
||||
resolution.Claims = claims
|
||||
|
||||
@@ -680,6 +684,45 @@ func checkCapabilities(modules []mcat.Manifest, node mcat.Node) []string {
|
||||
return problems
|
||||
}
|
||||
|
||||
// holdUnanswered holds each module of the set that wants a requirement nothing answers, with the words "nothing provides" naming the
|
||||
// provision (A-452): it stays in the set, so what it provides still counts for the others. A requirement none of the set's modules
|
||||
// wants (an assigned name the catalogue does not know) has no consumer to hold and comes back as a problem of the node; so does a
|
||||
// set whose every module is held, since then nothing could be composed.
|
||||
func holdUnanswered(modules []mcat.Manifest, unanswered []string, because map[string]string, held map[string]string) (map[string]string, []string) {
|
||||
var problems []string
|
||||
for _, want := range unanswered {
|
||||
found := false
|
||||
for _, m := range modules {
|
||||
wants := false
|
||||
for _, w := range m.Wants() {
|
||||
if w == want {
|
||||
wants = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !wants {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
why := fmt.Sprintf("nothing provides %q, wanted by %s", want, m.Module)
|
||||
if prior, ok := held[m.Module]; ok {
|
||||
why = prior + "; " + why
|
||||
}
|
||||
held[m.Module] = why
|
||||
}
|
||||
if !found {
|
||||
problems = append(problems, fmt.Sprintf("nothing provides %q, wanted by %s", want, because[want]))
|
||||
}
|
||||
}
|
||||
if len(unanswered) > 0 && len(held) >= len(modules) {
|
||||
problems = append(problems, "no module of the node could be composed: every one is held")
|
||||
}
|
||||
return held, problems
|
||||
}
|
||||
|
||||
// holdClaims refuses two modules holding one singular thing, within this node's own set and against what is held elsewhere for
|
||||
// the wider scopes: the claims that hold, and for each module that cannot hold what it claims, why (every reason, joined).
|
||||
func holdClaims(modules []mcat.Manifest, node mcat.Node, elsewhere []mcat.Held, holdings []mcat.Held) ([]mcat.Held, map[string]string) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package resolution
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// A-452 (ace, 2026-11-16 23:11: ten unanswered requirements refused the whole composition): a requirement nothing answers holds
|
||||
// each module that wants it, with the "nothing provides" words naming the provision, and every other module of the node resolves;
|
||||
// a held module that provides still counts for the modules that want what it provides (A-405, A-407).
|
||||
func TestAnUnansweredRequirementHoldsItsConsumersAndTheNodeComposesTheRest(t *testing.T) {
|
||||
got, held, err := ResolveHolding(shelf(
|
||||
mod("ca-trust", nil, []string{"internal-acme-ca"}, nil),
|
||||
mod("baserow", []string{"spreadsheet"}, []string{"postgres-database", "route"}, nil),
|
||||
mod("sheet-viewer", nil, []string{"spreadsheet"}, nil),
|
||||
mod("editor", nil, nil, nil),
|
||||
), []string{"ca-trust", "baserow", "sheet-viewer", "editor"}, workstation(), mcat.World{})
|
||||
if err != nil {
|
||||
t.Fatalf("an unanswered requirement refused the whole node: %v", err)
|
||||
}
|
||||
for module, provision := range map[string]string{"ca-trust": "internal-acme-ca", "baserow": "postgres-database"} {
|
||||
if !strings.Contains(held[module], `nothing provides "`+provision+`"`) {
|
||||
t.Errorf("%s is not held for %q: %v", module, provision, held)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(held["baserow"], `nothing provides "route"`) || len(held) != 2 {
|
||||
t.Errorf("baserow is not held for each of its requirements, or another module is held: %v", held)
|
||||
}
|
||||
names := map[string]bool{}
|
||||
for _, m := range got.Modules {
|
||||
names[m.Module] = true
|
||||
}
|
||||
if !names["editor"] || !names["sheet-viewer"] || !names["baserow"] {
|
||||
t.Errorf("the node does not hold every module in its set: %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
// What nothing could be composed of, or no consumer could name, is still the machine's refusal.
|
||||
func TestAnUnansweredRequirementRefusesTheNodeWhenEveryModuleIsHeldOrNoneWantsIt(t *testing.T) {
|
||||
_, _, err := ResolveHolding(shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
|
||||
[]string{"ca-trust"}, workstation(), mcat.World{})
|
||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") {
|
||||
t.Errorf("a node with every module held was composed: %v", err)
|
||||
}
|
||||
_, _, err = ResolveHolding(shelf(mod("editor", nil, nil, nil)), []string{"ghost"}, workstation(), mcat.World{})
|
||||
if err == nil || !strings.Contains(err.Error(), "nothing provides") {
|
||||
t.Errorf("an assigned module nobody knows did not refuse the node: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user