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
156 lines
6.0 KiB
Go
156 lines
6.0 KiB
Go
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
|
|
// X display on its own machine, owns its configuration file, and is started once, by its package's
|
|
// XDG autostart entry, never by the window manager or the session's start as well.
|
|
|
|
func TestItClaimsTheCompositorSeatAndRequiresTheXDisplay(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 != "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 := packages(m); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil {
|
|
t.Fatalf("packages: %v, absent %v", present, absent)
|
|
}
|
|
}
|
|
|
|
func TestItOwnsItsConfigurationAsWrittenInTheModule(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)
|
|
}
|
|
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 := 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) {
|
|
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 {
|
|
t.Fatalf("a session-start line as well as the package's autostart entry: %+v", m.Shell)
|
|
}
|
|
for _, r := range m.Resources {
|
|
if p, _ := r["path"].(string); strings.Contains(p, "i3/config.d") || strings.Contains(p, "autostart") {
|
|
t.Fatalf("a second start: %v", r)
|
|
}
|
|
if r["type"] == "service" || r["type"] == "process" {
|
|
t.Fatalf("a unit: %v", r)
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
// The backend and damage tracking are each machine's (novox/hq research 037: the backend depends on the
|
|
// machine's graphics driver; issue 345: a window left unpainted under glx is the first suspect). Both
|
|
// are config values whose defaults are what every machine ran before, so the file filled with them is today's
|
|
// (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) {
|
|
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.Settings)
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
// Trusted (unmarked): a value is pasted into the file as it is, so `xrender"; write-pid-path = "…`
|
|
// would add an option of the caller's. Until settings are typed and quoted (hq issue 346), only the
|
|
// controller's terminal sets them.
|
|
if _, marked := r["trusted"]; marked {
|
|
t.Fatal("the file stays trusted: its settings are set at the terminal alone (hq issue 346)")
|
|
}
|
|
got := parseRules("picom.conf", withDefaults(c), nil)
|
|
if got.Global["backend"] != "glx" || got.Global["use-damage"] != "true" || got.Global["vsync"] != "true" {
|
|
t.Fatalf("filled with the defaults: %v", got.Global)
|
|
}
|
|
}
|
|
|
|
// withDefaults fills the file's config values with their defaults, as a machine without its own values gets it.
|
|
func withDefaults(c string) string {
|
|
return strings.NewReplacer("${config:backend}", "glx", "${config:use-damage}", "true").Replace(c)
|
|
}
|
|
|
|
// 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)
|
|
}
|