From 3bb895152f1c705ec97caefb75f92c2f1a66afb2 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 00:27:47 +0100 Subject: [PATCH] =?UTF-8?q?Resolution:=20an=20optional=20consumer=20of=20a?= =?UTF-8?q?n=20unanswered=20requirement=20is=20left=20absent=20and=20liste?= =?UTF-8?q?d=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))