The group's mesh-build-go requires go-package-registry, which the forge now provides; the stand-in listed the forge's offers by hand and missed it, so the test failed against the group's catalogue. It now takes them from the catalogue's gitea manifest, so a registry the forge gains needs no edit. Claude-Session: https://claude.ai/code/session_01JG73KG7AfSdh6FP8VrBqCn
78 lines
2.8 KiB
Go
78 lines
2.8 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()
|
|
// The stand-in offers by name what the catalogue's forge offers, so a registry the forge gains is offered
|
|
// here too and never has to be added by hand, plus the two it stands in for that the forge does not offer.
|
|
offers := []mcat.Offer{{Name: "artifact-store"}, {Name: "node-tools"}}
|
|
for _, o := range catalogueManifest(t, "gitea").Provides {
|
|
offers = append(offers, mcat.Offer{Name: o.Name})
|
|
}
|
|
m := map[string]mcat.Manifest{
|
|
"forge": {Module: "forge", Version: "1", Provides: offers},
|
|
}
|
|
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))
|
|
}
|
|
}
|
|
}
|