Design 47 H1: disk-load declares its readings package, the gate accepts asks at 0.3, the Go build module refuses a build with no pin and keeps the same-repository tree (H-A-186, H-A-188, H-A-192, H-A-202) #720

Merged
mesh-tools merged 3 commits from fix/47-H1-catalog-h1-owed into main 2026-11-20 21:39:11 +00:00
6 changed files with 111 additions and 50 deletions
+9
View File
@@ -24,6 +24,15 @@
"loads": [
"disk-load"
]
},
{
"name": "diskreadings",
"kind": "package",
"language": "go",
"paths": [
"diskreadings"
],
"series": "0.1"
}
]
},
@@ -2,6 +2,7 @@ package main
import (
"io/fs"
"maps"
"os"
"path"
"path/filepath"
@@ -127,11 +128,20 @@ func generatedFromDirs(tree, dir string) []string {
}
// ownZeroPackageDirs are the directories (from the tree's root) of the packages of the checked repository that a go.mod
// under the artifact's named paths requires at the zero version (H-A-136; ADR 0573 §2). Each is found by the manifests
// of the repository's modules: a module's directory or the directory of one of its artifacts' paths whose go.mod declares
// the required module path. One no manifest leads to is left to the fetch's resolution, which fails naming it.
// under the artifact's named paths requires at the zero version (H-A-136; ADR 0573 §2), transitively: the go.mod of each
// such directory is read in turn for the packages of the repository it requires at the zero version, each directory
// once (design 47 H, H-A-202, H-A-198). Each is found by the manifests of the repository's modules: a module's directory
// or the directory of one of its artifacts' paths whose go.mod declares the required module path. One no manifest leads
// to is left to the fetch's resolution, which fails naming it.
func ownZeroPackageDirs(tree, repository, dir string, paths []string) []string {
want := map[string]bool{}
addReqs := func(raw []byte) {
for _, pn := range forgePins(string(raw)) {
if pn.short == zeroShort && "novox/"+pn.repo == repository {
want[pn.module] = true
}
}
}
for _, p := range paths {
root := filepath.Join(tree, filepath.FromSlash(path.Join(dir, p)))
filepath.WalkDir(root, func(file string, e fs.DirEntry, err error) error {
@@ -147,14 +157,8 @@ func ownZeroPackageDirs(tree, repository, dir string, paths []string) []string {
if e.Name() != "go.mod" {
return nil
}
raw, err := os.ReadFile(file)
if err != nil {
return nil
}
for _, pn := range forgePins(string(raw)) {
if pn.short == zeroShort && "novox/"+pn.repo == repository {
want[pn.module] = true
}
if raw, err := os.ReadFile(file); err == nil {
addReqs(raw)
}
return nil
})
@@ -162,10 +166,29 @@ func ownZeroPackageDirs(tree, repository, dir string, paths []string) []string {
if len(want) == 0 {
return nil
}
var out []string
byModule := map[string][]string{} // a module path and the manifest-named directories whose go.mod declares it
for _, cand := range manifestDirs(tree) {
if mod := goModulePath(filepath.Join(tree, filepath.FromSlash(cand), "go.mod")); want[mod] && !slices.Contains(out, cand) {
out = append(out, cand)
if mod := goModulePath(filepath.Join(tree, filepath.FromSlash(cand), "go.mod")); mod != "" && !slices.Contains(byModule[mod], cand) {
byModule[mod] = append(byModule[mod], cand)
}
}
var out []string
done := map[string]bool{}
for len(want) > len(done) {
for _, mod := range slices.Sorted(maps.Keys(want)) {
if done[mod] {
continue
}
done[mod] = true
for _, cand := range byModule[mod] {
if slices.Contains(out, cand) {
continue
}
out = append(out, cand)
if raw, err := os.ReadFile(filepath.Join(tree, filepath.FromSlash(cand), "go.mod")); err == nil {
addReqs(raw) // what this package requires of the repository comes along (H-A-202)
}
}
}
}
slices.Sort(out)
@@ -29,6 +29,7 @@ func writeFile(t *testing.T, file, body string) {
// modules stay the artifact's own (A-447a): neither the generated-from directory's nor the sibling package's.
func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZeroVersionPackages(t *testing.T) {
const sdk = "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk"
const repo = "git.novox.be/novox/mesh-delivery"
zero := " v0.0.0-00010101000000-" + zeroShort
for _, tc := range []struct {
name, dir string
@@ -37,6 +38,7 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
kept, gone []string
modules []string
seats []string // generated into the tree by the seat generator, its out-of-step check then finding nothing
refused string // the narrowing fails naming this
}{
{name: "a generated-from directory", dir: "modules/c", paths: []string{"go/seats/a"},
files: map[string]string{
@@ -92,6 +94,33 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
"modules/mesh-delivery-sdk/go.mod", "modules/mesh-delivery-sdk/steprun/s.go"},
gone: []string{"module.json", "go.sum", "modules/mesh-delivery-view", "modules/mesh-delivery-contracts/go/clients/other"},
modules: []string{"modules/mesh-delivery-contracts/go/clients/meshcatalogclient"}},
// H-A-202, H-A-198: the packages of the repository a required one requires at the zero version come along too,
// transitively (state -> builds -> client), each found by its manifest.
{name: "the repository's packages a required package requires, transitively", dir: "modules/a", paths: []string{"state"},
files: map[string]string{
"modules/a/module.json": `{"module":"a","build":{"artifacts":[{"name":"state","kind":"package","language":"go","paths":["state"]}]}}`,
"modules/a/state/go.mod": "module " + repo + "/modules/a/state\n\ngo 1.26\n\nrequire " + repo + "/modules/b/builds" + zero + "\n",
"modules/a/state/s.go": "package state\n",
"modules/b/module.json": `{"module":"b","build":{"artifacts":[{"name":"builds","kind":"package","language":"go","paths":["builds"]}]}}`,
"modules/b/builds/go.mod": "module " + repo + "/modules/b/builds\n\ngo 1.26\n\nrequire (\n\t" + repo + "/modules/c/client" + zero + "\n\tgit.novox.be/novox/mesh-sdk/go" + zero + "\n)\n",
"modules/b/builds/b.go": "package builds\n",
"modules/b/other/o.go": "package other\n",
"modules/c/module.json": `{"module":"c","build":{"artifacts":[{"name":"client","kind":"package","language":"go","paths":["client"]}]}}`,
"modules/c/client/go.mod": "module " + repo + "/modules/c/client\n\ngo 1.26\n\nrequire " + repo + "/modules/b/builds" + zero + "\n",
"modules/c/client/c.go": "package client\n",
"modules/c/other/o.go": "package other\n",
"modules/d/module.json": `{"module":"d"}`,
},
kept: []string{"modules/a/state/s.go", "modules/b/builds/b.go", "modules/c/client/c.go"},
gone: []string{"modules/b/other", "modules/c/other", "modules/d"},
modules: []string{"modules/a/state"}},
// A named path that leaves the repository is refused.
{name: "a named path that leaves the repository", dir: "mesh-grants", paths: []string{".", "../../outside"},
files: map[string]string{"mesh-grants/module.json": `{"module":"mesh-grants"}`, "mesh-grants/go.mod": "module mesh-grants\n\ngo 1.26\n"},
refused: `"../../outside" leaves`},
{name: "a named path that leaves the repository from a nested module", dir: "modules/mesh-grants", paths: []string{"../../../outside"},
files: map[string]string{"modules/mesh-grants/module.json": `{"module":"mesh-grants"}`, "modules/mesh-grants/go.mod": "module mesh-grants\n\ngo 1.26\n"},
refused: `"../../../outside" leaves`},
} {
t.Run(tc.name, func(t *testing.T) {
tree := t.TempDir()
@@ -125,7 +154,14 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
}
}
req := sdkstep.FetchRequest{Repository: "novox/mesh-delivery", Commit: commitSHA, Dir: tc.dir, Paths: tc.paths}
if err := narrowTree(tree, req.Repository, req); err != nil {
err := narrowTree(tree, req.Repository, req)
if tc.refused != "" {
if err == nil || !strings.Contains(err.Error(), tc.refused) {
t.Fatalf("the narrowing answered %v, want it refused naming %s", err, tc.refused)
}
return
}
if err != nil {
t.Fatal(err)
}
for _, k := range tc.kept {
@@ -365,9 +365,9 @@ func (m *Module) takeReplacedZeroPins(ctx context.Context, root, repository, dir
}
// takeZeroRequirements takes, for each requirement at the zero version, the version it is built against (ADR 0573 §2,
// §4: whatever go.mod names): the commit the ask names for the package; else the head of the package's repository among
// the asked versions (the check's or try's members: another package of the same repository names it); else the latest
// published version, the trunk's head. It never looks for the commit 000000000000 among the pull request heads. One
// §4: whatever go.mod names): a module of the checked repository from the fetched tree (H-A-198); any other at the pin
// the ask names for that package path, and with no pin it refuses the build, never taking another path's version or
// the latest (design 47 H, H-A-192). It never looks for the commit 000000000000 among the pull request heads. One
// taken before (dir's modfile requires or replaces it) is left as it is.
func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir, d string, reqs []zeroRequirement, asked sdkstep.PackageVersions, pins *sync.Mutex) ([]TakenVersion, error) {
resolved := map[string]string{}
@@ -409,13 +409,13 @@ func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir
taken = append(taken, tv)
continue
}
tv := TakenVersion{Dir: d, Package: p.module, Asked: askedFor(asked, p), Named: named}
why := "the ask names it"
// The ask's pin for this path alone: a build module given no pin refuses the build, loud, and never takes another
// path's version nor the latest (design 47 H, H-A-192).
tv := TakenVersion{Dir: d, Package: p.module, Asked: asked[p.module], Named: named}
if tv.Asked == "" {
tv.Asked, why = "latest", "the ask names no commit of its repository, so its latest published version"
} else if _, ok := asked[p.module]; !ok {
why = "the head of its repository among the asked versions"
return taken, fmt.Errorf("no pin for %s: the builder pins or waits (H-A-192)", p.module)
}
why := "the ask names it"
if err := m.takeVersion(ctx, root, dir, &tv, pins); err != nil {
return taken, fmt.Errorf("the requirement of %s at the zero version: %w", p.module, err)
}
@@ -431,20 +431,6 @@ func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir
// namedBySaid says that a module dir replaces by the directory by names a package, and dir's go.mod does not.
func namedBySaid(by string) string { return "named by " + by + ", not by this go.mod" }
// askedFor is the commit the ask names for the package p: its own, else that of the first package of the same repository
// in order (the members' heads are by repository), else none.
func askedFor(asked sdkstep.PackageVersions, p pin) string {
if c := asked[p.module]; c != "" {
return c
}
for _, pkg := range slices.Sorted(maps.Keys(asked)) {
if pkg == forgePrefix+p.repo || strings.HasPrefix(pkg, forgePrefix+p.repo+"/") {
return asked[pkg]
}
}
return ""
}
// useOwnModules replaces, in dir's temporary modfile, every module of the fetched tree whose path lies in the repository
// repo by its directory in the tree (once), and answers the paths of those modules. A replace of a module dir does not
// require is harmless to Go; one module of a repository requires another of it at the zero version.
@@ -301,10 +301,10 @@ func TestARelativeReplaceStillResolvesInTheTemporaryModfile(t *testing.T) {
}
// A go.mod requirement at the zero version v0.0.0-00010101000000-000000000000 names no commit (ADR 0573 §2, §4: whatever
// go.mod names): it is taken from the commit the ask names for the package, else from the head of its repository among
// the asked versions, else from the trunk's latest published version, and never looked for as the commit 000000000000
// among the pull request heads.
func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
// go.mod names): it is taken from the pin the ask names for that package path alone, and never looked for as the commit
// 000000000000 among the pull request heads. With no pin of its own the build is refused, loud, naming the path: never
// built at another package's pin of the same repository nor at the latest (design 47 H, H-A-192).
func TestARequirementAtTheZeroVersionIsTakenFromItsPinOrRefused(t *testing.T) {
t.Parallel()
const sdk = "git.novox.be/novox/mesh-sdk/go"
zeroMod := "module fixture/member\n\ngo 1.26\n\nrequire (\n\t" + sdk + " v0.0.0-00010101000000-" + zeroShort + "\n)\n"
@@ -314,6 +314,7 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
packages map[string]any
download string // what go mod download -json answers
want string // the version asked of go
refused bool // the step fails, naming the path: the ask carries no pin for it (H-A-192)
head bool // the asked commit is on no trunk: only a pull request head carries it
// replaced: the directory's go.mod names no mesh package; a module it replaces by a directory of the tree requires
// it at the zero version, so go mod download passes and only a shut-off package load would look it up (1966/AC178-1)
@@ -321,18 +322,14 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
}{
{name: "the ask names the package", packages: map[string]any{sdk: trunk}, want: sdk + "@" + trunk,
download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`},
{name: "the ask names another package of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk/other": trunk}, want: sdk + "@" + trunk,
download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`},
{name: "the ask names the root of its repository, which no package of is published", packages: map[string]any{"git.novox.be/novox/mesh-sdk": trunk}, want: sdk + "@" + trunk,
download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`},
{name: "the ask pins only another package of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk/other": trunk}, refused: true},
{name: "the ask pins only the root of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk": trunk}, refused: true},
{name: "the ask names the head of a pull request", packages: map[string]any{sdk: commitSHA}, want: sdk + "@" + commitSHA, head: true},
{name: "the ask names nothing of its repository", packages: map[string]any{"git.novox.be/novox/mesh-tools/go": trunk}, want: sdk + "@latest",
download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`},
{name: "no ask", want: sdk + "@latest", download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`},
{name: "the ask names nothing of its repository", packages: map[string]any{"git.novox.be/novox/mesh-tools/go": trunk}, refused: true},
{name: "no ask", refused: true},
{name: "named only by a module the directory replaces, the ask names it", packages: map[string]any{sdk: trunk}, want: sdk + "@" + trunk, replaced: true,
download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`},
{name: "named only by a module the directory replaces, no ask", want: sdk + "@latest", replaced: true,
download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`},
{name: "named only by a module the directory replaces, no ask", replaced: true, refused: true},
} {
t.Run(c.name, func(t *testing.T) {
gomod := zeroMod
@@ -375,6 +372,15 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
t.Fatal(err)
}
st := states.waitEnd(t)
if c.refused {
if st.State == sdkstep.StepPassed || !strings.Contains(st.Reason, "no pin for "+sdk) {
t.Fatalf("the step ended %s (%s), want it failed naming no pin for %s", st.State, st.Reason, sdk)
}
if h.ran(" mod download -json " + sdk + "@") {
t.Errorf("go was asked for a version of %s with no pin:\n%s", sdk, strings.Join(h.f.lines(), "\n"))
}
return
}
if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
}
+1
View File
@@ -291,6 +291,7 @@
}
],
"packages": {
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks": "0.3",
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg": "0.1"
},
"invokes": [