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:
2026-11-17 00:18:25 +01:00
parent 13fcfae051
commit 310ff0cabc
6 changed files with 117 additions and 11 deletions
+3 -1
View File
@@ -201,7 +201,9 @@ func TestAGrantIsCreatedForEachCredentialMadeForAConsumer(t *testing.T) {
}
// A consumer whose set does not resolve is skipped, not fatal.
nodeOf(t, &in, "laptop").Assigned = append(nodeOf(t, &in, "laptop").Assigned, "files")
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "nothing-gives-this"}}
in.Catalogue["files"] = catalogue.Manifest{Module: "files", Version: "1", Requires: []string{"s3-bucket", "two-give-this"}}
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
if got, err := Render(in, "anchor", Foreseeing); err != nil || len(got.Rendering.Grants) != 0 {
t.Errorf("a consumer that does not resolve: %v %+v", err, got.Rendering.Grants)
}
+9 -3
View File
@@ -39,11 +39,17 @@ func aNode(t *testing.T, manifests ...string) (*bus, map[string]string) {
// refusal can be of the held module's stub (node-tools held, then "its build produced 0 bundle(s)", its own why unsaid).
func aNodeRefusedWholeSaysWhatItHeld(t *testing.T) {
refused := `{"module":"power","version":"1","items":[{"collection":"contribution:node-bar:block","attributes":{"shows":"state"},"template":"files/a"}]}`
needs := `{"module":"lamp","version":"1","requires":["nothing-provides-this"]}`
b, fps := aNode(t, refused, needs)
needs := `{"module":"lamp","version":"1","requires":["two-provide-this"]}`
giverA := `{"module":"giver-a","version":"1","provides":[{"name":"two-provide-this"}]}`
giverB := `{"module":"giver-b","version":"1","provides":[{"name":"two-provide-this"}]}`
b, fps := aNode(t, refused, needs, giverA, giverB)
// The two givers are in the catalogue and placed on no node, so lamp's requirement has two answers and nobody chose.
placed := b.assignments["n1"]
placed.Modules = placed.Modules[:2]
b.assignments["n1"] = placed
refuse(b, "power", `"shows" is none of them`)
_, _, held, err := Compose(context.Background(), b, Mesh{}, Scope{Node: "n1"}, fps)
if err == nil || !strings.Contains(err.Error(), "nothing provides") || !strings.Contains(err.Error(), `held before: power: `) ||
if err == nil || !strings.Contains(err.Error(), "choose one") || !strings.Contains(err.Error(), `held before: power: `) ||
!strings.Contains(err.Error(), `"shows" is none of them`) {
t.Errorf("the node refused whole with %v (held %v), want lamp's refusal and power held before, with its why", err, held)
}
+6 -4
View File
@@ -11,12 +11,14 @@ import (
// fourOnTheNetwork is aMesh and two more machines on the private network at the site `there`: `ace`, dialled at
// ace.example:51820, at 10.77.0.3, and `box`, behind no endpoint, at 10.77.0.4. A module `office` requires
// `document-server`, which nothing in the catalogue provides: the shape of issue 1833 (nextcloud on the hub wanting a
// document server nobody offered).
// `document-server`, which two modules of the catalogue provide and nobody chose: a refusal of the node's own set, as
// issue 1833 was (nextcloud on the hub wanting a document server; an unanswered requirement now costs only its consumer, A-452).
func fourOnTheNetwork(t *testing.T) Input {
t.Helper()
in := aMesh(t)
in.Catalogue["office"] = catalogue.Manifest{Module: "office", Version: "1", Requires: []string{"document-server"}}
in.Catalogue["docs-a"] = catalogue.Manifest{Module: "docs-a", Version: "1", Provides: catalogue.Offers("document-server")}
in.Catalogue["docs-b"] = catalogue.Manifest{Module: "docs-b", Version: "1", Provides: catalogue.Offers("document-server")}
caps := map[string]bool{"container-runtime": true, "wireguard": true, "systemd": true}
in.Nodes = append(in.Nodes,
Node{Name: "ace", Place: Place{Key: keyOf(t, "ace"), Endpoint: "ace.example:51820", Site: "there", Address: "10.77.0.3"},
@@ -26,7 +28,7 @@ func fourOnTheNetwork(t *testing.T) Input {
return in
}
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement nothing provides.
// unresolvableBy makes one machine's own set fail to resolve: it is also given `office`, whose requirement two modules provide.
func unresolvableBy(t *testing.T, in *Input, name string) {
t.Helper()
n := nodeOf(t, in, name)
@@ -70,7 +72,7 @@ func TestOneMachineThatDoesNotResolveIsRefusedAlone(t *testing.T) {
if err == nil || !IsUnresolvable(err) {
t.Fatalf("the machine that does not resolve is not refused as its own set failing: %v", err)
}
if !strings.Contains(err.Error(), `nothing provides "document-server", wanted by office`) {
if !strings.Contains(err.Error(), `"document-server" is wanted by office and 2 modules provide it`) {
t.Errorf("the refusal does not name what could not be resolved: %v", err)
}
}
+45 -2
View File
@@ -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)
}
}
+3 -1
View File
@@ -295,7 +295,9 @@ func TestARecordAnsweredNeedGetsItsKeyAndTheManagerItsPublicKey(t *testing.T) {
// 1362/AC5: a node whose own set does not compose returns an error callers can tell from an unreadable Input.
func TestANodeWhoseOwnSetDoesNotComposeIsToldApartFromAnUnreadableInput(t *testing.T) {
in := aMesh(t)
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"nothing-gives-this"}}
in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Requires: []string{"two-give-this"}}
in.Catalogue["giver-a"] = catalogue.Manifest{Module: "giver-a", Version: "1", Provides: catalogue.Offers("two-give-this")}
in.Catalogue["giver-b"] = catalogue.Manifest{Module: "giver-b", Version: "1", Provides: catalogue.Offers("two-give-this")}
laptop := nodeOf(t, &in, "laptop")
laptop.Assigned = append(laptop.Assigned, "rival-one")
if _, err := Resolve(in, "laptop"); err == nil || !IsUnresolvable(err) {