Files
mesh-catalog/modules/rofi/cmd/rofi-tools/manifest_test.go
T
jschoubben a3db292b8d 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
2026-11-22 21:32:03 +01:00

178 lines
6.1 KiB
Go

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
// `menu`, requires the X display on its own machine, owns its configuration and its two themes, and
// places the seat's dmenu-compatible command, its launcher and power menu, and its key bindings as
// its own i3 drop-in.
func TestItClaimsTheLauncherSeatServingMenuAndRequiresTheXDisplay(t *testing.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)
}
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 := packages(m); !reflect.DeepEqual(present, []string{"rofi"}) || absent != nil {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestItOwnsItsFilesAsWrittenInTheModule(t *testing.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",
"theme-powermenu": "files/themes/mesh-powermenu.rasi",
"dmenu": "files/bin/dmenu",
"launch": "files/bin/rofi-launch",
"powermenu": "files/bin/rofi-powermenu",
} {
fromTemplate(t, m, id, source)
}
for _, id := range []string{"dmenu", "launch", "powermenu"} {
if resource(t, m, id)["mode"] != "0755" {
t.Errorf("%s is executable", id)
}
}
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) {
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 := 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(templateText(t, m, "theme"), `"Inter 11"`) {
t.Error("the theme's prose is in the interface face")
}
}
func TestThePowerMenuNamesNoWindowManagerAndNoLocker(t *testing.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)
}
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)
}
}
for _, want := range []string{"loginctl lock-session", "loginctl terminate-session", "systemctl suspend", "systemctl reboot", "systemctl poweroff"} {
if !strings.Contains(menu, want) {
t.Errorf("the power menu lacks %s", want)
}
}
}
func TestTheKeyBindingsAreAnI3DropInRunningTheModulesOwnCommands(t *testing.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)
}
i3LinesAreSource(t, m, "files/i3/50-rofi.conf")
bindings := i3Lines(m)
for _, line := range strings.Split(bindings, "\n") {
if line == "" || strings.HasPrefix(line, "#") {
continue
}
if !strings.HasPrefix(line, "bindsym $mod+") || !strings.Contains(line, "exec --no-startup-id ~/.local/bin/rofi-") {
t.Errorf("a binding that is not the launcher's: %s", line)
}
}
for _, key := range []string{"$mod+d ", "$mod+Escape "} {
if !strings.Contains(bindings, "bindsym "+key) {
t.Errorf("no %s", key)
}
}
if m.Shell != nil {
t.Fatalf("the launcher starts nothing at session start: %+v", m.Shell)
}
}
func TestTheToolsAgreeWithTheManifest(t *testing.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) {
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)
}