From 656bc8b5c2f4acd36e984041b38cbae130ca6747 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 11:30:00 +0100 Subject: [PATCH] I4: a fingerprint takes of a reported set only what the module graph publishes At every recompute, and where a report's import form is computed, the import set counts only the imports a package artifact of the module graph's entries holds (a Go module path or an npm name, itself or a path under it); any other import is outside the mesh and never sends the module to the version line. The state imports keeps the reported set whole. A graph state that cannot be listed keeps no name back, since its nodes name no package. Builds: design 47 H2 H-A-539, H-A-540 --- .../internal/index/form.go | 7 +- .../internal/index/imports.go | 7 +- .../internal/index/imports_test.go | 71 +++++++++++-------- .../internal/index/importset.go | 52 ++++++++++++++ .../internal/index/toolchains.go | 14 ++-- 5 files changed, 113 insertions(+), 38 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/form.go b/modules/mesh-delivery-indexer/internal/index/form.go index 1b1874c8a..ceceb5773 100644 --- a/modules/mesh-delivery-indexer/internal/index/form.go +++ b/modules/mesh-delivery-indexer/internal/index/form.go @@ -27,7 +27,8 @@ type form struct { // // - **The import form**, for a module whose import set is reported (reported: a key in the state imports, whatever the // set's length, or a set its value held before that state was, design 47 H2 H-A-536, H-A-537; the set is kept.Imports) -// when every import is published (the packages state): the content digest of each imported package and the requirements' digest of each +// when every import in the mesh (one a package of the module graph's entries holds, mesh; any other is outside it, +// H-A-539, H-A-540) is published (the packages state): the content digest of each imported package and the requirements' digest of each // mesh Go module holding one. Its versions are each holding module's published commit (another repository's only); an // import set naming none of another repository while the go.mod requires one keeps the version line's (refined). // - **A change of form never rebuilds by itself** (§4): kept.ImportForm is the import-form fingerprint of the inputs @@ -46,10 +47,10 @@ type form struct { // digests of that version's commit. // // It sets kept.ImportForm when it writes the import form. -func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, reported bool, toolchains map[string]meshcatalogclient.Toolchain2, prev meshcatalog.ModulesByModuleValue, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, logf func(string, ...any)) form { +func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, reported bool, mesh map[string]bool, toolchains map[string]meshcatalogclient.Toolchain2, prev meshcatalog.ModulesByModuleValue, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, logf func(string, ...any)) form { in := inputsFrom(module, *kept, toolchains) if reported { - r := fingerprint.Resolve(repository, kept.Imports, published) + r := fingerprint.Resolve(repository, inTheMesh(kept.Imports, mesh), published) if len(r.Missing) == 0 { in.Imports, in.Requires = r.Digests, r.Requires fp, none := fingerprint.Of(in) diff --git a/modules/mesh-delivery-indexer/internal/index/imports.go b/modules/mesh-delivery-indexer/internal/index/imports.go index 68888d8a6..22110afbe 100644 --- a/modules/mesh-delivery-indexer/internal/index/imports.go +++ b/modules/mesh-delivery-indexer/internal/index/imports.go @@ -61,9 +61,12 @@ func (ix *Indexer) keepImports(ctx context.Context, e reported) (bool, error) { kept := *cur.Inputs2 kept.Imports, kept.ImportForm = slices.Clone(e.imports), "" digests := map[string]string{} - if built, err := ix.publishedAsBuilt(ctx, cur, e); err != nil { + mesh, meshErr := ix.meshPackages(ctx, nil) // the import form takes only what the module graph publishes (H-A-539, H-A-540) + if meshErr != nil { + ix.logf("%s: the packages the module graph publishes cannot be read (%v): its imports are kept, and its next recompute writes the import form", e.module, meshErr) + } else if built, err := ix.publishedAsBuilt(ctx, cur, e); err != nil { ix.logf("%s: the packages its build imported cannot be read as built (%v): its imports are kept, and its next recompute writes the import form", e.module, err) - } else if r := fingerprint.Resolve(cur.Repository, e.imports, built); len(r.Missing) > 0 { + } else if r := fingerprint.Resolve(cur.Repository, inTheMesh(e.imports, mesh), built); len(r.Missing) > 0 { ix.logf("%s: no published package holds %v: its imports are kept, and the recompute that resolves them writes the import form", e.module, r.Missing) } else { in := inputsFrom(e.module, kept, toolchains) diff --git a/modules/mesh-delivery-indexer/internal/index/imports_test.go b/modules/mesh-delivery-indexer/internal/index/imports_test.go index d4ab0b575..02ea1a4fe 100644 --- a/modules/mesh-delivery-indexer/internal/index/imports_test.go +++ b/modules/mesh-delivery-indexer/internal/index/imports_test.go @@ -65,11 +65,7 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T ix.Packages, ix.Files, ix.Imports = newMem(), listings.files, newMem() // avahi's go.sum names mesh-sdk (the version line), as every Go module's does; mesh-sdk's module is held at c1. setPackages(t, mods, "avahi", []string{meshSDK}) - sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"}) - if err != nil { - t.Fatal(err) - } - mods.put("mesh-sdk", sdkModule) + meshSDKPublished(t, ix, mods) held, _ := ix.heldModules(ctx) if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil { t.Fatal(err) @@ -206,11 +202,7 @@ func onlyTheVersionLineTakesAPin(t *testing.T) { reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") ix.Packages, ix.Files, ix.Imports = newMem(), forge{c1: sdkFiles("a1", "b1")}.files, newMem() setPackages(t, mods, "avahi", []string{meshSDK}) - sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"}) - if err != nil { - t.Fatal(err) - } - mods.put("mesh-sdk", sdkModule) + meshSDKPublished(t, ix, mods) held, _ := ix.heldModules(ctx) if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil { t.Fatal(err) @@ -278,16 +270,15 @@ func aReportedSetIsAKeyOrAHeldSet(t *testing.T) { }{ {"a reported empty set (H-A-536)", nil, false}, {"a set held before the state imports, no key (H-A-537)", []string{meshSDK + "/buildstep"}, true}, + // H-A-539, H-A-540: an import no entry of the module graph publishes is outside the mesh: kept whole in the state + // imports, never sending the module to the version line. + {"a set with an import outside the mesh (H-A-540)", []string{"github.com/x/y", meshSDK + "/buildstep"}, false}, } { ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")}) reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") ix.Packages, ix.Files, ix.Imports = newMem(), forge{c1: sdkFiles("a1", "b1"), c3: sdkFiles("a2", "b1")}.files, newMem() setPackages(t, mods, "avahi", []string{meshSDK}) - sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"}) - if err != nil { - t.Fatal(err) - } - mods.put("mesh-sdk", sdkModule) + meshSDKPublished(t, ix, mods) held, _ := ix.heldModules(ctx) if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil { t.Fatal(err) @@ -303,6 +294,8 @@ func aReportedSetIsAKeyOrAHeldSet(t *testing.T) { if err := ix.dropImportSet(ctx, "avahi"); err != nil { t.Fatal(err) } + } else if set, found, _ := ix.ImportSetOf(ctx, "avahi"); !found || len(set.Imports) != len(c.imports) { + t.Fatalf("%s: imports.avahi = %+v, %v; want the reported set whole", c.name, set, found) } if err := ix.Recompute(ctx); err != nil { t.Fatal(err) @@ -323,6 +316,34 @@ func aReportedSetIsAKeyOrAHeldSet(t *testing.T) { } } +// meshSDKPublished holds mesh-sdk at c1 as an entry of the module graph whose Go package artifact publishes meshSDK (its +// go.mod's module line), so an import of it is in the mesh (design 47 H2 H-A-539, H-A-540). +func meshSDKPublished(t *testing.T, ix *Indexer, mods *memStore) { + t.Helper() + manifest := `{"module":"mesh-sdk","version":"0.1","build":{"artifacts":[{"name":"go","kind":"package","language":"go","paths":["go"]}]}}` + digest := meshcatalogclient.ManifestDigest([]byte(manifest)) + kept, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "mesh-sdk", Manifest: manifest}) + if err != nil { + t.Fatal(err) + } + key, _ := meshcatalogclient.ManifestsKey(digest) + if ix.Manifests == nil { + ix.Manifests = newMem() + } + ix.Manifests.(*memStore).put(key, kept) + sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package", Manifest: digest}) + if err != nil { + t.Fatal(err) + } + mods.put("mesh-sdk", sdkModule) + ix.ReadFile = func(_ context.Context, repository, _, file string) ([]byte, error) { + if repository == "novox/mesh-sdk" && file == "go/go.mod" { + return []byte("module " + meshSDK + "\n"), nil + } + return nil, nil + } +} + // A build of a fingerprint the module no longer holds says nothing of its inputs now: its imports are not kept. func buildOfAnOlderFingerprintKeepsNoImports(t *testing.T) { ctx := context.Background() @@ -437,11 +458,7 @@ func anAcceptedSeriesPinsItsNewest(t *testing.T) { reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") ix.Packages, ix.Files = newMem(), forge{c1: sdkFiles("a1", "b1"), c2: sdkFiles("a1", "b2"), c3: sdkFiles("a2", "b2")}.files setPackages(t, mods, "avahi", []string{meshSDK}) - sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"}) - if err != nil { - t.Fatal(err) - } - mods.put("mesh-sdk", sdkModule) + meshSDKPublished(t, ix, mods) step := func(what string, act func() error) meshcatalog.ModulesByModuleValue { t.Helper() if err := act(); err != nil { @@ -504,11 +521,7 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t * reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") ix.Packages, ix.Files = newMem(), forge{c1: sdkFiles("a1", "b1"), c3: sdkFiles("a2", "b2")}.files setPackages(t, mods, "avahi", []string{meshSDK}) - raw, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"}) - if err != nil { - t.Fatal(err) - } - mods.put("mesh-sdk", raw) + meshSDKPublished(t, ix, mods) held, _ := ix.heldModules(ctx) if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil { t.Fatal(err) @@ -602,7 +615,7 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t * {"a build's imports naming none of another repository, which none publishes", held, []string{own}, ""}, } { kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Packages: []string{contracts}, Imports: c.imports} - f := formOf("avahi", "novox/mesh-catalog", &kept, c.imports != nil, nil, meshcatalog.ModulesByModuleValue{}, c.held, published, nil, nil) + f := formOf("avahi", "novox/mesh-catalog", &kept, c.imports != nil, map[string]bool{contracts: true, own: true, meshSDK: true}, nil, meshcatalog.ModulesByModuleValue{}, c.held, published, nil, nil) if got := f.versions[contracts]; got != c.want { t.Errorf("%s: version of %s = %q, want %q", c.name, contracts, got, c.want) } @@ -614,12 +627,12 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t * // so the module has a fingerprint, and the same tree gives the same one whatever commit names it. sibling := "git.novox.be/novox/mesh-catalog/modules/sibling" kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t\nderived modules/sibling o1", Packages: []string{sibling}} - f := formOf("avahi", "novox/mesh-catalog", &kept, false, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil) + f := formOf("avahi", "novox/mesh-catalog", &kept, false, map[string]bool{contracts: true, own: true, meshSDK: true}, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil) if f.fp == "" { t.Fatalf("an unpublished package of the same repository: none %q, want a fingerprint by its directory's tree", f.none) } kept.Tree = "t\nderived modules/sibling o2" - if g := formOf("avahi", "novox/mesh-catalog", &kept, false, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil); g.fp == "" || g.fp == f.fp { + if g := formOf("avahi", "novox/mesh-catalog", &kept, false, map[string]bool{contracts: true, own: true, meshSDK: true}, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil); g.fp == "" || g.fp == f.fp { t.Errorf("the sibling's directory changed: fingerprint %q, was %q; want a new one", g.fp, f.fp) } }) @@ -629,7 +642,7 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t * imports []string }{{"an import no package holds", []string{meshSDK + "/announce"}}, {"no import reported", nil}} { kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Imports: c.imports, ImportForm: "src2:" + strings.Repeat("a", 64)} - f := formOf("avahi", "novox/mesh-catalog", &kept, c.imports != nil, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil) + f := formOf("avahi", "novox/mesh-catalog", &kept, c.imports != nil, map[string]bool{meshSDK: true}, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil) if kept.ImportForm != "" { t.Errorf("%s: kept import form %q after the version line %q", c.name, kept.ImportForm, f.fp) } diff --git a/modules/mesh-delivery-indexer/internal/index/importset.go b/modules/mesh-delivery-indexer/internal/index/importset.go index 09a6601f4..2867c5e51 100644 --- a/modules/mesh-delivery-indexer/internal/index/importset.go +++ b/modules/mesh-delivery-indexer/internal/index/importset.go @@ -6,10 +6,12 @@ import ( "errors" "fmt" "slices" + "strings" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph" stdio "git.novox.be/novox/mesh-sdk/go" ) @@ -194,3 +196,53 @@ func (ix *Indexer) trunkImportForm(ctx context.Context, key string, imports []st } return m.Inputs2.ImportForm } + +// meshPackages are the names of the packages the entries of the module graph being computed publish (its held modules, +// as viewEntries gives each its artifacts; the graph's nodes name no package, so a graph state that cannot be listed +// keeps nothing from it, ADR 0603 §2), a Go module path or an npm name each: what a reported import set is held against +// at every recompute (design 47 H2 H-A-539, H-A-540). held nil reads the indexer's modules. +func (ix *Indexer) meshPackages(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue) (map[string]bool, error) { + if held == nil { + var err error + if held, err = ix.heldModules(ctx); err != nil { + return nil, err + } + } + names := map[string]bool{} + for name, cur := range held { + if cur.Manifest == "" { + continue + } + raw, m, err := ix.manifestRaw(ctx, cur.Manifest) + if err != nil { + continue // a manifest that cannot be read publishes nothing this pass; the recompute says it of the module + } + for _, a := range ix.withArtifacts(ctx, CatalogEntryOf(name, cur, m, raw, graph.Node{}), m).Artifacts { + if p := a.Package; p != nil && p.Name != "" && (p.Ecosystem == EcosystemGo || p.Ecosystem == EcosystemNpm) { + names[p.Name] = true + } + } + } + return names, nil +} + +// inTheMesh are the imports a package of names holds, the package itself or a path under it (I9's reading); any other +// import is outside the mesh, and never sends the module to the version line (design 47 H2 H-A-539, H-A-540). The state +// imports keeps the set whole; only what the fingerprint takes is held against names. +func inTheMesh(imports []string, names map[string]bool) []string { + var out []string + for _, imp := range imports { + for p := imp; p != ""; { + if names[p] { + out = append(out, imp) + break + } + i := strings.LastIndex(p, "/") + if i < 0 { + break + } + p = p[:i] + } + } + return out +} diff --git a/modules/mesh-delivery-indexer/internal/index/toolchains.go b/modules/mesh-delivery-indexer/internal/index/toolchains.go index bc1688871..a6935710a 100644 --- a/modules/mesh-delivery-indexer/internal/index/toolchains.go +++ b/modules/mesh-delivery-indexer/internal/index/toolchains.go @@ -235,6 +235,12 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc ix.logf("no fingerprint is written by this pass: %v", err) return fmt.Errorf("no fingerprint is written: %w", err) } + // The packages the module graph's entries publish: a reported import set counts only those (design 47 H2 H-A-539, H-A-540). + mesh, err := ix.meshPackages(ctx, held) + if err != nil { + ix.logf("no fingerprint is written by this pass: the packages the module graph publishes cannot be read: %v", err) + return fmt.Errorf("no fingerprint is written: %w", err) + } series := ix.SeriesAll(ctx) // each package's series, the newest a user accepting it takes (DLV-I6) type result struct { fp, none string @@ -308,11 +314,11 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc r.none = strings.Join(missing, "; ") case noToolchain != "": r.none = noToolchain - if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins, series); ok { + if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins, series, mesh); ok { r = result{fp: fp, tcs: k.held.Toolchains, pkgs: pkgs} } default: - f := formOf(module, k.cur.Repository, &kept, k.reported, toolchains, k.held, held, pub, pins, ix.logf) + f := formOf(module, k.cur.Repository, &kept, k.reported, mesh, toolchains, k.held, held, pub, pins, ix.logf) r.fp, r.none = f.fp, f.none if r.fp != "" { // a pin is a released version, never a commit (H-A-161), and the version line's fingerprint takes it (H-A-167) @@ -519,7 +525,7 @@ func hasContext(m catalogue.Manifest) bool { // with the toolchains it was computed with in place of the languages agreed on none, give it again, in its form. Any // other input that moved (a merge, a base, an agreed toolchain, an imported package) gives another fingerprint, and the // module has none until they agree. -func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, series map[string]SeriesPackage) (string, sdkstep.PackageVersions, bool) { +func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, series map[string]SeriesPackage, mesh map[string]bool) (string, sdkstep.PackageVersions, bool) { if k.held.Fp2 == "" { return "", nil, false } @@ -535,7 +541,7 @@ func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, } toolchains[artifact] = meshcatalogclient.Toolchain2{Language: language, Version: used.Version, Recipe: used.Recipe} } - f := formOf(module, k.held.Repository, &kept, k.reported, toolchains, k.held, held, published, pins, nil) + f := formOf(module, k.held.Repository, &kept, k.reported, mesh, toolchains, k.held, held, published, pins, nil) if f.none != "" || f.fp == "" { return "", nil, false }