Merge pull request 'Design 47 H1: a same-repository module named only by a replace is a requirement of the module graph (H-A-224)' (#302) from fix/47-H1-indexer-replace-required into main

This commit was merged in pull request #302.
This commit is contained in:
2026-11-21 00:30:50 +00:00
2 changed files with 25 additions and 3 deletions
@@ -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
@@ -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)
}
}