Resolution: an optional consumer of an unanswered requirement is left absent and listed (A-452, ADR 0330 §3, §7)
Builds: design 47 G A-452
This commit is contained in:
@@ -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,
|
resolution := mcat.Resolution{Node: node.Name, At: node.At, PublicDomain: node.PublicDomain,
|
||||||
Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount,
|
Account: node.Account, AccountHome: node.AccountHome, AgentAccount: node.AgentAccount,
|
||||||
AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities,
|
AgentAccountHome: node.AgentAccountHome, Capabilities: node.Capabilities,
|
||||||
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept,
|
Because: because, Needs: needs, Unhostable: unhostable, Kept: kept}
|
||||||
Absent: absentOf(absent, order, catalogue)}
|
|
||||||
for _, n := range providersFirst(order, catalogue) {
|
for _, n := range providersFirst(order, catalogue) {
|
||||||
resolution.Modules = append(resolution.Modules, catalogue[n])
|
resolution.Modules = append(resolution.Modules, catalogue[n])
|
||||||
}
|
}
|
||||||
|
|
||||||
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
||||||
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
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, unheld...)
|
||||||
problems = append(problems, checkResources(resolution.Modules)...)
|
problems = append(problems, checkResources(resolution.Modules)...)
|
||||||
resolution.Claims = claims
|
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
|
// 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
|
// 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.
|
// 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
|
var problems []string
|
||||||
for _, want := range unanswered {
|
for _, want := range unanswered {
|
||||||
found := false
|
found := false
|
||||||
@@ -725,7 +726,8 @@ func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[s
|
|||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
if m.IsOptional(want) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
if held == nil {
|
if held == nil {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ func TestARequirementWithOneAnswerIsTakenSilently(t *testing.T) {
|
|||||||
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode(t *testing.T) {
|
||||||
optional := mod("viewer", nil, []string{"codec"}, nil)
|
optional := mod("viewer", nil, []string{"codec"}, nil)
|
||||||
optional.OptionalRequires = map[string]bool{"codec": true}
|
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}}}
|
meshDB := mcat.Manifest{Module: "postgres", Provides: []mcat.Offer{{Name: "postgres-database", Scope: mcat.ScopeMesh}}}
|
||||||
for _, c := range []struct {
|
for _, c := range []struct {
|
||||||
name string
|
name string
|
||||||
@@ -78,8 +79,8 @@ func TestARequirementNoOneAnswersHoldsItsConsumersAndSeveralAnswersRefuseTheNode
|
|||||||
{name: "in the whole mesh", assigned: []string{"baserow", "editor"},
|
{name: "in the whole mesh", assigned: []string{"baserow", "editor"},
|
||||||
shelf: shelf(meshDB, mod("baserow", nil, []string{"postgres-database"}, nil), mod("editor", nil, nil, nil)),
|
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`}},
|
held: map[string]string{"baserow": `nothing in this mesh provides "postgres-database", wanted by baserow`}},
|
||||||
{name: "wanted only optionally", assigned: []string{"viewer", "editor"},
|
{name: "wanted hard by one and optionally by another", assigned: []string{"player", "viewer"},
|
||||||
shelf: shelf(optional, mod("editor", nil, nil, nil)), absent: true},
|
shelf: shelf(hard, optional), held: map[string]string{"player": `nothing provides "codec"`}, absent: true},
|
||||||
{name: "every module held", assigned: []string{"ca-trust"},
|
{name: "every module held", assigned: []string{"ca-trust"},
|
||||||
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
|
shelf: shelf(mod("ca-trust", nil, []string{"internal-acme-ca"}, nil)),
|
||||||
refused: []string{"nothing provides", "every one is held"}},
|
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)
|
t.Errorf("%s is held with %q, want %q", m, held[m], w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.absent && (len(held) != 0 || len(got.Absent) == 0) {
|
if _, heldToo := held["viewer"]; c.absent && (heldToo || len(got.Absent) != 1 || got.Absent[0] != (mcat.Absent{Consumer: "viewer", Requirement: "codec"})) {
|
||||||
t.Errorf("an optional requirement was held or not left absent: held %v absent %v", held, got.Absent)
|
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) {
|
if len(got.Modules) != len(c.assigned) {
|
||||||
t.Errorf("the node does not keep every module of its set: %v", names(got))
|
t.Errorf("the node does not keep every module of its set: %v", names(got))
|
||||||
|
|||||||
Reference in New Issue
Block a user