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
165 lines
8.8 KiB
Go
165 lines
8.8 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"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"
|
|
)
|
|
|
|
// A fixture repository novox/mesh-delivery: the Go package state of modules/g requires the same-repository module
|
|
// modules/b/builds at the zero version, which requires modules/c/client in turn; mesh-sdk is of another repository, and
|
|
// modules/b/gone names a directory the tree holds no go.mod of.
|
|
const ptpZero = " v0.0.0-00010101000000-000000000000"
|
|
|
|
var ptpGoMods = map[string]string{
|
|
"modules/g/state": "module git.novox.be/novox/mesh-delivery/modules/g/state\n\nrequire (\n\tgit.novox.be/novox/mesh-delivery/modules/b/builds" + ptpZero +
|
|
"\n\tgit.novox.be/novox/mesh-sdk/go" + ptpZero + "\n\tgit.novox.be/novox/mesh-delivery/modules/b/gone" + ptpZero + "\n)\n",
|
|
"modules/b/builds": "module git.novox.be/novox/mesh-delivery/modules/b/builds\n\nrequire git.novox.be/novox/mesh-delivery/modules/c/client" + ptpZero + " // indirect\n",
|
|
"modules/c/client": "module git.novox.be/novox/mesh-delivery/modules/c/client\n",
|
|
}
|
|
|
|
// ptpProgram is modules/g's manifest: a program naming no paths beside the package state.
|
|
const ptpProgram = `{"module":"g","version":"1.0","build":{"artifacts":[{"name":"program","kind":"bundle","language":"go","system":"arch","from":"cmd/g","binary":"g","loads":["g"]},` +
|
|
`{"name":"state","kind":"package","language":"go","paths":["state"],"series":"0.1"}]}}`
|
|
|
|
// ptpIndexer answers the fixture's go.mod files and, for a path asked from the root, the object objects names for it.
|
|
func ptpIndexer(t *testing.T, objects map[string]string) (*Indexer, *memStore, *[]map[string][]string) {
|
|
ix, mods, _ := manifestsIndexer(t)
|
|
ix.GoMod = func(_ context.Context, _, _, dir string) ([]byte, error) {
|
|
if c, ok := ptpGoMods[dir]; ok {
|
|
return []byte(c), nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
var asked []map[string][]string
|
|
ix.Named = func(_ context.Context, _, _ string, paths map[string][]string) (map[string]map[string]string, error) {
|
|
asked = append(asked, paths)
|
|
out := map[string]map[string]string{}
|
|
for dir, ps := range paths {
|
|
out[dir] = map[string]string{}
|
|
for _, p := range ps {
|
|
out[dir][p] = objects[p]
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
return ix, mods, &asked
|
|
}
|
|
|
|
// Design 47 H-A-202, H-A-172: the same-repository modules a Go build resolves from the tree, transitively, join the tree
|
|
// input of every form with their objects, so a change of one moves the fingerprint of a module whose program names no
|
|
// paths; the entry's paths stay the manifest's.
|
|
func TestADerivedDirectoryMovesTheFingerprintOfEveryForm(t *testing.T) {
|
|
objects := map[string]string{"modules/b/builds": strings.Repeat("b", 40), "modules/c/client": strings.Repeat("c", 40)}
|
|
tree := func(objects map[string]string) string {
|
|
ix, mods, asked := ptpIndexer(t, objects)
|
|
f := withManifests(mergedMsg("novox/mesh-delivery", map[string]string{"modules/g": "gtree"}), map[string]string{"modules/g": ptpProgram}, nil)
|
|
if err := ix.Apply(context.Background(), f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m, _ := moduleOf(t, mods, "g")
|
|
if got := strings.Join(m.Paths["state"], ","); got != "state" {
|
|
t.Errorf("the entry's paths of state are %q, want the manifest's", got)
|
|
}
|
|
if len(*asked) != 1 || strings.Join((*asked)[0][""], ",") != "modules/b/builds,modules/c/client" {
|
|
t.Fatalf("asked the forge %v, want the derived directories from the root once", *asked)
|
|
}
|
|
if m.Inputs2 == nil || !strings.HasPrefix(m.Inputs2.Tree, "gtree\n") {
|
|
t.Fatalf("inputs = %+v (%s), want the directory's tree with the derived lines", m.Inputs2, m.None2)
|
|
}
|
|
return m.Inputs2.Tree
|
|
}
|
|
before := tree(objects)
|
|
if want := "gtree\nderived modules/b/builds " + objects["modules/b/builds"] + "\nderived modules/c/client " + objects["modules/c/client"]; before != want {
|
|
t.Errorf("the tree input is %q, want %q", before, want)
|
|
}
|
|
objects["modules/c/client"] = strings.Repeat("d", 40)
|
|
after := tree(objects)
|
|
fp := func(tree string) string {
|
|
v, _ := fingerprint.Of(fingerprint.Inputs{Module: "g", Tree: tree})
|
|
return v
|
|
}
|
|
if fp(before) == fp(after) {
|
|
t.Errorf("a change of modules/c/client left the fingerprint %s", fp(after))
|
|
}
|
|
// The named tree takes them too: a module whose every artifact names its paths.
|
|
named := `{"module":"g","version":"1.0","build":{"artifacts":[{"name":"state","kind":"package","language":"go","paths":["state"],"series":"0.1"}]}}`
|
|
ix, mods, _ := ptpIndexer(t, objects)
|
|
f := withManifests(mergedMsg("novox/mesh-delivery", map[string]string{"modules/g": "gtree"}), map[string]string{"modules/g": named}, nil)
|
|
f.Paths = map[string]map[string]string{"modules/g": {"state": strings.Repeat("1", 40)}}
|
|
if err := ix.Apply(context.Background(), f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m, _ := moduleOf(t, mods, "g"); m.Inputs2 == nil || !strings.HasPrefix(m.Inputs2.Tree, fingerprint.NamedTreePrefix) ||
|
|
!strings.HasSuffix(m.Inputs2.Tree, "\nderived modules/c/client "+objects["modules/c/client"]) || strings.Join(m.Paths["state"], ",") != "state" {
|
|
t.Errorf("module = %+v, want the named tree with the derived lines and the manifest's paths", m)
|
|
}
|
|
// A forge that names no object of a derived directory gives the module none, naming it.
|
|
ix, mods, _ = ptpIndexer(t, map[string]string{"modules/b/builds": strings.Repeat("b", 40)})
|
|
if err := ix.Apply(context.Background(), withManifests(mergedMsg("novox/mesh-delivery", map[string]string{"modules/g": "gtree"}),
|
|
map[string]string{"modules/g": ptpProgram}, nil)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m, _ := moduleOf(t, mods, "g"); m.Fp2 != "" || !strings.Contains(m.None2, "modules/c/client") {
|
|
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", nil)
|
|
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)
|
|
}
|
|
}
|