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,69 +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"`
|
||||
Moved bool `json:"moved"`
|
||||
Version string `json:"version"`
|
||||
Capabilities []string `json:"capabilities"`
|
||||
Requires []string `json:"requires"`
|
||||
Claims []claim `json:"claims"`
|
||||
Seats []any `json:"seats"`
|
||||
Tools []string `json:"tools"`
|
||||
Environment *environment `json:"environment"`
|
||||
Shell []shellCode `json:"shell"`
|
||||
Resources []map[string]any `json:"resources"`
|
||||
// Lines for other modules' seats (novox/hq ADR 0212): the window manager's, here.
|
||||
Items []item `json:"items"`
|
||||
Contributions []any `json:"contributions"`
|
||||
Build struct {
|
||||
Artifacts []map[string]any `json:"artifacts"`
|
||||
} `json:"build"`
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -74,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 {
|
||||
@@ -90,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"])
|
||||
}
|
||||
@@ -112,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 {
|
||||
@@ -121,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,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)
|
||||
}
|
||||
@@ -149,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() {
|
||||
@@ -191,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)
|
||||
}
|
||||
}
|
||||
@@ -223,7 +169,7 @@ const displaySession = "contribution:node-display-session:config"
|
||||
|
||||
// i3Lines is what the module contributes to the window manager: the text of its item of the collection
|
||||
// contribution:node-display-session:config (design 57 L3, issue 848).
|
||||
func (m manifest) i3Lines() string {
|
||||
func i3Lines(m catalogue.Manifest) string {
|
||||
var out string
|
||||
for _, it := range m.Items {
|
||||
if it.Collection == displaySession {
|
||||
@@ -239,7 +185,7 @@ func (m manifest) i3Lines() string {
|
||||
|
||||
// i3LinesAreSource checks the window-manager lines are one item whose template is the source file, and that no
|
||||
// old-form contribution to node-display-session is left.
|
||||
func (m manifest) i3LinesAreSource(t *testing.T, source string) {
|
||||
func i3LinesAreSource(t *testing.T, m catalogue.Manifest, source string) {
|
||||
t.Helper()
|
||||
if len(m.Contributions) != 0 {
|
||||
t.Fatalf("the module still holds contributions: the lines are an item of %s", displaySession)
|
||||
@@ -253,14 +199,7 @@ func (m manifest) i3LinesAreSource(t *testing.T, source string) {
|
||||
if len(templates) != 1 || templates[0] != source {
|
||||
t.Fatalf("the items of %s are %v, want the one template %s", displaySession, templates, source)
|
||||
}
|
||||
if m.i3Lines() == "" {
|
||||
if i3Lines(m) == "" {
|
||||
t.Fatalf("the template %s holds no line", source)
|
||||
}
|
||||
}
|
||||
|
||||
type item struct {
|
||||
Collection string `json:"collection"`
|
||||
Name string `json:"name"`
|
||||
Attributes map[string]string `json:"attributes"`
|
||||
Template string `json:"template"`
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// rofi's shape (novox/hq ADR 0208, research 026/04): it claims node-launcher and serves its verb
|
||||
@@ -12,23 +16,39 @@ import (
|
||||
// its own i3 drop-in.
|
||||
|
||||
func TestItClaimsTheLauncherSeatServingMenuAndRequiresTheXDisplay(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
if m.Module != "rofi" || 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-launcher", Scope: "node", Serves: []string{"menu", "secret"}}}) {
|
||||
// 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 != "rofi" || m.DefinesSeats != nil {
|
||||
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
|
||||
}
|
||||
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-launcher", Scope: "node", Serves: []string{"menu", "secret"}}}) {
|
||||
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{"rofi"}) || absent != nil {
|
||||
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"rofi"}) || absent != nil {
|
||||
t.Fatalf("packages: %v, absent %v", present, absent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestItOwnsItsFilesAsWrittenInTheModule(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)
|
||||
}
|
||||
for id, source := range map[string]string{
|
||||
"configuration": "files/config.rasi",
|
||||
"theme": "files/themes/mesh.rasi",
|
||||
@@ -37,39 +57,55 @@ func TestItOwnsItsFilesAsWrittenInTheModule(t *testing.T) {
|
||||
"launch": "files/bin/rofi-launch",
|
||||
"powermenu": "files/bin/rofi-powermenu",
|
||||
} {
|
||||
m.fromTemplate(t, id, source)
|
||||
fromTemplate(t, m, id, source)
|
||||
}
|
||||
for _, id := range []string{"dmenu", "launch", "powermenu"} {
|
||||
if m.resource(t, id)["mode"] != "0755" {
|
||||
if resource(t, m, id)["mode"] != "0755" {
|
||||
t.Errorf("%s is executable", id)
|
||||
}
|
||||
}
|
||||
if p := m.resource(t, "dmenu")["path"]; p != "${machine:account-home}/.local/bin/dmenu" {
|
||||
if p := resource(t, m, "dmenu")["path"]; p != "${machine:account-home}/.local/bin/dmenu" {
|
||||
t.Fatalf("the seat's command is dmenu on the account's PATH: %v", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheThemesAreTheMeshsFacesAndTheConfigurationNamesOne(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
conf := m.text(t, "configuration")
|
||||
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)
|
||||
}
|
||||
conf := templateText(t, m, "configuration")
|
||||
if !strings.Contains(conf, `@theme "mesh"`) || strings.Contains(conf, "@import") {
|
||||
t.Fatal("the configuration names the theme mesh and imports nothing")
|
||||
}
|
||||
for _, id := range []string{"theme", "theme-powermenu"} {
|
||||
c := m.text(t, id)
|
||||
c := templateText(t, m, id)
|
||||
if !strings.Contains(c, `"JetBrainsMono Nerd Font`) || strings.Contains(c, "@import") ||
|
||||
strings.Contains(c, "Hack") || strings.Contains(c, "Iosevka") {
|
||||
t.Errorf("%s: the monospace face, and no imported file", id)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(m.text(t, "theme"), `"Inter 11"`) {
|
||||
if !strings.Contains(templateText(t, m, "theme"), `"Inter 11"`) {
|
||||
t.Error("the theme's prose is in the interface face")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThePowerMenuNamesNoWindowManagerAndNoLocker(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
menu := m.text(t, "powermenu")
|
||||
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)
|
||||
}
|
||||
menu := templateText(t, m, "powermenu")
|
||||
for _, never := range []string{"i3-msg", "i3lock", "betterlockscreen", "openbox", "bspc", "qdbus", "mpc"} {
|
||||
if strings.Contains(menu, never) {
|
||||
t.Errorf("the power menu names %s", never)
|
||||
@@ -83,9 +119,17 @@ func TestThePowerMenuNamesNoWindowManagerAndNoLocker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTheKeyBindingsAreAnI3DropInRunningTheModulesOwnCommands(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
m.i3LinesAreSource(t, "files/i3/50-rofi.conf")
|
||||
bindings := m.i3Lines()
|
||||
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)
|
||||
}
|
||||
i3LinesAreSource(t, m, "files/i3/50-rofi.conf")
|
||||
bindings := i3Lines(m)
|
||||
for _, line := range strings.Split(bindings, "\n") {
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
@@ -105,12 +149,29 @@ func TestTheKeyBindingsAreAnI3DropInRunningTheModulesOwnCommands(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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user