Files
mesh-host/internal/compose/resolution/toolchain_manifests_test.go
T
jschoubben d68e241724 Take the catalogue's composition rules into the node-engine
ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk
carries no composition rule. The catalogue functions only the
node-engine's composition reaches (Resolve, Resolution's Compose,
Declaration, DataItems, LeftOut, Rules and the rest, the settings,
placeholder and template refusals, the rendering helpers) are copied
with their tests into internal/compose/resolution; a method of a
mesh-sdk shape becomes a function taking it first. The composition
calls its own copies, and the captured catalogue its tests read lives
here now, shared by mesh-compose's tests.

Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
2026-11-02 19:15:55 +01:00

72 lines
2.5 KiB
Go

package resolution
import (
"strings"
"testing"
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
)
// builderNode is a machine that can run a build module: the package manager and user namespaces it asks of
// the machine, and the forge account (mesh-scope, provided by the forge) and the artifact store the build
// modules publish to (ADR 0513, provided by distribution) stood in for, and node-tools, the tool runner they pull their
// asks through (mesh-catalog issue 1911; mesh-tools' module, not in the catalogue).
func builderNode() mcat.Node {
return mcat.Node{Name: "builder", Site: "house",
Capabilities: map[string]bool{"package-manager": true, "user-namespaces": true}}
}
func toolchainShelf(t *testing.T) map[string]mcat.Manifest {
t.Helper()
m := map[string]mcat.Manifest{
"forge": {Module: "forge", Version: "1", Provides: []mcat.Offer{{Name: "forge-account"}, {Name: "npm-package-registry"}, {Name: "artifact-store"}, {Name: "node-tools"}}},
}
for _, name := range []string{"go", "nodejs", "mesh-build-go", "mesh-build-node", "dev-tools"} {
m[name] = catalogueManifest(t, name)
}
return m
}
func TestAModuleNeedingAToolchainIsRefusedOnANodeWithoutIt(t *testing.T) {
for _, c := range []struct{ module, provision string }{
{"mesh-build-go", "go-toolchain"},
{"mesh-build-node", "node-toolchain"},
{"dev-tools", "go-toolchain"},
} {
_, err := Resolve(toolchainShelf(t), []string{"forge", c.module}, builderNode(), mcat.World{})
if err == nil {
t.Fatalf("%s composed on a node with no toolchain module", c.module)
}
for _, want := range []string{`"` + c.provision + `" is wanted by ` + c.module,
"usable only on the machine that provides it"} {
if !strings.Contains(err.Error(), want) {
t.Errorf("%s: the refusal does not say %q:\n%v", c.module, want, err)
}
}
}
}
func TestAModuleNeedingAToolchainComposesOnANodeWithIt(t *testing.T) {
for _, c := range []struct{ module, owner string }{
{"mesh-build-go", "go"},
{"mesh-build-node", "nodejs"},
{"dev-tools", "go"},
} {
assigned := []string{"forge", c.owner, c.module}
if c.module == "dev-tools" {
assigned = append(assigned, "nodejs")
}
got, err := Resolve(toolchainShelf(t), assigned, builderNode(), mcat.World{})
if err != nil {
t.Fatalf("%s with %s did not compose: %v", c.module, c.owner, err)
}
in := map[string]bool{}
for _, n := range names(got) {
in[n] = true
}
if !in[c.module] || !in[c.owner] {
t.Errorf("%s with %s composed %v", c.module, c.owner, names(got))
}
}
}