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,81 +1,15 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// The module's manifest, read the way the catalogue reads it, for the manifest tests. The same in
// every desktop module that carries it.
type manifest struct {
Module string `json:"module"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Requires []string `json:"requires"`
Claims []claim `json:"claims"`
Seats []any `json:"seats"`
Tools []string `json:"tools"`
Config map[string]config `json:"config"`
Environment *environment `json:"environment"`
Shell []shellCode `json:"shell"`
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
// config is one config value as the definition declares it (novox/hq ADR 0348 §4).
type config struct {
Type string `json:"type"`
Description string `json:"description"`
Enum []any `json:"enum"`
Minimum *float64 `json:"minimum"`
Maximum *float64 `json:"maximum"`
Pattern string `json:"pattern"`
Trusted bool `json:"trusted"`
Predefined string `json:"predefined"`
Default any `json:"default"`
Required bool `json:"required"`
Runtime bool `json:"runtime"`
}
type claim struct {
Name string `json:"name"`
Scope string `json:"scope"`
Serves []string `json:"serves"`
}
type environment struct {
Variables map[string]string `json:"variables"`
Path []map[string]any `json:"path"`
}
type shellCode struct {
For string `json:"for"`
Slot string `json:"slot"`
Code string `json:"code"`
}
func readManifest(t *testing.T) manifest {
t.Helper()
raw, 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 {
t.Fatalf("module.json: %v", err)
}
return m
}
func (m manifest) resource(t *testing.T, id string) map[string]any {
func resource(t *testing.T, m catalogue.Manifest, id string) map[string]any {
t.Helper()
for _, r := range m.Resources {
if r["id"] == id {
@@ -86,7 +20,7 @@ func (m manifest) resource(t *testing.T, id string) map[string]any {
return nil
}
func (m manifest) packages() (present, absent []string) {
func packages(m catalogue.Manifest) (present, absent []string) {
for _, r := range m.Resources {
if r["type"] == "package" {
if r["absent"] == true {
@@ -102,9 +36,9 @@ func (m manifest) packages() (present, absent []string) {
// fromTemplate checks that a file resource takes its text from its template file in the module's
// repository (novox/hq ADR 0349 §2): it names the template, carries no text of its own beside it, and the
// template is there. The readable file in the repository is the one place the machine's text is written.
func (m manifest) fromTemplate(t *testing.T, id, template string) {
func fromTemplate(t *testing.T, m catalogue.Manifest, id, template string) {
t.Helper()
r := m.resource(t, id)
r := resource(t, m, id)
if r["type"] != "file" {
t.Fatalf("%s is a %v, not a file", id, r["type"])
}
@@ -124,7 +58,7 @@ func (m manifest) fromTemplate(t *testing.T, id, template string) {
// everyFileIsATemplate checks that no file resource carries its text inline, and that the build packs
// files/ into the one archive the controller reads the templates back from (novox/hq ADR 0349 §2).
func (m manifest) everyFileIsATemplate(t *testing.T) {
func everyFileIsATemplate(t *testing.T, m catalogue.Manifest) {
t.Helper()
for _, r := range m.Resources {
if _, inline := r["content"]; inline {
@@ -133,10 +67,10 @@ func (m manifest) everyFileIsATemplate(t *testing.T) {
}
packs := 0
for _, a := range m.Build.Artifacts {
if a["kind"] == "archive" && a["from"] == "files" {
if a.Kind == "archive" && a.From == "files" {
packs++
if a["name"] != "files" {
t.Errorf("the templates archive is named %v, not files", a["name"])
if a.Name != "files" {
t.Errorf("the templates archive is named %v, not files", a.Name)
}
}
}
@@ -146,9 +80,9 @@ func (m manifest) everyFileIsATemplate(t *testing.T) {
}
// text is the text a file resource places on the machine: its template file's.
func (m manifest) text(t *testing.T, id string) string {
func templateText(t *testing.T, m catalogue.Manifest, id string) string {
t.Helper()
name, _ := m.resource(t, id)["template"].(string)
name, _ := resource(t, m, id)["template"].(string)
if name == "" {
t.Fatalf("resource %s names no template", id)
}
@@ -161,7 +95,7 @@ func (m manifest) text(t *testing.T, id string) string {
// checkTheToolsAgree checks that the manifest lists the module's own tools exactly, that the bundle
// serves each seat verb the claims promise as <seat>.<verb>, and that the Go bundle is declared.
func checkTheToolsAgree(t *testing.T, m manifest) {
func checkTheToolsAgree(t *testing.T, m catalogue.Manifest) {
t.Helper()
own, seat := map[string]bool{}, map[string]bool{}
for _, tool := range tools() {
@@ -203,14 +137,14 @@ func checkTheToolsAgree(t *testing.T, m manifest) {
t.Errorf("the bundle serves %s, which no claim promises", name)
}
}
var bundle map[string]any
var bundle *catalogue.Artifact
for _, a := range m.Build.Artifacts {
if a["kind"] == "bundle" {
bundle = a
if a.Kind == "bundle" {
bundle = &a
}
}
if bundle == nil || bundle["language"] != "go" || bundle["system"] != "arch" ||
bundle["from"] != "cmd/"+m.Module+"-tools" || bundle["binary"] != m.Module+"-tools" {
if bundle == nil || bundle.Language != "go" || bundle.System != "arch" ||
bundle.From != "cmd/"+m.Module+"-tools" || bundle.Binary != m.Module+"-tools" {
t.Errorf("the Go tools bundle: %v", bundle)
}
}
+70 -17
View File
@@ -1,9 +1,13 @@
package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// picom's shape (novox/hq ADR 0208): it claims node-compositor and serves no verb of it, requires the
@@ -11,34 +15,58 @@ import (
// XDG autostart entry, never by the window manager or the session's start as well.
func TestItClaimsTheCompositorSeatAndRequiresTheXDisplay(t *testing.T) {
m := readManifest(t)
if m.Module != "picom" || m.Seats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.Seats)
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(m.Claims, []claim{{Name: "node-compositor", Scope: "node"}}) {
// 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)
}
if m.Module != "picom" || m.DefinesSeats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
}
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-compositor", Scope: "node"}}) {
t.Fatalf("claims: %+v", m.Claims)
}
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
t.Fatalf("requires: %v", m.Requires)
}
if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil {
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestItOwnsItsConfigurationAsWrittenInTheModule(t *testing.T) {
m := readManifest(t)
m.fromTemplate(t, "configuration", "files/picom.conf")
if p := m.resource(t, "configuration")["path"]; p != "${machine:account-home}/.config/picom/picom.conf" {
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)
}
fromTemplate(t, m, "configuration", "files/picom.conf")
if p := resource(t, m, "configuration")["path"]; p != "${machine:account-home}/.config/picom/picom.conf" {
t.Fatalf("path: %v", p)
}
if d := m.resource(t, "configuration-dir"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/picom" {
if d := resource(t, m, "configuration-dir"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/picom" {
t.Fatalf("the directory: %v", d)
}
}
func TestThePackagesAutostartEntryIsItsOnlyStart(t *testing.T) {
m := 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)
}
// picom's package ships /etc/xdg/autostart/picom.desktop, which the session's dex runs. A second
// start from here would be a second compositor, refused by the first.
if m.Shell != nil {
@@ -55,7 +83,15 @@ func TestThePackagesAutostartEntryIsItsOnlyStart(t *testing.T) {
}
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
m := 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)
}
checkTheToolsAgree(t, m)
checkNoSecretsOrInstallationNames(t)
}
@@ -66,14 +102,22 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
// (novox/hq ADR 0348 §4): the backend a string of picom's backends, damage tracking a boolean, both trusted
// as the file is.
func TestTheBackendAndDamageTrackingAreConfigValuesWithTodaysDefaults(t *testing.T) {
m := readManifest(t)
b, d := m.Config["backend"], m.Config["use-damage"]
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)
}
b, d := m.Settings["backend"], m.Settings["use-damage"]
if b.Type != "string" || b.Default != "glx" || b.Description == "" || !b.Trusted || len(b.Enum) == 0 ||
d.Type != "boolean" || d.Default != true || d.Description == "" || !d.Trusted {
t.Fatalf("config: %+v", m.Config)
t.Fatalf("config: %+v", m.Settings)
}
r := m.resource(t, "configuration")
c := m.text(t, "configuration")
r := resource(t, m, "configuration")
c := templateText(t, m, "configuration")
for _, want := range []string{`backend = "${config:backend}";`, "use-damage = ${config:use-damage};"} {
if !strings.Contains(c, want) {
t.Errorf("the file asks for %q", want)
@@ -98,5 +142,14 @@ func withDefaults(c string) string {
// No file resource carries its text inline (novox/hq ADR 0349 §2).
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
readManifest(t).everyFileIsATemplate(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)
}
everyFileIsATemplate(t, m)
}