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
160 lines
5.7 KiB
Go
160 lines
5.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// slack's shape (novox/hq ADR 0208, ADR 0210, ADR 0212, ADR 0182): no package (Slack comes from the
|
|
// AUR, and the host installs from the official repositories only), no seat, no file; the X display on
|
|
// its own machine; one contribution to node-display-session that is both Slack's one start and its
|
|
// window rules; and the Go bundle serving exactly the listed slack_ tools.
|
|
|
|
func TestItInstallsNothingAndOwnsNoFile(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)
|
|
}
|
|
raw := string(manifestJSON)
|
|
if m.Module != "slack" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
|
|
t.Fatalf("%+v", m)
|
|
}
|
|
// slack-desktop is the AUR's: a package resource would ask the host for what it cannot install.
|
|
if m.Resources != nil || m.Capabilities != nil {
|
|
t.Fatalf("no package, no file: %v %v", m.Resources, m.Capabilities)
|
|
}
|
|
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil {
|
|
t.Fatal("it holds no seat, sets no environment and adds no session code")
|
|
}
|
|
// Slack's own setting writes ~/.config/autostart/slack.desktop (a link): never the module's.
|
|
for _, never := range []string{".config/autostart", ".config/Slack", "root-state", "Cookies"} {
|
|
if strings.Contains(raw, never) {
|
|
t.Errorf("module.json names %q", never)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTheOneContributionIsTheStartAndTheWindowRules(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)
|
|
}
|
|
content := displayLines(t, m)
|
|
if !strings.HasSuffix(content, "\n") {
|
|
t.Fatalf("%q", content)
|
|
}
|
|
var execs, rules []string
|
|
for _, l := range strings.Split(content, "\n") {
|
|
l = strings.TrimSpace(l)
|
|
switch {
|
|
case strings.HasPrefix(l, "exec"):
|
|
execs = append(execs, l)
|
|
case strings.HasPrefix(l, "for_window"):
|
|
rules = append(rules, l)
|
|
case l == "" || strings.HasPrefix(l, "#"):
|
|
default:
|
|
t.Errorf("a line that is neither the start nor a rule: %q", l)
|
|
}
|
|
}
|
|
want := "exec --no-startup-id " + slackBin + " " + strings.Join(startArgs, " ")
|
|
if len(execs) != 1 || execs[0] != want {
|
|
t.Fatalf("one start, the package entry's arguments, as slack_restart starts it: %q", execs)
|
|
}
|
|
// The operator's rules of 2026-08 (50-slack.conf), verified then against Slack's windows.
|
|
wantRules := []string{
|
|
`for_window [class="(?i)^slack$" window_role="browser-window"] move to workspace $ws3`,
|
|
`for_window [class="(?i)^slack$" window_role="browser-window"] floating disable`,
|
|
`for_window [class="(?i)^slack$" window_role="browser-window"] border pixel 2`,
|
|
}
|
|
if !reflect.DeepEqual(rules, wantRules) {
|
|
t.Fatalf("%q", rules)
|
|
}
|
|
for _, r := range rules {
|
|
if !strings.HasPrefix(r, ruleMark) {
|
|
t.Errorf("slack_check recognises the module's rules by %q: %s", ruleMark, r)
|
|
}
|
|
}
|
|
// The placed lines start Slack once: the fake i3 configuration below holds exactly this content.
|
|
f := newFake(t)
|
|
f.write(testHome+"/"+i3Main, "exec --no-startup-id dex --autostart --environment i3\n# slack\n"+content)
|
|
if s := f.starts(); len(s) != 1 || !s[0].Mine {
|
|
t.Fatalf("%+v", s)
|
|
}
|
|
if n, _ := f.windowRules(); n != 3 {
|
|
t.Fatalf("%d rules", n)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
raw := string(manifestJSON)
|
|
served := map[string]bool{}
|
|
for _, tool := range tools() {
|
|
served[tool.Name] = true
|
|
if !strings.HasPrefix(tool.Name, "slack_") || strings.TrimSpace(tool.Description) == "" {
|
|
t.Errorf("%s: prefixed slack_ and described", tool.Name)
|
|
}
|
|
}
|
|
for _, name := range m.Tools {
|
|
if !served[name] {
|
|
t.Errorf("module.json lists %s, which the bundle does not serve", name)
|
|
}
|
|
delete(served, name)
|
|
}
|
|
for name := range served {
|
|
t.Errorf("the bundle serves %s, which module.json does not list", name)
|
|
}
|
|
if len(m.Build.Artifacts) != 2 { // the tools bundle and the archive of its template
|
|
t.Fatalf("%v", m.Build.Artifacts)
|
|
}
|
|
b := m.Build.Artifacts[0]
|
|
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
|
|
b.From != "cmd/slack-tools" || b.Binary != "slack-tools" {
|
|
t.Errorf("the Go tools bundle: %v", b)
|
|
}
|
|
s := strings.ToLower(raw)
|
|
for _, never := range []string{"/home/", "jochen", "g14", "shanks", "novox.be", "http", "password", "token"} {
|
|
if strings.Contains(s, never) {
|
|
t.Errorf("module.json names %q", never)
|
|
}
|
|
}
|
|
}
|
|
|
|
// displayLines is the module's lines for the window manager: the text of the template of its one item of the
|
|
// collection contribution:node-display-session:config (design 57 L3, issue 848).
|
|
func displayLines(t *testing.T, m catalogue.Manifest) string {
|
|
t.Helper()
|
|
if !m.Moved || len(m.Contributions) != 0 || len(m.Items) != 1 ||
|
|
m.Items[0].Collection != "contribution:node-display-session:config" {
|
|
t.Fatalf("moved %v, contributions %v, items %+v", m.Moved, m.Contributions, m.Items)
|
|
}
|
|
text, err := os.ReadFile(filepath.Join("..", "..", m.Items[0].Template))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return string(text)
|
|
}
|