mesh-build-go: a narrowed root module keeps its seats/ and every generated package

A module at the repository's root naming generated-from "." (mesh-contracts)
kept nothing of it: the narrowing kept "." alone, which prunes everything,
so the seat generator's check of go-meshconfig still found every file out
of step. Such a module now keeps the seats/ directory the generator reads
and the paths of every artifact naming generated-from; nothing else of the
root.

Builds: design 47 H H-A-137
This commit is contained in:
2026-11-20 13:03:05 +01:00
parent c52907a346
commit 30f274bcb0
2 changed files with 78 additions and 6 deletions
@@ -73,6 +73,9 @@ func narrowTree(tree, repository string, req sdkstep.FetchRequest) error {
// under answers p's path relative to dir when p is dir or lies under it.
func under(dir, p string) (string, bool) {
if dir == "." {
return p, true
}
if p == dir {
return ".", true
}
@@ -83,8 +86,11 @@ func under(dir, p string) (string, bool) {
}
// generatedFromDirs are the generated-from directories (from the tree's root) the artifacts of the module in dir name
// (H-A-136): the seat definitions a generated package is compared against. A manifest that is absent or unreadable names
// none; the steps that read it say so.
// (H-A-136): the seat definitions a generated package is compared against. A module at the repository's root keeps not
// its generated-from directory, which would be the whole repository, but the generator's inputs and outputs: the seats/
// directory of each generated-from directory and the paths of every artifact of the module naming generated-from, as
// the generator's check reads every generated package (H-A-137). A manifest that is absent or unreadable names none;
// the steps that read it say so.
func generatedFromDirs(tree, dir string) []string {
raw, err := os.ReadFile(filepath.Join(tree, filepath.FromSlash(dir), "module.json"))
if err != nil {
@@ -95,11 +101,26 @@ func generatedFromDirs(tree, dir string) []string {
return nil
}
var out []string
add := func(p string) {
if p == ".." || strings.HasPrefix(p, "../") || slices.Contains(out, p) {
return
}
if _, err := os.Lstat(filepath.Join(tree, filepath.FromSlash(p))); err == nil { // steprun.Narrow refuses a path the tree lacks
out = append(out, p)
}
}
for _, a := range man.Build.Artifacts {
if g := strings.TrimSpace(a.GeneratedFrom); g != "" {
if p := path.Join(dir, filepath.ToSlash(g)); p != ".." && !strings.HasPrefix(p, "../") && !slices.Contains(out, p) {
out = append(out, p)
}
g := strings.TrimSpace(a.GeneratedFrom)
if g == "" {
continue
}
if dir != "." {
add(path.Join(dir, filepath.ToSlash(g)))
continue
}
add(path.Join(filepath.ToSlash(g), "seats"))
for _, p := range a.Paths {
add(path.Clean(filepath.ToSlash(p)))
}
}
return out
@@ -8,8 +8,20 @@ import (
"testing"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/seatgen"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
)
func writeFile(t *testing.T, file, body string) {
t.Helper()
if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(file, []byte(body), 0o644); err != nil {
t.Fatal(err)
}
}
// Design 47 H, lead answer H-A-136 (live 2026-11-20, the first pipeline main.3): a workspace narrowed to an artifact's
// named paths also holds every generated-from directory an artifact of its module names (the seat definitions the
// generated package is compared against) and the directory, with its go.mod, of every package of the same repository the
@@ -24,6 +36,7 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
files map[string]string
kept, gone []string
modules []string
seats []string // generated into the tree by the seat generator, its out-of-step check then finding nothing
}{
{name: "a generated-from directory", dir: "modules/c", paths: []string{"go/seats/a"},
files: map[string]string{
@@ -48,6 +61,18 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
kept: []string{"modules/c/seats/a.json", "modules/c/go/seats/b/go.mod"},
gone: []string{"modules/d"},
modules: []string{"modules/c/go/seats/a"}},
{name: "a module at the repository's root with generated-from \".\"", dir: ".", paths: []string{"go/seats/onestore"},
files: map[string]string{
"module.json": `{"module":"mesh-contracts","build":{"artifacts":[{"name":"go-onestore","kind":"package","language":"go","paths":["go/seats/onestore"],"generated-from":"."},{"name":"go-twostore","kind":"package","language":"go","paths":["go/seats/twostore"],"generated-from":"."},{"name":"ts-onestore","kind":"package","language":"typescript","paths":["ts/seats/onestore"],"generated-from":"."},{"name":"ts-twostore","kind":"package","language":"typescript","paths":["ts/seats/twostore"],"generated-from":"."},{"name":"go-other","kind":"package","language":"go","paths":["go/other"]}]}}`,
"README.md": "the repository\n",
"docs/a.md": "not named\n",
"go/other/go.mod": "module git.novox.be/novox/mesh-contracts/go/other\n\ngo 1.26\n",
"modules/x/module.json": `{"module":"x"}`,
},
seats: []string{"one-store", "two-store"},
kept: []string{"module.json", "seats/one-store/seat.json", "seats/two-store/seat.json", "go/seats/onestore/go.mod", "go/seats/twostore/contract.go", "ts/seats/twostore/package.json"},
gone: []string{"README.md", "docs", "go/other", "modules"},
modules: []string{"go/seats/onestore"}},
{name: "a package of the same repository at the zero version", dir: "modules/mesh-delivery-contracts",
paths: []string{"go/clients/meshcatalogclient"},
files: map[string]string{
@@ -80,6 +105,25 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
all = append(all, filepath.Dir(f))
}
}
if len(tc.seats) > 0 {
for _, seat := range tc.seats {
writeFile(t, filepath.Join(tree, "seats", seat, "seat.json"), `{"format":1,"seat":"`+seat+`","scope":"mesh","grain":"whole","domain":"Module","decision":"ADR 1","verbs":[{"name":"query","input":{"type":"object"},"answer":{"type":"object"}}]}`)
}
g, err := seatgen.Load(tree, "git.novox.be/novox/mesh-contracts/go", "@novox/mesh-contracts")
if err != nil {
t.Fatal(err)
}
files, err := seatgen.Generate(g)
if err != nil {
t.Fatal(err)
}
for f, b := range files {
writeFile(t, filepath.Join(tree, f), string(b))
if filepath.Base(f) == "go.mod" {
all = append(all, filepath.Dir(f))
}
}
}
req := sdkstep.FetchRequest{Repository: "novox/mesh-delivery", Commit: commitSHA, Dir: tc.dir, Paths: tc.paths}
if err := narrowTree(tree, req.Repository, req); err != nil {
t.Fatal(err)
@@ -94,6 +138,13 @@ func TestANarrowedWorkspaceHoldsTheGeneratedFromDirectoriesAndItsRepositorysZero
t.Errorf("%s is still in the workspace", g)
}
}
if len(tc.seats) > 0 {
for _, root := range []string{steprun.GeneratedRootGo, steprun.GeneratedRootTS} {
if out, err := steprun.OutOfStep(filepath.Join(tree, tc.dir), root); err != nil || len(out) != 0 {
t.Errorf("the seat generator's check in the narrowed workspace, root %s: %v %v, want nothing out of step", root, out, err)
}
}
}
var left []string
for _, d := range all {
if _, err := os.Stat(filepath.Join(tree, d, "go.mod")); err == nil {