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:
@@ -1,12 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// blueman's shape (novox/hq ADR 0208, ADR 0210): one official package, no seat, the X display on its
|
||||
@@ -14,40 +15,16 @@ import (
|
||||
// bluetooth module's (bluez, its utilities, its daemon), and the Go bundle serving exactly the listed
|
||||
// blueman_ 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 []any `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 TestItInstallsTheAppletAndNothingElse(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 TestItInstallsTheAppletAndNothingElse(t *testing.T) {
|
||||
m, _ := readManifest(t)
|
||||
if m.Module != "blueman" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) ||
|
||||
!reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
|
||||
t.Fatalf("%+v", m)
|
||||
@@ -55,13 +32,22 @@ func TestItInstallsTheAppletAndNothingElse(t *testing.T) {
|
||||
if len(m.Resources) != 1 || m.Resources[0]["type"] != "package" || m.Resources[0]["package"] != packageFor {
|
||||
t.Fatalf("resources: %v", m.Resources)
|
||||
}
|
||||
if m.Claims != nil || m.Seats != nil || m.Environment != nil {
|
||||
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil {
|
||||
t.Fatal("it holds no seat and sets no environment")
|
||||
}
|
||||
}
|
||||
|
||||
func TestItAddsNoSecondStartAndDeclaresNothingOfTheBluetoothModule(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)
|
||||
// The package ships its XDG autostart entry, which the session's dex runs: an xinitrc slot or a
|
||||
// window-manager exec would start it twice.
|
||||
if m.Shell != nil || m.Contributions != nil {
|
||||
@@ -75,7 +61,16 @@ func TestItAddsNoSecondStartAndDeclaresNothingOfTheBluetoothModule(t *testing.T)
|
||||
}
|
||||
|
||||
func TestTheToolsAgreeWithTheManifest(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)
|
||||
served := map[string]bool{}
|
||||
for _, tool := range tools() {
|
||||
served[tool.Name] = true
|
||||
@@ -96,8 +91,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/blueman-tools" || b["binary"] != "blueman-tools" {
|
||||
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
|
||||
b.From != "cmd/blueman-tools" || b.Binary != "blueman-tools" {
|
||||
t.Errorf("the Go tools bundle: %v", b)
|
||||
}
|
||||
s := strings.ToLower(raw)
|
||||
|
||||
Reference in New Issue
Block a user