mesh-build-go: the compose ask's test builds a stand-in composer from its own testdata, reading no other repository

A pipeline's test step places no repository beside the tree and a module's tests read nothing outside their module (lead answer
A-474), so the test no longer needs MESH_CHECK_BESIDE or the node-engine's tree: it fetches a small program of the composer's
contract (testdata/composer) and still proves the build once, the kept composer on the second ask, and the verdict by case.

Builds: design 47 G lead answer A-474 (principles 10 and 9)
This commit is contained in:
2026-11-17 15:31:00 +01:00
parent 9ed13cd9dc
commit 84106a9338
3 changed files with 54 additions and 85 deletions
@@ -24,70 +24,7 @@ import (
"git.novox.be/novox/mesh-sdk/go/testbus"
)
// nodeEngineTree is the node-engine's repository as the checker places it beside this check (MESH_CHECK_BESIDE, the
// repository mesh-host), and with it every Go module of the other repositories placed there (mesh-sdk, mesh-contracts,
// mesh-delivery, mesh-networking, the catalogue's trunk) and of the catalogue under check, first, as candidates: the workspace lays those the
// node-engine's composer requires at the zero version, transitively (workspaceOf), so they resolve as the group lays
// them, wherever the composer lives. The test
// builds the node-engine's real composer command from that tree; it does not stand one in. With no beside directory it
// fails, and with the node-engine beside but no composer command in it it fails: a composer test that could not build its
// composer proves nothing. With a beside directory that holds no node-engine at all it skips aloud (NOT JUDGED), since a
// checker from before this release places none for the catalogue.
func nodeEngineTree(t *testing.T) (tree string, modules []string) {
t.Helper()
beside := os.Getenv("MESH_CHECK_BESIDE")
if beside == "" {
t.Fatal("NOT CHECKED: MESH_CHECK_BESIDE is not set, so the node-engine's repository (mesh-host) is not beside this check")
}
tree = filepath.Join(beside, "mesh-host")
if !dirExists(tree) {
// A checker from before novox/hq ADR 0593 places only mesh-sdk beside a catalogue check, so the node-engine's
// repository is absent, not wrong: said aloud, since nothing here could build a composer to judge.
t.Skipf("NOT JUDGED: the node-engine's repository (mesh-host) is not beside this check in MESH_CHECK_BESIDE=%s; the running checker places none for the catalogue, so the composer is judged only once it does", beside)
}
if _, err := os.Stat(filepath.Join(tree, "cmd", "mesh-compose")); err != nil {
t.Fatalf("NOT CHECKED: the node-engine's composer command is not beside this check in MESH_CHECK_BESIDE=%s: %v", beside, err)
}
entries, err := os.ReadDir(beside)
if err != nil {
t.Fatal(err)
}
var roots []string
for _, e := range entries {
if e.Name() == "mesh-host" || !dirExists(filepath.Join(beside, e.Name())) {
continue
}
root, err := filepath.EvalSymlinks(filepath.Join(beside, e.Name()))
if err != nil {
t.Fatal(err)
}
roots = append(roots, root)
}
// The catalogue under check, first: beside lies its trunk (issue 1295), whose modules a head's must win over.
catalogue, err := filepath.Abs(filepath.Join("..", "..", "..", ".."))
if err != nil {
t.Fatal(err)
}
for _, root := range append([]string{catalogue}, roots...) {
filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
if d.IsDir() && (d.Name() == ".git" || d.Name() == "testdata" || d.Name() == "node_modules") {
return filepath.SkipDir
}
if !d.IsDir() && d.Name() == "go.mod" {
modules = append(modules, filepath.Dir(p))
}
return nil
})
}
return tree, modules
}
func dirExists(p string) bool { st, err := os.Stat(p); return err == nil && st.IsDir() }
// copyTree copies the files of a source tree into dst, leaving out its .git.
// copyHostTree copies the files of a source tree into dst, leaving out its .git.
func copyHostTree(t *testing.T, src, dst string) {
t.Helper()
src, err := filepath.EvalSymlinks(src)
@@ -130,7 +67,7 @@ func goEnvOf(t *testing.T, name string) string {
}
// 1622/AC1, AC3 against the real bus (ADR 0593 §7, C9): a compose ask put on the Go build seat's check stream is pulled by
// the module started whole on that bus, which fetches the commit (the node-engine's repository beside the check, its Go module at the root), builds the composer command the ask names there with nothing fetched, fills the
// the module started whole on that bus, which fetches the commit (a stand-in composer of this module's testdata, its Go module at the root), builds the composer command the ask names there with nothing fetched, fills the
// request's manifests from the indexer's state and runs the composer; the step key <node>.<ask id> passes with the
// composer's verdict. A second ask of the same commit runs the kept composer: fetched and built once.
func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
@@ -157,14 +94,11 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
m.Run = StepRunner(t.TempDir())
m.GoModCache = goEnvOf(t, "GOMODCACHE") // the module cache this module's own build filled, read and not fetched
run, gocache := m.Run, goEnvOf(t, "GOCACHE") // this machine's build cache, so the composer's packages compile once
hostTree, beside := nodeEngineTree(t)
workFile := ""
// The composer is a stand-in of this module's own testdata (design 47 G A-474: a module's tests read nothing outside it, and a
// pipeline's step places no other repository beside the tree): a program of the composer's contract that imports nothing.
hostTree := filepath.Join("testdata", "composer")
m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
env = append(env, "GOCACHE="+gocache)
if workFile != "" {
env = append(env, "GOWORK="+workFile, "GOFLAGS=-mod=readonly") // a workspace takes no -mod=mod
}
return run(ctx, env, name, args...)
return run(ctx, append(env, "GOCACHE="+gocache), name, args...)
}
read, digests := catalogHolds(t, `{"module":"demo","version":"1"}`)
m.ReadEntry = read
@@ -181,18 +115,6 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
return nil, err
}
copyHostTree(t, hostTree, tree)
if len(beside) > 0 { // the group's other repositories, laid beside the node-engine's tree as one workspace
work, err := workspaceOf(tree, beside)
if err != nil {
return nil, err
}
if err := os.WriteFile(filepath.Join(m.Work, ws, "go.work"), []byte(work), 0o600); err != nil {
return nil, err
}
workFile = filepath.Join(m.Work, ws, "go.work")
// Nothing is downloaded here: this level has no network. The check's own fetch downloaded this workspace's
// graph (downloadBeside), and a module it lacks fails the build naming it.
}
return map[string]any{"workspace": ws}, nil
}
}
@@ -203,7 +125,7 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
ask := func() sdkstep.Step {
a := composeAskOf(t, digests[0])
a.Compose.Fetch.Repository, a.Compose.Dir, a.Compose.Package = "novox/mesh-host", catalogclient.RootPath, "github.com/novox/mesh-host/cmd/mesh-compose"
a.Compose.Fetch.Repository, a.Compose.Dir, a.Compose.Package = "novox/mesh-catalog", catalogclient.RootPath, "standin/cmd/mesh-compose"
raw, err := sdkstep.EncodeStepAsk(a)
if err != nil {
t.Fatal(err)
@@ -0,0 +1,44 @@
// Command mesh-compose is the stand-in composer the compose ask's test builds: a program of the contract the Go build module
// runs (`-request <file>`, the last line of its standard output a composer verdict of version 1), which judges nothing and
// answers each case of the request by its name, with no manifest and no machine. It imports nothing of the mesh.
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
)
func main() {
file := flag.String("request", "", "the request file")
flag.Parse()
raw, err := os.ReadFile(*file)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
var req struct {
Cases []struct {
Name string `json:"name"`
} `json:"cases"`
}
if err := json.Unmarshal(raw, &req); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
type verdict struct {
Name string `json:"name"`
Manifests map[string]any `json:"manifests"`
}
out := struct {
V int `json:"v"`
SDK string `json:"sdk"`
Cases []verdict `json:"cases"`
}{V: 1, SDK: "stand-in"}
for _, c := range req.Cases {
out.Cases = append(out.Cases, verdict{Name: c.Name, Manifests: map[string]any{}})
}
line, _ := json.Marshal(out)
fmt.Println(string(line))
}
@@ -0,0 +1,3 @@
module standin
go 1.26