From 310ff0cabcbbf4a13472746e3681fb215ee0c4c5 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 00:18:25 +0100 Subject: [PATCH 1/3] Resolution: an unanswered requirement holds its consumers, not the node (A-452) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- internal/compose/credentials_test.go | 4 +- internal/compose/frombus/held_rows_test.go | 12 +++-- internal/compose/one_machine_alone_test.go | 10 ++-- internal/compose/resolution/resolve.go | 47 ++++++++++++++++- .../resolution/unanswered_requirement_test.go | 51 +++++++++++++++++++ internal/compose/resolve_test.go | 4 +- 6 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 internal/compose/resolution/unanswered_requirement_test.go diff --git a/internal/compose/credentials_test.go b/internal/compose/credentials_test.go index 1ba5920f..96de579f 100644 --- a/internal/compose/credentials_test.go +++ b/internal/compose/credentials_test.go @@ -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) } diff --git a/internal/compose/frombus/held_rows_test.go b/internal/compose/frombus/held_rows_test.go index 0ac83e0c..05588031 100644 --- a/internal/compose/frombus/held_rows_test.go +++ b/internal/compose/frombus/held_rows_test.go @@ -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) } diff --git a/internal/compose/one_machine_alone_test.go b/internal/compose/one_machine_alone_test.go index 2c8fef9e..1ad5f631 100644 --- a/internal/compose/one_machine_alone_test.go +++ b/internal/compose/one_machine_alone_test.go @@ -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) } } diff --git a/internal/compose/resolution/resolve.go b/internal/compose/resolution/resolve.go index 89b6ffbb..ba6ce3ed 100644 --- a/internal/compose/resolution/resolve.go +++ b/internal/compose/resolution/resolve.go @@ -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) { diff --git a/internal/compose/resolution/unanswered_requirement_test.go b/internal/compose/resolution/unanswered_requirement_test.go new file mode 100644 index 00000000..42c853a0 --- /dev/null +++ b/internal/compose/resolution/unanswered_requirement_test.go @@ -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) + } +} diff --git a/internal/compose/resolve_test.go b/internal/compose/resolve_test.go index 09369def..a78dd83f 100644 --- a/internal/compose/resolve_test.go +++ b/internal/compose/resolve_test.go @@ -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) { -- 2.54.0 From c6d893e14119f719d29f70e7f7a314c803a4ec2f Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 00:25:30 +0100 Subject: [PATCH 2/3] Resolution: a requirement nothing in the mesh answers holds its consumers too; optional ones stay absent (A-452) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/compose/frombus/answer_rows_test.go | 4 +- internal/compose/resolution/resolve.go | 46 ++++++--- internal/compose/resolution/resolve_test.go | 93 ++++++++++++++----- .../resolution/unanswered_requirement_test.go | 51 ---------- internal/compose/resolve.go | 27 ++++-- 5 files changed, 124 insertions(+), 97 deletions(-) delete mode 100644 internal/compose/resolution/unanswered_requirement_test.go diff --git a/internal/compose/frombus/answer_rows_test.go b/internal/compose/frombus/answer_rows_test.go index de6fd3e6..5ea57583 100644 --- a/internal/compose/frombus/answer_rows_test.go +++ b/internal/compose/frombus/answer_rows_test.go @@ -675,7 +675,9 @@ func otherNodeNotResolvedIsNamed(t *testing.T) { given[n] = &p } a := Answer(ctx, b, Mesh{}, Scope{Node: "n1", Assignments: given}, map[string]string{"cons": "src2:" + strings.Repeat("1", 64)}, nil, "p-h1", 1) - if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || !strings.Contains(a.Refused, "prov on n2 lacks container-runtime") { + // cons is held for the requirement nothing answers (A-452) and its why names n2's provider. + if a.Verdict != nodeengine.CandidateAnswerVerdictRefused || len(a.Refusals) != 1 || a.Refusals[0].Module != "cons" || + !strings.Contains(a.Refusals[0].Why, "prov on n2 lacks container-runtime") { t.Errorf("a refusal for want of n2's provider = %+v", a) } } diff --git a/internal/compose/resolution/resolve.go b/internal/compose/resolution/resolve.go index ba6ce3ed..d1c48eb5 100644 --- a/internal/compose/resolution/resolve.go +++ b/internal/compose/resolution/resolve.go @@ -151,9 +151,6 @@ 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 @@ -184,6 +181,22 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No absent[want] = true reported[want] = true } + // 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. + // The value is the remedy the mesh-wide refusal adds, empty for a requirement nothing on the node answers. + unanswered := map[string]string{} + var unansweredOrder []string + holdWhenUnanswered := func(want, remedy string) { + if !wantedHard(want) && wantedOptionally(want) { + // Only optional consumers: left absent, never held (ADR 0330 §3). + leaveAbsent(want) + return + } + if _, ok := unanswered[want]; !ok { + unansweredOrder = append(unansweredOrder, want) + } + unanswered[want] = remedy + } for { if len(queue) == 0 { @@ -376,9 +389,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No } else if len(answers) > 1 { remedy = "— assign one of these to a node: " + strings.Join(answers, ", ") } - problems = append(problems, fmt.Sprintf( - "nothing in this mesh provides %q, wanted by %s %s", - want, because[want], remedy)) + // Not answered on the node nor in the rest of the mesh: costs its consumers only (A-452). + holdWhenUnanswered(want, remedy) case len(where) == 1: if c, pinned := world.Pinned[want]; pinned && !chosenMatches(c, where[0]) { // One provider, and it is not the one this machine was told to use. Silently @@ -486,7 +498,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No continue } reported[want] = true - unanswered = append(unanswered, want) + holdWhenUnanswered(want, "") continue case 1: // No choice to make, so none is made. This is the case that lets `install i3` bring @@ -601,7 +613,7 @@ 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) + held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held) problems = append(problems, unheld...) problems = append(problems, checkResources(resolution.Modules)...) resolution.Claims = claims @@ -684,11 +696,19 @@ func checkCapabilities(modules []mcat.Manifest, node mcat.Node) []string { return problems } +// unansweredWords is why a consumer is held for a requirement nothing answers, naming the provision. +func unansweredWords(want, consumer, remedy string) string { + if remedy == "" { + return fmt.Sprintf("nothing provides %q, wanted by %s", want, consumer) + } + return fmt.Sprintf("nothing in this mesh provides %q, wanted by %s %s", want, consumer, remedy) +} + // 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) { +func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[string]string, because map[string]string, held map[string]string) (map[string]string, []string) { var problems []string for _, want := range unanswered { found := false @@ -704,17 +724,21 @@ func holdUnanswered(modules []mcat.Manifest, unanswered []string, because map[st continue } found = true + if m.IsOptional(want) { + // Optional for this module: not held (ADR 0330 §3). + continue + } if held == nil { held = map[string]string{} } - why := fmt.Sprintf("nothing provides %q, wanted by %s", want, m.Module) + why := unansweredWords(want, m.Module, remedies[want]) 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])) + problems = append(problems, unansweredWords(want, because[want], remedies[want])) } } if len(unanswered) > 0 && len(held) >= len(modules) { diff --git a/internal/compose/resolution/resolve_test.go b/internal/compose/resolution/resolve_test.go index 7eb06e43..f40e6a02 100644 --- a/internal/compose/resolution/resolve_test.go +++ b/internal/compose/resolution/resolve_test.go @@ -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)) + } + }) } } diff --git a/internal/compose/resolution/unanswered_requirement_test.go b/internal/compose/resolution/unanswered_requirement_test.go deleted file mode 100644 index 42c853a0..00000000 --- a/internal/compose/resolution/unanswered_requirement_test.go +++ /dev/null @@ -1,51 +0,0 @@ -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) - } -} diff --git a/internal/compose/resolve.go b/internal/compose/resolve.go index fcd2fc98..44982e3b 100644 --- a/internal/compose/resolve.go +++ b/internal/compose/resolve.go @@ -291,22 +291,31 @@ func (c *composer) resolutionHolding(nodeName string) (catalogue.Resolution, map At: onNetwork[nodeName], PublicDomain: node.PublicDomain, Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome}, world) - if err != nil { - // What another node's set would have offered is missing when that set does not resolve here: said with the - // refusal, so "nothing provides" is read beside why (issue 1126, probe #532). + // What another node's set would have offered is missing when that set does not resolve here: said with the refusal, and with + // each module held for a requirement nothing answers, so "nothing provides" is read beside why (issue 1126, probe #532). + why := func() string { + var out string if len(left) > 0 { - var why []string + var parts []string for _, l := range left { - why = append(why, l.String()) + parts = append(parts, l.String()) } - err = fmt.Errorf("%w\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", err, len(left), strings.Join(why, "; ")) + out += fmt.Sprintf("\n\nand %d node(s) offer nothing here, as they could not be resolved: %s", len(left), strings.Join(parts, "; ")) } if len(c.unhostable) > 0 { - err = fmt.Errorf("%w\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s", - err, strings.Join(c.unhostable, "; ")) + out += fmt.Sprintf("\n\nand these modules offer nothing here, as their node cannot run them in this composition: %s", + strings.Join(c.unhostable, "; ")) } + return out + } + if err != nil { // The node's own set does not compose: the only failure a mesh-wide gatherer may pass over. - return catalogue.Resolution{}, nil, notResolvable{err} + return catalogue.Resolution{}, nil, notResolvable{fmt.Errorf("%w%s", err, why())} + } + for m, w := range held { + if strings.Contains(w, "nothing provides") || strings.Contains(w, "nothing in this mesh provides") { + held[m] = w + why() + } } return resolved, held, nil } -- 2.54.0 From 3bb895152f1c705ec97caefb75f92c2f1a66afb2 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 00:27:47 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Resolution:=20an=20optional=20consumer=20of?= =?UTF-8?q?=20an=20unanswered=20requirement=20is=20left=20absent=20and=20l?= =?UTF-8?q?isted=20(A-452,=20ADR=200330=20=C2=A73,=20=C2=A77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G A-452 --- internal/compose/resolution/resolve.go | 12 +++++++----- internal/compose/resolution/resolve_test.go | 9 +++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/compose/resolution/resolve.go b/internal/compose/resolution/resolve.go index d1c48eb5..34b8fe93 100644 --- a/internal/compose/resolution/resolve.go +++ b/internal/compose/resolution/resolve.go @@ -605,15 +605,16 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No resolution := mcat.Resolution{Node: node.Name, At: node.At, PublicDomain: node.PublicDomain, Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities, - Because: because, Needs: needs, Unhostable: unhostable, Kept: kept, - Absent: absentOf(absent, order, catalogue)} + Because: because, Needs: needs, Unhostable: unhostable, Kept: kept} for _, n := range providersFirst(order, catalogue) { resolution.Modules = append(resolution.Modules, catalogue[n]) } problems = append(problems, checkCapabilities(resolution.Modules, node)...) claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings) - held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held) + held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held, absent) + // Listed after the holding: an optional consumer of a requirement nothing answers is left absent there (ADR 0330 §3, §7). + resolution.Absent = absentOf(absent, order, catalogue) problems = append(problems, unheld...) problems = append(problems, checkResources(resolution.Modules)...) resolution.Claims = claims @@ -708,7 +709,7 @@ func unansweredWords(want, consumer, remedy string) string { // 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, remedies map[string]string, because map[string]string, held map[string]string) (map[string]string, []string) { +func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[string]string, because map[string]string, held map[string]string, absent map[string]bool) (map[string]string, []string) { var problems []string for _, want := range unanswered { found := false @@ -725,7 +726,8 @@ func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[s } found = true if m.IsOptional(want) { - // Optional for this module: not held (ADR 0330 §3). + // Optional for this module: not held, left absent and listed (ADR 0330 §3, §7). + absent[want] = true continue } if held == nil { diff --git a/internal/compose/resolution/resolve_test.go b/internal/compose/resolution/resolve_test.go index f40e6a02..757292cf 100644 --- a/internal/compose/resolution/resolve_test.go +++ b/internal/compose/resolution/resolve_test.go @@ -61,6 +61,7 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) { func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) { optional := mod("viewer", nil, []string{"codec"}, nil) optional.OptionalRequires = map[string]bool{"codec": true} + hard := mod("player", nil, []string{"codec"}, nil) meshDB := mcat.Manifest{Module: "postgres", Provides: []mcat.Offer{{Name: "postgres-database", Scope: mcat.ScopeMesh}}} for _, c := range []struct { name string @@ -78,8 +79,8 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode {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: "wanted hard by one and optionally by another", assigned: []string{"player", "viewer"}, + shelf: shelf(hard, optional), held: map[string]string{"player": `nothing provides "codec"`}, 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"}}, @@ -114,8 +115,8 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode 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 _, heldToo := held["viewer"]; c.absent && (heldToo || len(got.Absent) != 1 || got.Absent[0] != (mcat.Absent{Consumer: "viewer", Requirement: "codec"})) { + t.Errorf("the optional consumer was held or not listed 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)) -- 2.54.0