I9: the catalog graph's kind 1 comes from the reported import set

An entry whose fingerprint was computed with an import set gets one kind-1 edge per import,
from the package artifact of the longest name holding it to its artifacts of that ecosystem;
a requirement no import names gives none. An entry with no set keeps kind 1 from packages.

Builds: design 47 H2 H-A-522, H-A-532 DQ-14
This commit is contained in:
2026-11-23 11:14:24 +01:00
parent 2f4fe5fa8b
commit b52a70b1b2
2 changed files with 64 additions and 11 deletions
@@ -245,22 +245,32 @@ func edgesOf(a meshcatalog.CatalogEntry, all map[string]meshcatalog.CatalogEntry
}
modules := slices.Sorted(maps.Keys(all))
delivers := primaryOf(a)
// Kind 1: a package its build imports, from the artifact that publishes it, to each artifact built from that ecosystem (§47).
for _, name := range slices.Sorted(maps.Keys(a.Packages)) {
for _, m := range modules {
b := all[m]
if m == a.Module {
continue
}
for _, art := range b.Artifacts {
if art.Package == nil || art.Package.Name != name {
// Kind 1: a package its build imports, from the artifact that publishes it, to each artifact built from that ecosystem (§47):
// from its reported import set, each import from the package artifact of the longest name holding it (design 47 H2
// H-A-522, H-A-532 DQ-14); from its manifest's packages only until a set is reported.
if imports := importSetOf(a); len(imports) > 0 {
for _, imp := range imports {
var holder *meshcatalog.Artifact
for _, m := range modules {
if m == a.Module {
continue
}
for _, to := range importersOf(a, art.Package.Ecosystem) {
add(meshcatalog.Edge{Kind: 1, From: art.Ref, To: to, Stale: true, Word: "packages", Why: name})
for i, art := range all[m].Artifacts {
if p := art.Package; p != nil && (imp == p.Name || strings.HasPrefix(imp, p.Name+"/")) &&
(holder == nil || len(p.Name) > len(holder.Package.Name)) {
holder = &all[m].Artifacts[i]
}
}
}
if holder == nil {
continue
}
for _, to := range importersOf(a, holder.Package.Ecosystem) {
add(meshcatalog.Edge{Kind: 1, From: holder.Ref, To: to, Stale: true, Word: "imports", Why: imp})
}
}
} else {
edgesOfPackages(a, all, modules, add)
}
// Kind 2: an artifact its manifest's `needs` references in another module, published before the artifact that names it
// delivers (A-212, §432).
@@ -453,3 +463,32 @@ func (ix *Indexer) withActs(ctx context.Context, entries map[string]meshcatalog.
}
return WithActs(entries, defs)
}
// importSetOf is the import set the entry's fingerprint was computed with (its inputs' imports), none before a report.
func importSetOf(a meshcatalog.CatalogEntry) []string {
if a.Inputs == nil || a.Inputs.From == nil {
return nil
}
return a.Inputs.From.Imports
}
// edgesOfPackages are kind 1 from the entry's packages, its go.mod's requirements, for an entry with no reported import set
// (H-A-522).
func edgesOfPackages(a meshcatalog.CatalogEntry, all map[string]meshcatalog.CatalogEntry, modules []string, add func(meshcatalog.Edge)) {
for _, name := range slices.Sorted(maps.Keys(a.Packages)) {
for _, m := range modules {
b := all[m]
if m == a.Module {
continue
}
for _, art := range b.Artifacts {
if art.Package == nil || art.Package.Name != name {
continue
}
for _, to := range importersOf(a, art.Package.Ecosystem) {
add(meshcatalog.Edge{Kind: 1, From: art.Ref, To: to, Stale: true, Word: "packages", Why: name})
}
}
}
}
}
@@ -49,6 +49,20 @@ func TestAnEntryCarriesItsEdgesOfKindsOneToFourAndSix(t *testing.T) {
if len(before.Edges) != 0 || len(entries["app"].Edges) != 0 {
t.Errorf("the entries given were changed")
}
// Design 47 H2 H-A-522, H-A-532 DQ-14: with a reported import set, kind 1 comes from it, each import from the package of
// the longest Go module path holding it (lib/go/sub, nested in lib/go), and none from a requirement no import names.
entries["sub"] = meshcatalog.CatalogEntry{Module: "sub", Artifacts: []meshcatalog.Artifact{{Ref: "sub:go", Language: "go", Kind: "package",
Package: &meshcatalog.ArtifactPackage{Ecosystem: EcosystemGo, Name: "git.example/lib/go/sub"}}}}
entries["other"] = meshcatalog.CatalogEntry{Module: "other", Artifacts: []meshcatalog.Artifact{{Ref: "other:go", Language: "go", Kind: "package",
Package: &meshcatalog.ArtifactPackage{Ecosystem: EcosystemGo, Name: "git.example/other/go"}}}}
imp := entries["app"]
imp.Packages = map[string]string{"git.example/lib/go": "1.2.3", "git.example/other/go": "0.1.0"}
imp.Inputs = &meshcatalog.EntryInputs{From: &meshcatalog.FingerprintInputs{Imports: []string{"git.example/lib/go/sub/x"}}}
entries["app"] = imp
if got := WithEdges(entries)["app"].Edges; got[0] != (meshcatalog.Edge{Kind: 1, From: "sub:go", To: "app:program", Stale: true, Word: "imports", Why: "git.example/lib/go/sub/x"}) ||
slices.ContainsFunc(got[1:], func(e meshcatalog.Edge) bool { return e.Kind == 1 }) {
t.Errorf("edges with an import set: %+v, want one kind 1 from sub:go and none from the requirements", got)
}
}
// Design 47 G A-208: a revision kept holds each entry with its edges, so the builder and the assigner read them from the entry.