From 9e09767a4babc91f475b8b788e37ff26b3016db3 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 01:26:29 +0100 Subject: [PATCH] Indexer: a same-repository module named only by a replace is a requirement The watchman's go.mod names buildrun in a replace directive with no require line, and the walk of the module graph followed require lines only, so buildrun's requirement of the module assigner's client was never pinned and every test step of the watchman failed "no pin". The walk now takes the same-repository modules a go.mod replaces by a directory as required, with the same same-repository test, so their go.mod files are read and their other-repository requirements pinned, transitively. Builds: design 47 H-A-224, H-A-201 --- .../internal/index/package_trees.go | 8 +++++--- .../internal/index/package_trees_test.go | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/package_trees.go b/modules/mesh-delivery-indexer/internal/index/package_trees.go index 40d716d2..128150ff 100644 --- a/modules/mesh-delivery-indexer/internal/index/package_trees.go +++ b/modules/mesh-delivery-indexer/internal/index/package_trees.go @@ -60,8 +60,9 @@ func (t *goModTree) sameRepositoryDir(required string) (string, bool) { } // sameRepositoryRequired are the directories (from the root, sorted, each once) of every same-repository Go module the -// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). The -// start directories themselves are not among them. +// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). A +// same-repository module a go.mod names in a replace directive counts as required, whether or not a require line names it +// (H-A-224). The start directories themselves are not among them. func (t *goModTree) sameRepositoryRequired(start []string) []string { seen := map[string]bool{} for _, s := range start { @@ -72,7 +73,8 @@ func (t *goModTree) sameRepositoryRequired(start []string) []string { for len(queue) > 0 { dir := queue[0] queue = queue[1:] - for _, req := range fingerprint.MeshRequiresOf(t.goMod(dir)) { + raw := t.goMod(dir) + for _, req := range append(fingerprint.MeshRequiresOf(raw), fingerprint.ReplacedSiblings(raw, t.f.Repository)...) { d, ok := t.sameRepositoryDir(req) if !ok || seen[d] { continue 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 06c1fc06..69057f59 100644 --- a/modules/mesh-delivery-indexer/internal/index/package_trees_test.go +++ b/modules/mesh-delivery-indexer/internal/index/package_trees_test.go @@ -2,6 +2,7 @@ package index import ( "context" + "slices" "strings" "testing" @@ -141,4 +142,23 @@ func TestTheEntryPinsEveryRequirementOfTheModuleGraph(t *testing.T) { if _, pinned := pins[builds]; pinned || len(pins) != 1 { t.Errorf("pins = %v, want %s only, never a module of the repository", pins, conditions) } + // H-A-224: a same-repository module the go.mod names only in a replace directive (the watchman's buildrun) counts as + // required: its own requirement of another repository's client is pinned too. + const assigner = "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" + objects["modules/d/buildrun"] = strings.Repeat("d", 40) + ix, mods, _ = ptpIndexer(t, objects) + mod["modules/g"] += "\nreplace git.novox.be/novox/mesh-delivery/modules/d/buildrun => ../d/buildrun\n" + mod["modules/d/buildrun"] = "module git.novox.be/novox/mesh-delivery/modules/d/buildrun\n\nrequire " + assigner + 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 + } + if err := ix.Apply(context.Background(), f); err != nil { + t.Fatal(err) + } + if m, _ := moduleOf(t, mods, "g"); m.Inputs2 == nil || !slices.Contains(m.Inputs2.Packages, assigner) || !slices.Contains(m.Inputs2.Packages, conditions) { + t.Errorf("packages = %+v, want the replaced sibling's requirement %s pinned beside the client's", m.Inputs2, assigner) + } }