Read each module's own manifest through mesh-sdk's catalogue reader (H-A-498)

The fifteen desktop modules' tools tests failed on every manifest with
"json: unknown field class": a test helper copied into each module decoded
module.json into its own struct, refusing unknown fields. Manifest
strictness is the catalog check's alone, and the manifest's form is a
contract read through mesh-sdk's catalogue package, so the copied
`manifest` struct and its reader go from the fifteen desktop modules and
pacman; each test reads module.json with catalogue.Decode and asserts only
the module's own promises (claims, files, tools) on catalogue.Manifest.

Builds: design 47 H2 H-A-498, H-A-498 addendum
This commit is contained in:
2026-11-22 21:32:03 +01:00
parent bf972d1d34
commit a3db292b8d
31 changed files with 1205 additions and 1207 deletions
+19 -35
View File
@@ -1,39 +1,15 @@
package main
import (
"encoding/json"
"os"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
type resource map[string]any
type manifestShape struct {
Module string `json:"module"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Claims []map[string]any `json:"claims"`
Tools []string `json:"tools"`
Resources []resource `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
func manifest(t *testing.T) manifestShape {
t.Helper()
raw, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
}
var m manifestShape
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
return m
}
func (m manifestShape) resource(t *testing.T, id string) resource {
func resourceOf(t *testing.T, m catalogue.Manifest, id string) resource {
t.Helper()
for _, r := range m.Resources {
if r["id"] == id {
@@ -47,7 +23,15 @@ func (m manifestShape) resource(t *testing.T, id string) resource {
// TestToolsAreTheManifests holds the served tools and the manifest's list to one another, and the
// bundle to the shape the builder compiles and the runtime loads.
func TestToolsAreTheManifests(t *testing.T) {
m := manifest(t)
manifestJSON, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
}
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
m, err := catalogue.Decode(manifestJSON)
if err != nil {
t.Fatalf("module.json: %v", err)
}
names := map[string]bool{}
for _, tool := range tools(machine(nil, 1000)) {
if names[tool.Name] {
@@ -64,17 +48,17 @@ func TestToolsAreTheManifests(t *testing.T) {
if len(names) != 0 {
t.Errorf("served and not listed: %v", names)
}
var tools map[string]any
var tools *catalogue.Artifact
for _, a := range m.Build.Artifacts {
if a["name"] == "tools" {
tools = a
if a.Name == "tools" {
tools = &a
}
}
if tools == nil || tools["kind"] != "bundle" || tools["language"] != "go" || tools["system"] != "arch" ||
tools["from"] != "cmd/"+binaryName || tools["binary"] != binaryName {
if tools == nil || tools.Kind != "bundle" || tools.Language != "go" || tools.System != "arch" ||
tools.From != "cmd/"+binaryName || tools.Binary != binaryName {
t.Fatalf("the tools artifact: %v", tools)
}
if loads, _ := tools["loads"].([]any); len(loads) != 1 || loads[0] != binaryName {
t.Fatalf("loads: %v", tools["loads"])
if len(tools.Loads) != 1 || tools.Loads[0] != binaryName {
t.Fatalf("loads: %v", tools.Loads)
}
}