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
@@ -1,12 +1,13 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// openrazer's shape (novox/hq ADR 0207, ADR 0208, ADR 0210): the three official packages of the
@@ -14,44 +15,17 @@ import (
// its own (D-Bus activation through the package's unit is the one start), nothing of the tray's (the
// polychromatic module's), and the Go bundle serving exactly the listed openrazer_ tools.
type manifest struct {
Module string `json:"module"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Requires []string `json:"requires"`
Tools []string `json:"tools"`
Resources []map[string]any `json:"resources"`
Claims []any `json:"claims"`
Seats []any `json:"seats"`
Shell []any `json:"shell"`
Contributions []struct {
Seat string `json:"seat"`
Kind string `json:"kind"`
Content string `json:"content"`
} `json:"contributions"`
Environment any `json:"environment"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
func readManifest(t *testing.T) (manifest, string) {
t.Helper()
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
dec := json.NewDecoder(strings.NewReader(string(raw)))
dec.DisallowUnknownFields()
var m manifest
if err := dec.Decode(&m); err != nil {
// 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)
}
return m, string(raw)
}
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
served := map[string]bool{}
for _, tool := range tools() {
served[tool.Name] = true
@@ -72,8 +46,8 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
t.Fatalf("%v", m.Build.Artifacts)
}
b := m.Build.Artifacts[0]
if b["kind"] != "bundle" || b["language"] != "go" || b["system"] != "arch" ||
b["from"] != "cmd/openrazer-tools" || b["binary"] != "openrazer-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/openrazer-tools" || b.Binary != "openrazer-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -85,7 +59,16 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
}
func TestItInstallsTheStackAndStartsNothing(t *testing.T) {
m, raw := readManifest(t)
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "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)
}
raw := string(manifestJSON)
if m.Module != "openrazer" || m.Requires != nil || !reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
t.Fatalf("%+v", m)
}
@@ -114,7 +97,7 @@ func TestItInstallsTheStackAndStartsNothing(t *testing.T) {
if len(accounts) != 1 || !reflect.DeepEqual(accounts[0], want) {
t.Fatalf("the account: %v, want %v", accounts, want)
}
if m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
t.Fatal("it holds no seat, sets no environment and adds no start")
}
// The tray is polychromatic's, from outside the official repositories; the kernel headers DKMS