I11 entry-needs: CatalogEntryOf writes the entry's needs from the module's value, ModuleValueOf reads them back

Builds: design 47 H2 H-A-682 (1), H-A-568, H-A-569 (2)
This commit is contained in:
2026-11-25 17:20:01 +01:00
parent d4ea1f3445
commit 3baef9df5b
3 changed files with 23 additions and 5 deletions
@@ -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, 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, 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} 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 // 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). // included, since contributing to a requirement is requiring it (design 47 G §709, A-229).
for _, r := range m.Wants() { 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 // 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 // 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 // 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
// fingerprint, the reader needs) are not kept. // line's old-form fingerprint is not kept.
func ModuleValueOf(e meshcatalog.CatalogEntry) meshcatalog.ModulesByModuleValue { 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), 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 { 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 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 { if in.From != nil {
@@ -109,6 +109,19 @@ func TestAnEntryNamesWhatItContributesToAndEveryRequirement(t *testing.T) {
if e := CatalogEntryOf("kv", meshcatalog.ModulesByModuleValue{}, catalogue.Manifest{}, "", graph.Node{}); e.Contributes != nil || e.Class != "" { 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) 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. // 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 { 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) t.Errorf("the entry of a core manifest carries the class %q, want core", e.Class)
@@ -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 // 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 // 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 { for name := range mods.vals {
m, _ := moduleOf(t, mods, name) 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) { if back := ModuleValueOf(entries[name]); !reflect.DeepEqual(back, m) {
t.Errorf("%s read back from its entry = %+v, want %+v", name, back, m) t.Errorf("%s read back from its entry = %+v, want %+v", name, back, m)
} }