diff --git a/go/compose/composed.go b/go/compose/composed.go index 5c60334..599e890 100644 --- a/go/compose/composed.go +++ b/go/compose/composed.go @@ -318,10 +318,15 @@ func Stub(m catalogue.Manifest) catalogue.Manifest { m.OwnsPaths = catalogue.DeclaredPaths(m) } m.Build = nil - // Nor is anything of its own handed or collected: the templates and items its build kept fill resources and items a - // stub does not have (issue 1126: novox's node refused "postgres: its build kept a template for consumers, which it - // does not declare" with postgres held). - m.Handed, m.Items = nil, nil + // Nor is a template its build kept for its own files handed: a stub carries none of them (issue 1126: novox's node + // refused "postgres: its build kept a template for consumers, which it does not declare" with postgres held). Its + // items stay, and the templates they render through: a held module's contributions to other modules' collections + // (seat contributions, shell blocks, seat data) still reach their collectors. + if m.Handed != nil { + h := *m.Handed + h.Templates = nil + m.Handed = &h + } var dirs []map[string]any for _, r := range m.Resources { if r["type"] == "directory" { diff --git a/go/compose/frombus/answer_rows_test.go b/go/compose/frombus/answer_rows_test.go index b72850a..a870cd9 100644 --- a/go/compose/frombus/answer_rows_test.go +++ b/go/compose/frombus/answer_rows_test.go @@ -294,13 +294,30 @@ func answerNamesEveryRefusalAndLeavesAnOldBuildToTheNode(t *testing.T) { if got, want := catalogue.DeclaredPaths(compose.Carried(f1, "f1-circuits", &f1runs)), catalogue.DeclaredPaths(f1); !reflect.DeepEqual(got, want) { t.Errorf("f1-circuits carried owns %v, want what the controller composes from its manifest, %v", got, want) } - // Issue 1126: a held module hands and collects nothing of its own, so a template its build kept for a file it no - // longer carries refuses nothing (novox's node: "postgres: its build kept a template for consumers"). - kept := f1 - kept.Handed = &catalogue.Handed{Templates: map[string]string{"consumers": "files/consumers.json"}} - kept.Items = []catalogue.Item{{Collection: "routes", Content: "x"}} - if st := compose.Stub(kept); st.Handed != nil || st.Items != nil { - t.Errorf("a stub hands %+v and collects %+v", st.Handed, st.Items) + // Issue 1126: a held module hands no template its build kept for a file it no longer carries (novox's node: + // "postgres: its build kept a template for consumers"), but keeps its items and their templates, so what it + // contributes to other modules' collections still reaches them. + for _, row := range []struct { + name string + handed *catalogue.Handed + items []catalogue.Item + }{ + {"templates and items", &catalogue.Handed{Templates: map[string]string{"consumers": "files/consumers.json"}, + Items: map[string]string{"routes": "files/routes.tmpl"}}, []catalogue.Item{{Collection: "routes", Content: "x"}}}, + {"items alone", nil, []catalogue.Item{{Collection: "routes", Content: "x"}}}, + } { + kept := f1 + kept.Handed, kept.Items = row.handed, row.items + st := compose.Stub(kept) + if st.Handed != nil && st.Handed.Templates != nil { + t.Errorf("%s: a stub hands templates %v", row.name, st.Handed.Templates) + } + if !reflect.DeepEqual(st.Items, row.items) { + t.Errorf("%s: a stub collects %+v, want its items %+v", row.name, st.Items, row.items) + } + if row.handed != nil && (st.Handed == nil || !reflect.DeepEqual(st.Handed.Items, row.handed.Items) || row.handed.Templates == nil) { + t.Errorf("%s: a stub hands item templates %+v, want %v and its manifest untouched", row.name, st.Handed, row.handed.Items) + } } var k1, k2 any _ = json.Unmarshal(keptComposed, &k1)