Compose a module that has no resource of its own as an empty composition (issue 1945)

Its want names a composition (ADR 0539 clauses 1 and 6), so a module whose needs others meet must still have one at
its fingerprint, or no want could ever be written for it. Found by the served test.
This commit is contained in:
2026-10-24 19:25:14 +02:00
parent dd58fbcb2c
commit e05481e992
4 changed files with 46 additions and 5 deletions
+27 -2
View File
@@ -218,7 +218,7 @@ func TestTheCompositionsOfANodeAreItsDeclaration(t *testing.T) {
Resources []json.RawMessage `json:"resources"`
}
_ = json.Unmarshal(body, &d)
comps, moved, err := compositionsOf(node, body, fps, nil)
comps, moved, err := compositionsOf(node, body, fps, nil, nil)
if err != nil {
t.Fatalf("%s: %v", node, err)
}
@@ -253,7 +253,7 @@ func TestTheCompositionsOfANodeAreItsDeclaration(t *testing.T) {
// unchanged it writes nothing; a changed input writes a new revision of that key alone, by compare-and-set.
func TestACompositionIsWrittenOnceAndAgainOnlyWhenItChanges(t *testing.T) {
body, fps := capturedBody(t, "g14")
comps, _, err := compositionsOf("g14", body, fps, nil)
comps, _, err := compositionsOf("g14", body, fps, nil, nil)
if err != nil {
t.Fatal(err)
}
@@ -335,3 +335,28 @@ func TestCompositionsOutsideTheFiveNewestAreDeleted(t *testing.T) {
}
}
}
// 1945 (found by the served test): a module the node runs that composes no resource of its own still has its
// composition, empty, at its fingerprint, so a want can name it; a module the node runs with no fingerprint of the new
// form gets none.
func TestAModuleWithNoResourceOfItsOwnStillHasItsComposition(t *testing.T) {
body := []byte(`{"declaration":1,"resources":[]}`)
fp := sdkdelivery.SourcePrefix2 + strings.Repeat("b", 64)
comps, _, err := compositionsOf("laptop", body, map[string]string{"board": fp}, nil, []string{"board", "legacy"})
if err != nil {
t.Fatal(err)
}
key, _ := sdkdelivery.ComposedKey("laptop", "board", fp)
c, ok := comps[key]
if !ok || len(c.Resources) != 0 {
t.Fatalf("the board's composition: %+v (%v)", c, ok)
}
if _, err := sdkdelivery.EncodeComposed(c); err != nil {
t.Errorf("an empty composition does not encode: %v", err)
}
for k := range comps {
if strings.Contains(k, "legacy") {
t.Errorf("a module with no fingerprint of the new form was composed: %s", k)
}
}
}