Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/narrow_test.go
T
jschoubben f4cd0e89fd mesh-build-node-narrowed-packages: narrow a step's workspace as H-A-136 and H-A-137 say
Review round 1. The node build module runs the seat generator's check at its unit level
(steprun.OutOfStep), so its narrowed workspace keeps what H-A-136 and H-A-137 name: every
generated-from directory of the module, and for a root module the seats/ directory and the
paths of every artifact naming generated-from. Narrowed bare, a step of one mesh-contracts
package named the generated files left out as out of step. The fetch and the steps verb now
narrow the same way, and the steps verb reads its narrowed tree as the levels do.

narrowTree and generatedFromDirs are copied from mesh-build-go without its Go part, not moved
into mesh-delivery-sdk's steprun: the move is a change to two more repositories and a group
delivery for some sixty lines, in a fix that unblocks the build steps now; the copy says so.
packageDir and narrowedAway share one path helper.

Builds: design 47 H H-A-136, H-A-137 (hq design/47-H1-answers-59), ADR 0499 clause 4
2026-11-20 16:10:08 +01:00

75 lines
3.1 KiB
Go

package main
import (
"os"
"path/filepath"
"strings"
"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"
)
// A root contracts module (mesh-contracts at 87eab81, pipeline main.3 of 2026-11-20): two seats, each generated as a Go
// and a TypeScript package naming generated-from ".", in step with the seat generator, beside what no step reads.
func rootContracts(t *testing.T) string {
t.Helper()
tree := t.TempDir()
put := func(p, body string) {
write(t, filepath.Join(tree, filepath.FromSlash(p)), body, 0o644)
}
var arts []string
for _, s := range []string{"one-store", "two-store"} {
put("seats/"+s+"/seat.json", `{"format":1,"seat":"`+s+`","scope":"mesh","grain":"whole","domain":"Module","decision":"ADR 1","verbs":[{"name":"query","input":{"type":"object"},"answer":{"type":"object"}}]}`)
pkg := strings.ReplaceAll(s, "-", "")
arts = append(arts,
`{"name":"go-`+pkg+`","kind":"package","language":"go","paths":["go/seats/`+pkg+`"],"generated-from":"."}`,
`{"name":"ts-`+pkg+`","kind":"package","language":"typescript","paths":["ts/seats/`+pkg+`"],"generated-from":"."}`)
}
put("module.json", `{"module":"c","version":"0.1","build":{"artifacts":[`+strings.Join(arts, ",")+`]}}`)
put("README.md", "the repository\n")
g, err := seatgen.Load(tree, "example.org/c/go", "@example/c")
if err != nil {
t.Fatal(err)
}
files, err := seatgen.Generate(g)
if err != nil {
t.Fatal(err)
}
for p, body := range files {
put(p, string(body))
}
return tree
}
// Design 47 H, H-A-136 and H-A-137: a step's workspace of one package of a root module keeps, beside the package's path
// and module.json, the seats/ directory and the paths of every artifact naming generated-from, so the unit level's
// generator check finds nothing out of step; nothing else is kept. Narrowed bare (steprun.Narrow), the check names the
// generated files left out.
func TestANarrowedRootContractsModuleIsInStepWithTheGenerator(t *testing.T) {
req := sdkstep.FetchRequest{Repository: "novox/c", Commit: commitSHA, Dir: ".", Paths: []string{"ts/seats/onestore"}}
bare := rootContracts(t)
if err := steprun.Narrow(bare, req); err != nil {
t.Fatal(err)
}
if out, err := steprun.OutOfStep(bare, steprun.GeneratedRootTS); err != nil || len(out) == 0 {
t.Fatalf("narrowed bare: out of step %v (%v), want the left-out packages named", out, err)
}
tree := rootContracts(t)
if err := narrowTree(tree, req); err != nil {
t.Fatal(err)
}
if out, err := steprun.OutOfStep(tree, steprun.GeneratedRootTS); err != nil || len(out) != 0 {
t.Errorf("narrowed: out of step %v (%v), want none", out, err)
}
for _, kept := range []string{"module.json", "seats/two-store/seat.json", "ts/seats/twostore/package.json", "go/seats/twostore/go.mod"} {
if _, err := os.Stat(filepath.Join(tree, filepath.FromSlash(kept))); err != nil {
t.Errorf("%s is not kept: %v", kept, err)
}
}
if _, err := os.Stat(filepath.Join(tree, "README.md")); err == nil {
t.Error("README.md is still in the workspace")
}
}