diff --git a/modules/mesh-delivery-indexer/internal/index/modules.go b/modules/mesh-delivery-indexer/internal/index/modules.go index 6efa9c20..a67cd6b7 100644 --- a/modules/mesh-delivery-indexer/internal/index/modules.go +++ b/modules/mesh-delivery-indexer/internal/index/modules.go @@ -110,6 +110,11 @@ func (ix *Indexer) applyMoving(ctx context.Context, f whole, drop bool, moves ma next.None2 = "the manifest cannot be read: it cannot be kept as a value" } else { packages := ix.goPackages(ctx, f, dir, cur, has) + if m, err := judge.ForInputs([]byte(raw)); err == nil && usesGo(languagesOf(m)) { + // The entry pins every mesh package of another repository the module's build requires, transitively across + // the same-repository modules of its graph (design 47 H-A-201). + packages = unionSorted(packages, trees.otherRequired(goModuleDirs(m, dir))) + } in := inputsOfNamed(name, raw, f.Trees[dir], f.Locks[dir], objects[dir], packages, ix.baseFP(ctx)) if in.Kept != nil { // A Go build resolves the same-repository modules its go.mod files require, transitively, from the tree: their diff --git a/modules/mesh-delivery-indexer/internal/index/package_trees.go b/modules/mesh-delivery-indexer/internal/index/package_trees.go index c5ffe23b..40d716d2 100644 --- a/modules/mesh-delivery-indexer/internal/index/package_trees.go +++ b/modules/mesh-delivery-indexer/internal/index/package_trees.go @@ -106,6 +106,29 @@ func goModuleDirs(m catalogue.Manifest, dir string) []string { return out } +// otherRequired are the mesh packages of other repositories (sorted, each once) that the go.mod of each start directory, +// and of every same-repository module those require transitively (sameRepositoryRequired), requires at any version, the +// zero version included: every one the module's build resolves, which the entry pins (design 47 H-A-201, H-A-183, +// H-A-157). A same-repository module is none: it is built from the tree (H-A-198, H-A-202). nil for none. +func (t *goModTree) otherRequired(start []string) []string { + var out []string + for _, d := range append(slices.Clone(start), t.sameRepositoryRequired(start)...) { + out = append(out, fingerprint.OtherPackages(fingerprint.MeshRequiresOf(t.goMod(d)), t.f.Repository)...) + } + if len(out) == 0 { + return nil + } + return slices.Compact(slices.Sorted(slices.Values(out))) +} + +// unionSorted is a and b together, sorted and each once; nil for none. +func unionSorted(a, b []string) []string { + if len(a)+len(b) == 0 { + return nil + } + return slices.Compact(slices.Sorted(slices.Values(append(slices.Clone(a), b...)))) +} + // derivedDirs are the same-repository module directories (from the root, sorted) the module's Go build resolves from the // tree beyond its own tree input (H-A-202): every one its go.mod files require, transitively, that its tree input does // not hold already, which is the module's directory for the directory's tree, and its named paths for the named tree. diff --git a/modules/mesh-delivery-indexer/internal/index/package_trees_test.go b/modules/mesh-delivery-indexer/internal/index/package_trees_test.go index ecdfeeb0..999bb220 100644 --- a/modules/mesh-delivery-indexer/internal/index/package_trees_test.go +++ b/modules/mesh-delivery-indexer/internal/index/package_trees_test.go @@ -5,6 +5,9 @@ import ( "strings" "testing" + sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" + "git.novox.be/novox/mesh-sdk/go/catalogue" + "mesh-delivery-indexer/internal/fingerprint" ) @@ -106,3 +109,36 @@ func TestADerivedDirectoryMovesTheFingerprintOfEveryForm(t *testing.T) { t.Errorf("module = %+v, want none naming the directory the forge gave no object of", m) } } + +// Design 47 H-A-201: the entry pins every mesh package of another repository the module's build requires, across the +// same-repository modules of its graph: here the one modules/c/client requires, which modules/g's go.mod never names. +// A module of the module's own repository is never pinned, whatever a build reported (H-A-198, H-A-202). +func TestTheEntryPinsEveryRequirementOfTheModuleGraph(t *testing.T) { + const conditions = "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" + objects := map[string]string{"modules/b/builds": strings.Repeat("b", 40), "modules/c/client": strings.Repeat("c", 40)} + ix, mods, _ := ptpIndexer(t, objects) + mod := map[string]string{ + "modules/g": "module g\n\nrequire git.novox.be/novox/mesh-delivery/modules/b/builds" + ptpZero + "\n", + "modules/c/client": "module git.novox.be/novox/mesh-delivery/modules/c/client\n\nrequire " + conditions + ptpZero + "\n", + } + ix.GoMod = func(_ context.Context, _, _, dir string) ([]byte, error) { + if c, ok := mod[dir]; ok { + return []byte(c), nil + } + return []byte(ptpGoMods[dir]), nil + } + f := withManifests(mergedMsg("novox/mesh-delivery", map[string]string{"modules/g": "gtree"}), map[string]string{"modules/g": ptpProgram}, + map[string]map[string]string{"modules/g": {"go.sum": avahiGoSum}}) + if err := ix.Apply(context.Background(), f); err != nil { + t.Fatal(err) + } + m, _ := moduleOf(t, mods, "g") + if m.Inputs2 == nil || strings.Join(m.Inputs2.Packages, ",") != conditions+",git.novox.be/novox/mesh-sdk/go" { + t.Errorf("packages = %+v, want the client's requirement and state's mesh-sdk, and no module of the repository", m.Inputs2) + } + builds := "git.novox.be/novox/mesh-delivery/modules/b/builds" + pins := releasedPins(sdkstep.PackageVersions{builds: "v0.1.106", conditions: "v0.1.4"}, nil, catalogue.Manifest{}, "novox/mesh-delivery") + if _, pinned := pins[builds]; pinned || len(pins) != 1 { + t.Errorf("pins = %v, want %s only, never a module of the repository", pins, conditions) + } +} diff --git a/modules/mesh-delivery-indexer/internal/index/toolchains.go b/modules/mesh-delivery-indexer/internal/index/toolchains.go index c6a4a53a..f8c1eb67 100644 --- a/modules/mesh-delivery-indexer/internal/index/toolchains.go +++ b/modules/mesh-delivery-indexer/internal/index/toolchains.go @@ -298,7 +298,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc 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) - r.fp, r.pkgs = pinnedOf(f, series, k.manifest) + r.fp, r.pkgs = pinnedOf(f, series, k.manifest, k.cur.Repository) r.tcs = toolchainsUsed(toolchains) } } @@ -517,7 +517,7 @@ func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, if f.none != "" || f.fp == "" { return "", nil, false } - fp, pkgs := pinnedOf(f, series, k.manifest) + fp, pkgs := pinnedOf(f, series, k.manifest, k.held.Repository) return fp, pkgs, fp == k.held.Fp2 } diff --git a/modules/mesh-delivery-indexer/internal/index/versions.go b/modules/mesh-delivery-indexer/internal/index/versions.go index f199ff14..9500d302 100644 --- a/modules/mesh-delivery-indexer/internal/index/versions.go +++ b/modules/mesh-delivery-indexer/internal/index/versions.go @@ -15,6 +15,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/keys" @@ -373,13 +374,17 @@ func isFloor(raw []byte) bool { // within the series the module accepts, the one its manifest m names or the default (Manifest.AcceptedSeries), whether // or not that series holds contents yet; a publish in another series pins nothing and moves nothing, and a module's // release number is never a pin. A package with none published in that series is kept with no version, so its kind-1 -// edge stands (H §746) and its build waits for the publish (H-A-165). nil for none. -func releasedPins(versions sdkstep.PackageVersions, series map[string]SeriesPackage, m catalogue.Manifest) sdkstep.PackageVersions { +// edge stands (H §746) and its build waits for the publish (H-A-165). A module of the module's own repository is never +// pinned, whatever a build reported: it is built from the tree (design 47 H-A-198, H-A-201, H-A-202). nil for none. +func releasedPins(versions sdkstep.PackageVersions, series map[string]SeriesPackage, m catalogue.Manifest, repository string) sdkstep.PackageVersions { if len(versions) == 0 { return nil } out := sdkstep.PackageVersions{} for p := range versions { + if repo, _, ok := trunk.PackageRepository(p); ok && repository != "" && trunk.SameRepository(repo, repository) { + continue + } out[p] = "" for _, s := range series { if s.GoModule != p || s.Newest == nil || s.Series != m.AcceptedSeries(s.Name) { @@ -398,8 +403,8 @@ func releasedPins(versions sdkstep.PackageVersions, series map[string]SeriesPack // form's fingerprint takes them (design 47 H-A-167, H-A-172; ADR 0573 §4) and a re-pin moves it, the module a mover // built again against the release; a fingerprint with no pin is the form's as it is. The held fingerprint of a build that // stands is kept while its pins are the ones it was built with, else its import form takes the new pins. -func pinnedOf(f form, series map[string]SeriesPackage, m catalogue.Manifest) (string, sdkstep.PackageVersions) { - pins := releasedPins(f.versions, series, m) +func pinnedOf(f form, series map[string]SeriesPackage, m catalogue.Manifest, repository string) (string, sdkstep.PackageVersions) { + pins := releasedPins(f.versions, series, m, repository) if f.stands { if maps.Equal(f.built, map[string]string(pins)) { return f.fp, pins