diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_graph.go b/modules/mesh-delivery-indexer/internal/index/catalog_graph.go index 93ff2d057..203b39ce3 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_graph.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_graph.go @@ -35,6 +35,11 @@ func CatalogEntryOf(module string, cur meshcatalog.ModulesByModuleValue, m catal Commit: cur.Commit, Manifest: manifestWhole(raw), ManifestDigest: meshcatalogclient.EntryManifestDigest(cur.Manifest), Verdict: cur.Verdict, Fp: n.FP, None: n.None, Bases: n.Bases, Packages: maps.Clone(cur.Packages), Provides: n.Provides, Requires: n.Requires, Awaits: n.Awaits, Invokes: n.Invokes, Serves: n.Serves, LeftOut: n.LeftOut, Main: MainOf(m), Contributes: contributesOf(m), Class: m.Class} + // needs are the reader capabilities the module's value names (design 47 H2, H-A-682 (1)): its manifest's words, forms + // and seat names and its templates' forms, sorted, absent when empty. + if len(cur.Needs) > 0 { + e.Needs = slices.Compact(slices.Sorted(slices.Values(cur.Needs))) + } // requires names every requirement as catalogue.Manifest.Wants lists them, optional ones and those only contributes names // included, since contributing to a requirement is requiring it (design 47 G §709, A-229). for _, r := range m.Wants() { @@ -66,11 +71,11 @@ func CatalogEntryOf(module string, cur meshcatalog.ModulesByModuleValue, m catal // ModuleValueOf is the module's value as the indexer computes with it, read back from its catalog graph entry: the // inverse of CatalogEntryOf, by which the indexer's view of the trunk is the newest trunk revision's entries (the lead's -// ruling on milestone 47/G finding 1; ADR 0656 §6: one form of the fact). The old line's fields (the old-form -// fingerprint, the reader needs) are not kept. +// ruling on milestone 47/G finding 1; ADR 0656 §6: one form of the fact), the reader needs included (H-A-682 (1)). The old +// line's old-form fingerprint is not kept. func ModuleValueOf(e meshcatalog.CatalogEntry) meshcatalog.ModulesByModuleValue { v := meshcatalog.ModulesByModuleValue{V: keys.Version, Repository: e.Repository, Path: e.Path, Commit: e.Commit, Manifest: meshcatalogclient.BareManifestDigest(e.ManifestDigest), - Verdict: e.Verdict, Fp2: e.Fp, None2: e.None, Packages: maps.Clone(e.Packages)} + Verdict: e.Verdict, Fp2: e.Fp, None2: e.None, Packages: maps.Clone(e.Packages), Needs: slices.Clone(e.Needs)} if in := e.Inputs; in != nil { v.Toolchains, v.Paths, v.Problems, v.Warnings, v.Unknown = maps.Clone(in.Toolchains), maps.Clone(in.Paths), in.Problems, in.Warnings, in.Unknown if in.From != nil { diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_graph_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_graph_test.go index 69dca5113..f54f70885 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_graph_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_graph_test.go @@ -109,6 +109,19 @@ func TestAnEntryNamesWhatItContributesToAndEveryRequirement(t *testing.T) { if e := CatalogEntryOf("kv", meshcatalog.ModulesByModuleValue{}, catalogue.Manifest{}, "", graph.Node{}); e.Contributes != nil || e.Class != "" { t.Errorf("an entry of a manifest contributing nothing and naming no class carries contributes %v, class %q", e.Contributes, e.Class) } + // Design 47 H2 H-A-682 (1): a module whose value names needs carries them sorted on its entry, and the value read back + // from the entry names them; a value with none leaves the entry's needs absent. + needs := []string{"seat:node-engine", "form:dir", "word:runs-as"} + e = CatalogEntryOf("web", meshcatalog.ModulesByModuleValue{Needs: needs}, m, raw, graph.Node{}) + if want := []string{"form:dir", "seat:node-engine", "word:runs-as"}; !reflect.DeepEqual(e.Needs, want) { + t.Errorf("needs = %v, want %v", e.Needs, want) + } + if back := ModuleValueOf(e); !reflect.DeepEqual(back.Needs, e.Needs) { + t.Errorf("the value read back names needs %v, want %v", back.Needs, e.Needs) + } + if e := CatalogEntryOf("web", meshcatalog.ModulesByModuleValue{}, m, raw, graph.Node{}); e.Needs != nil { + t.Errorf("a value with no needs gives the entry needs %v", e.Needs) + } // Design 47 H2 §810, H-A-394 (1): the entry carries its manifest's class, which the gate reads. if e := CatalogEntryOf("kv", meshcatalog.ModulesByModuleValue{}, catalogue.Manifest{Class: catalogue.ClassCore}, "", graph.Node{}); e.Class != catalogue.ClassCore { t.Errorf("the entry of a core manifest carries the class %q, want core", e.Class) diff --git a/modules/mesh-delivery-indexer/internal/index/toolchains_test.go b/modules/mesh-delivery-indexer/internal/index/toolchains_test.go index 9ee54972a..0be4f0fde 100644 --- a/modules/mesh-delivery-indexer/internal/index/toolchains_test.go +++ b/modules/mesh-delivery-indexer/internal/index/toolchains_test.go @@ -342,10 +342,10 @@ func TestBasesAreComputedFirstAndNoFingerprintTakesTheBuilder(t *testing.T) { // } // W3.1's inputs (the lead's ruling on finding 1): an entry carries what the next revision is computed from (the // fingerprint's inputs, the toolchains used, the package versions), so the module's value read back from it is the - // value modules held, but for the old line's fields. + // value modules held, but for the old-form fingerprint. for name := range mods.vals { m, _ := moduleOf(t, mods, name) - m.Fp, m.None, m.Needs = "", "", nil + m.Fp, m.None = "", "" if back := ModuleValueOf(entries[name]); !reflect.DeepEqual(back, m) { t.Errorf("%s read back from its entry = %+v, want %+v", name, back, m) }