Compare commits

..
Author SHA1 Message Date
mesh-tools c9554e4b91 Merge pull request '16 modules' tests read module.json through mesh-sdk's manifest type; the copied helper goes (design 47 H2 H-A-498)' (#744) from fix/manifest-test-lenient into main 2026-11-22 20:54:32 +00:00
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
mesh-tools bf972d1d34 Merge pull request 'mesh-build-go: a mesh Go package comes from the Go package registry alone, two download passes (design 47 H2 H-A-494)' (#743) from fix/goproxy-registry-only into main 2026-11-22 20:14:41 +00:00
jschoubben 837cd2570a mesh-build-go: take mesh packages from the Go package registry alone
The public proxy serves the forge's paths from git tags and direct reaches
the forge's git, so a version missing from the registry was found elsewhere
instead of failing loudly. The fetch now downloads in two passes over every
directory: first each pinned mesh package with GOPROXY=<seat>,off (a miss says
"the Go package registry holds no <pkg>@<v>"; no binding refuses "no Go
package registry bound"), and every zero-version requirement of the graph is
taken or refused then; second the rest of the build list with the public
proxy alone, no direct. Before either, a go.mod naming a mesh package at a
version other than the zero version is refused, so no forge path can reach
the public proxy; a pull request head is placed only for an ask's commit, and
the placement of go.mod-named pins goes. Every other go command (test, lint,
compile) runs with GOPROXY=off; GOPRIVATE and the account's ssh settings leave
goEnv, as repository fetches set their own.

Builds: design 47 H2 H-A-494, H-A-494 addendum (two downloads), H-A-494 second addendum (a forge path at a real version is refused), H-A-494 third addendum (a pull request head places only an ask's commit pin); design 51 Go packages (the recipe test refuses direct)
2026-11-22 21:10:09 +01:00
mesh-tools 338813219e Merge pull request 'mesh-cli: nox licence prints the licences overview; every controller leftover removed (issue 1126 notes 151/152)' (#742) from fix/nox-licence-overview into main 2026-11-22 20:02:14 +00:00
jschoubben 3ff4df5c6e mesh-cli: nox licence is the licences' overview; the controller's leftovers go
The operator typed `nox licence` and got the retired controller's refusal
instead of the licences. `nox licence` and `nox licence list` now call the
licence manager's licences and bindings and print one table of each, every
time local (1126/AC1); `nox licence usage [<licence>]` prints the usage
readings as a table (1126/AC2). `--json` prints the raw answer on every
rendered line, `nox nodes` included: one behaviour for one flag; for the
two calls one object {licences, bindings} (1126/AC3).

In the same change, the operator (2026-11-22 20:41): "why are there still
references to the controller?". Every retired controller line nox answered
with "this was the controller's" (its `instead` lines and the `unowned`
map) is deleted with its text: none has a seat verb of the same job; a
retired line now answers "is not a command" with exit 2, and nothing nox
prints names the controller (1126/AC4). The comments, help and README no
longer name the controller or issue 1126.

Builds: issue 1126 note 151, answers 1-5, and the note after it (acceptance
1126/AC1..AC4, the operator's 20:41 line); one-question-one-tool;
principle 4, a module is steered by its tools.
2026-11-22 20:50:22 +01:00
50 changed files with 1962 additions and 1533 deletions
@@ -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)
@@ -1,66 +1,19 @@
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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Items []item `json:"items"`
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.
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"`
}
// An item of a collection (novox/hq ADR 0349 clause 13): its text is the template file beside the manifest.
type item struct {
Collection string `json:"collection"`
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Template string `json:"template"`
}
// shell is the code the module adds to a shell's or the session's start, read from the templates of its items of
// the collections shell:<file>:<slot>, in the order they are declared.
func (m manifest) shell(t *testing.T) []shellCode {
func shell(t *testing.T, m catalogue.Manifest) []catalogue.ShellCode {
t.Helper()
var out []shellCode
var out []catalogue.ShellCode
for _, it := range m.Items {
parts := strings.Split(it.Collection, ":")
if len(parts) != 3 || parts[0] != "shell" {
@@ -70,15 +23,15 @@ func (m manifest) shell(t *testing.T) []shellCode {
if err != nil {
t.Fatal(err)
}
out = append(out, shellCode{For: parts[1], Slot: parts[2], Code: string(text)})
out = append(out, catalogue.ShellCode{For: parts[1], Slot: parts[2], Code: string(text)})
}
return out
}
// environmentOf is the variables the module sets, read from the templates of its items of the environment.
func (m manifest) environmentOf(t *testing.T) *environment {
func environmentOf(t *testing.T, m catalogue.Manifest) *catalogue.Environment {
t.Helper()
var env *environment
var env *catalogue.Environment
for _, it := range m.Items {
if it.Collection != "environment" || it.Attributes["kind"] != "variable" {
continue
@@ -88,30 +41,14 @@ func (m manifest) environmentOf(t *testing.T) *environment {
t.Fatal(err)
}
if env == nil {
env = &environment{Variables: map[string]string{}}
env = &catalogue.Environment{Variables: map[string]string{}}
}
env.Variables[it.Attributes["name"]] = strings.TrimSuffix(string(text), "\n")
}
return env
}
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)
}
m.Environment = m.environmentOf(t)
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 {
@@ -122,7 +59,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 {
@@ -138,9 +75,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"])
}
@@ -160,7 +97,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 {
@@ -169,10 +106,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)
}
}
}
@@ -182,9 +119,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)
}
@@ -197,7 +134,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() {
@@ -239,14 +176,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)
}
}
@@ -271,7 +208,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 {
@@ -287,7 +224,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)
@@ -301,7 +238,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)
}
}
@@ -6,12 +6,15 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"sync"
"syscall"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// clipmenu's shape (novox/hq ADR 0208, research 026/04): it claims node-clipboard serving history
@@ -19,28 +22,44 @@ import (
// from the session's start, and binds its menu as an i3 drop-in through the launcher's dmenu command.
func TestItClaimsTheClipboardSeatServingHistoryAndCopy(t *testing.T) {
m := readManifest(t)
if m.Module != "clipmenu" || 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-clipboard", Scope: "node", Serves: []string{"history", "copy"}}}) {
// 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 != "clipmenu" || m.DefinesSeats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
}
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-clipboard", Scope: "node", Serves: []string{"history", "copy"}}}) {
t.Fatalf("claims: %+v", m.Claims)
}
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
t.Fatalf("requires: %v", m.Requires)
}
present, absent := m.packages()
present, absent := packages(m)
if !reflect.DeepEqual(present, []string{"clipmenu"}) || !reflect.DeepEqual(absent, []string{"rofi-greenclip"}) {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestTheDaemonIsTheOperatorsUserUnitEnabledAndRunning(t *testing.T) {
m := readManifest(t)
if len(m.shell(t)) != 0 {
t.Fatalf("a second start from the session: %+v", m.shell(t))
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
svc := m.resource(t, "daemon")
// 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 len(shell(t, m)) != 0 {
t.Fatalf("a second start from the session: %+v", shell(t, m))
}
svc := resource(t, m, "daemon")
want := map[string]any{"id": "daemon", "type": "service", "unit": "clipmenud.service", "scope": "user",
"user": "${machine:account}", "state": "running", "boot": "enabled", "reload-on": nil}
for k, v := range want {
@@ -53,15 +72,15 @@ func TestTheDaemonIsTheOperatorsUserUnitEnabledAndRunning(t *testing.T) {
if h, _ := svc["health"].(map[string]any); h["kind"] != "unit" {
t.Fatalf("daemon health = %v, want kind unit", svc["health"])
}
dropin := m.resource(t, "daemon-dropin")
content := m.text(t, "daemon-dropin")
dropin := resource(t, m, "daemon-dropin")
content := templateText(t, m, "daemon-dropin")
if dropin["path"] != "${machine:account-home}/.config/systemd/user/clipmenud.service.d/mesh.conf" ||
dropin["owner"] != "${machine:account}" ||
!strings.Contains(content, "ExecStart=/usr/local/lib/mesh-clipmenu/clipmenud-session") ||
strings.Contains(content, "greenclip") {
t.Fatalf("drop-in: %v", dropin)
}
launcher := m.text(t, "launcher")
launcher := templateText(t, m, "launcher")
if !strings.Contains(launcher, "DISPLAY") || !strings.Contains(launcher, "/tmp/.X11-unix") ||
!strings.Contains(launcher, `PATH="/usr/local/lib/mesh-clipmenu:$PATH"`) || !strings.Contains(launcher, "exec clipmenud") {
t.Fatalf("launcher: %q", launcher)
@@ -74,7 +93,7 @@ func TestTheDaemonIsTheOperatorsUserUnitEnabledAndRunning(t *testing.T) {
if !strings.Contains(content, "StartLimitIntervalSec=0") || !strings.Contains(content, "RestartSec=2s") {
t.Fatalf("drop-in lacks the safety net: %q", content)
}
for k, v := range m.environmentOf(t).Variables {
for k, v := range environmentOf(t, m).Variables {
if !strings.Contains(content, "Environment="+k+"="+v) {
t.Fatalf("the unit lacks %s=%s", k, v)
}
@@ -82,34 +101,67 @@ func TestTheDaemonIsTheOperatorsUserUnitEnabledAndRunning(t *testing.T) {
}
func TestItsSettingsAreEnvironmentAndItsMenuIsTheLaunchersDmenu(t *testing.T) {
m := readManifest(t)
if !reflect.DeepEqual(m.Environment.Variables, map[string]string{"CM_SELECTIONS": "clipboard", "CM_MAX_CLIPS": "500", "CM_HISTLENGTH": "15"}) {
t.Fatalf("%v", m.Environment.Variables)
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
if _, set := m.Environment.Variables["CM_LAUNCHER"]; set {
// 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 !reflect.DeepEqual(environmentOf(t, m).Variables, map[string]string{"CM_SELECTIONS": "clipboard", "CM_MAX_CLIPS": "500", "CM_HISTLENGTH": "15"}) {
t.Fatalf("%v", environmentOf(t, m).Variables)
}
if _, set := environmentOf(t, m).Variables["CM_LAUNCHER"]; set {
t.Fatal("the launcher is clipmenu's default, dmenu: the seat's command")
}
m.i3LinesAreSource(t, "files/i3/50-clipmenu.conf")
if c := m.i3Lines(); !strings.Contains(c, "bindsym $mod+period exec --no-startup-id clipmenu") {
i3LinesAreSource(t, m, "files/i3/50-clipmenu.conf")
if c := i3Lines(m); !strings.Contains(c, "bindsym $mod+period exec --no-startup-id clipmenu") {
t.Fatalf("%s", c)
}
}
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)
}
// Run for real: DISPLAY from the manager is used at once; several sockets and no DISPLAY wait.
func TestTheLauncherUsesTheManagersDisplayAndWaitsOtherwise(t *testing.T) {
m := readManifest(t)
script := m.text(t, "launcher")
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)
}
script := templateText(t, m, "launcher")
dir := t.TempDir()
file := dir + "/launcher"
// clipmenud and the socket directory are faked: the script's own paths are rewritten.
@@ -162,8 +214,16 @@ func TestTheLauncherWaitsQuietlyWhileAnotherClipmenudHoldsTheLock(t *testing.T)
if _, err := exec.LookPath("flock"); err != nil {
t.Skip("flock is missing here")
}
m := readManifest(t)
script := m.text(t, "launcher")
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)
}
script := templateText(t, m, "launcher")
dir := t.TempDir()
body := strings.Replace(script, "exec clipmenud", `echo "started"`, 1)
file := dir + "/launcher"
@@ -1,85 +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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Capabilities []string `json:"capabilities"`
Requires []string `json:"requires"`
Claims []claim `json:"claims"`
Seats []any `json:"seats"`
Tools []string `json:"tools"`
Config map[string]config `json:"config"`
Emits []string `json:"emits"`
Items []item `json:"items"`
Contributions []any `json:"contributions"`
Environment *environment `json:"environment"`
Shell []shellCode `json:"shell"`
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
// config is one config value as the definition declares it (novox/hq ADR 0348 §4).
type config struct {
Type string `json:"type"`
Description string `json:"description"`
Enum []any `json:"enum"`
Minimum *float64 `json:"minimum"`
Maximum *float64 `json:"maximum"`
Pattern string `json:"pattern"`
Trusted bool `json:"trusted"`
Predefined string `json:"predefined"`
Default any `json:"default"`
Required bool `json:"required"`
Runtime bool `json:"runtime"`
}
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 {
@@ -90,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 {
@@ -106,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"])
}
@@ -128,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 {
@@ -137,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)
}
}
}
@@ -150,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)
}
@@ -165,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() {
@@ -207,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)
}
}
@@ -239,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 {
@@ -255,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)
@@ -269,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"`
}
+113 -28
View File
@@ -1,9 +1,13 @@
package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// dunst's shape (novox/hq ADR 0208): it claims node-notifier serving send and history, owns its
@@ -12,28 +16,44 @@ import (
// activation, so it requires no display of its own.
func TestItClaimsTheNotifierSeatServingSendAndHistory(t *testing.T) {
m := readManifest(t)
if m.Module != "dunst" || 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-notifier", Scope: "node", Serves: []string{"send", "history"}}}) {
// 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 != "dunst" || m.DefinesSeats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
}
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-notifier", Scope: "node", Serves: []string{"send", "history"}}}) {
t.Fatalf("claims: %+v", m.Claims)
}
// rofi, the context menu the dunstrc calls by name, is the rofi module's package: two modules on one
// machine may not declare the same package, and the rofi module holds node-launcher on every
// machine dunst serves.
if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"dunst", "libnotify"}) || absent != nil {
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"dunst", "libnotify"}) || absent != nil {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestItOwnsItsFileAndTheDropInDirectory(t *testing.T) {
m := readManifest(t)
m.fromTemplate(t, "configuration", "files/dunstrc")
if p := m.resource(t, "configuration")["path"]; p != "${machine:account-home}/.config/dunst/dunstrc" {
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/dunstrc")
if p := resource(t, m, "configuration")["path"]; p != "${machine:account-home}/.config/dunst/dunstrc" {
t.Fatalf("path: %v", p)
}
if d := m.resource(t, "dropins"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/dunst/dunstrc.d" {
if d := resource(t, m, "dropins"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/dunst/dunstrc.d" {
t.Fatalf("drop-ins: %v", d)
}
for _, r := range m.Resources {
@@ -44,8 +64,16 @@ func TestItOwnsItsFileAndTheDropInDirectory(t *testing.T) {
}
func TestTheFileIsTheDecidedOneAndCallsRofi(t *testing.T) {
m := readManifest(t)
c := 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)
}
c := templateText(t, m, "configuration")
for _, want := range []string{"origin = top-right", "transparency = 0", "corner_radius = 0", "font = Inter ${config:font-size}",
"width = ${config:width}", "dmenu = rofi -dmenu -no-custom -p dunst"} {
if !strings.Contains(c, " "+want+"\n") {
@@ -66,8 +94,16 @@ func TestTheFileIsTheDecidedOneAndCallsRofi(t *testing.T) {
// of them (dunst holds it open until the menu answers, and an Escape leaves it shown), and one without
// actions closes. Every other click is as it was.
func TestATapChoosesTheNotificationsAction(t *testing.T) {
m := readManifest(t)
c := 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)
}
c := templateText(t, m, "configuration")
for _, want := range []string{"mouse_left_click = do_action, close_current",
"mouse_middle_click = do_action, close_current", "mouse_right_click = close_all"} {
if !strings.Contains(c, " "+want+"\n") {
@@ -82,9 +118,17 @@ func TestATapChoosesTheNotificationsAction(t *testing.T) {
// The key that chooses from the keyboard is a line i3 places from this contribution (novox/hq ADR
// 0212): a binding only, never a start, so the bus stays the only thing that starts dunst.
func TestTheMenuKeyIsABindingI3Places(t *testing.T) {
m := readManifest(t)
m.i3LinesAreSource(t, "files/i3/50-dunst.conf")
lines := 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-dunst.conf")
lines := i3Lines(m)
if !strings.Contains(lines, "bindsym $mod+n exec --no-startup-id dunstctl context\n") {
t.Fatalf("no key for the context menu: %s", lines)
}
@@ -100,23 +144,31 @@ func TestTheMenuKeyIsABindingI3Places(t *testing.T) {
// predefined font-size (ADR 0348 §2), so a machine with a denser screen sets its own and every other
// machine's file is unchanged. Neither is trusted: the file says "trusted": false.
func TestTheFontSizeAndWidthAreConfigValuesWithTodaysDefaults(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)
}
want := map[string]float64{"font-size": 10, "width": 250}
if len(m.Config) != len(want) {
t.Fatalf("config: %+v", m.Config)
if len(m.Settings) != len(want) {
t.Fatalf("config: %+v", m.Settings)
}
for key, value := range want {
s, ok := m.Config[key]
s, ok := m.Settings[key]
if !ok || s.Type != "number" || s.Default != value || s.Required || s.Trusted ||
strings.TrimSpace(s.Description) == "" || s.Minimum == nil || s.Maximum == nil {
t.Errorf("%s: %+v, want an untrusted number defaulting to %v, with a description and bounds", key, s, value)
}
}
if p := m.Config["font-size"].Predefined; p != "font-size" {
if p := m.Settings["font-size"].Predefined; p != "font-size" {
t.Errorf("the font size falls back to %q, want the predefined font-size", p)
}
// Filled with the defaults, the file is the one every machine had before it took config values.
c := m.text(t, "configuration")
c := templateText(t, m, "configuration")
c = strings.ReplaceAll(c, "${config:font-size}", "10")
c = strings.ReplaceAll(c, "${config:width}", "250")
for _, want := range []string{"font = Inter 10", "width = 250"} {
@@ -130,7 +182,15 @@ func TestTheFontSizeAndWidthAreConfigValuesWithTodaysDefaults(t *testing.T) {
}
func TestNothingStartsItButTheBus(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)
}
if m.Shell != nil {
t.Fatalf("a session start: %+v", m.Shell)
}
@@ -147,25 +207,50 @@ func TestNothingStartsItButTheBus(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)
}
// dunst moves first (design 57 P6, issue 672): marked moved, its dunstrc is filled on the node by the provisioner's
// client from its template, and reloaded as the file declares.
func TestItIsHandedToTheProvisioner(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)
}
if !m.Moved {
t.Fatal("dunst is not marked moved")
}
m.fromTemplate(t, "configuration", "files/dunstrc")
if on := m.resource(t, "notifier")["reload-on"]; !reflect.DeepEqual(on, []any{"configuration"}) {
fromTemplate(t, m, "configuration", "files/dunstrc")
if on := resource(t, m, "notifier")["reload-on"]; !reflect.DeepEqual(on, []any{"configuration"}) {
t.Fatalf("the notifier is not reloaded on its dunstrc: %v", on)
}
}
+12 -2
View File
@@ -6,6 +6,8 @@ import (
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// The running dunst reads its file again when the file changes (novox/hq ADR 0262: a setting the
@@ -83,8 +85,16 @@ func TestAReloadDunstRefusesIsAFailure(t *testing.T) {
}
func TestTheRunningDunstIsReloadedWhenItsFileChanges(t *testing.T) {
m := readManifest(t)
s := m.resource(t, "notifier")
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)
}
s := resource(t, m, "notifier")
want := map[string]any{
"id": "notifier", "type": "service", "unit": "dunst.service",
"scope": "user", "user": "${machine:account}",
@@ -1,66 +1,19 @@
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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Items []item `json:"items"`
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.
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"`
}
// An item of a collection (novox/hq ADR 0349 clause 13): its text is the template file beside the manifest.
type item struct {
Collection string `json:"collection"`
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Template string `json:"template"`
}
// shell is the code the module adds to a shell's or the session's start, read from the templates of its items of
// the collections shell:<file>:<slot>, in the order they are declared.
func (m manifest) shell(t *testing.T) []shellCode {
func shell(t *testing.T, m catalogue.Manifest) []catalogue.ShellCode {
t.Helper()
var out []shellCode
var out []catalogue.ShellCode
for _, it := range m.Items {
parts := strings.Split(it.Collection, ":")
if len(parts) != 3 || parts[0] != "shell" {
@@ -70,15 +23,15 @@ func (m manifest) shell(t *testing.T) []shellCode {
if err != nil {
t.Fatal(err)
}
out = append(out, shellCode{For: parts[1], Slot: parts[2], Code: string(text)})
out = append(out, catalogue.ShellCode{For: parts[1], Slot: parts[2], Code: string(text)})
}
return out
}
// environmentOf is the variables the module sets, read from the templates of its items of the environment.
func (m manifest) environmentOf(t *testing.T) *environment {
func environmentOf(t *testing.T, m catalogue.Manifest) *catalogue.Environment {
t.Helper()
var env *environment
var env *catalogue.Environment
for _, it := range m.Items {
if it.Collection != "environment" || it.Attributes["kind"] != "variable" {
continue
@@ -88,30 +41,14 @@ func (m manifest) environmentOf(t *testing.T) *environment {
t.Fatal(err)
}
if env == nil {
env = &environment{Variables: map[string]string{}}
env = &catalogue.Environment{Variables: map[string]string{}}
}
env.Variables[it.Attributes["name"]] = strings.TrimSuffix(string(text), "\n")
}
return env
}
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)
}
m.Environment = m.environmentOf(t)
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 {
@@ -122,7 +59,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 {
@@ -138,9 +75,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"])
}
@@ -160,7 +97,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 {
@@ -169,10 +106,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)
}
}
}
@@ -182,9 +119,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)
}
@@ -197,7 +134,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() {
@@ -239,14 +176,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)
}
}
@@ -271,7 +208,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 {
@@ -287,7 +224,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)
@@ -301,7 +238,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)
}
}
+70 -19
View File
@@ -6,6 +6,8 @@ import (
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// feh's shape (novox/hq ADR 0208): no seat; it requires the X display on its own machine, carries
@@ -13,27 +15,43 @@ import (
// the session's start.
func TestItRequiresTheXDisplayAndClaimsNothing(t *testing.T) {
m := readManifest(t)
if m.Module != "feh" || m.Seats != nil || m.Claims != nil {
t.Fatalf("module %q, seats %v, claims %v", m.Module, m.Seats, m.Claims)
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 != "feh" || m.DefinesSeats != nil || m.Claims != nil {
t.Fatalf("module %q, seats %v, claims %v", m.Module, m.DefinesSeats, 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{"feh"}) || absent != nil {
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"feh"}) || absent != nil {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestTheWallpaperIsTheModulesOwnArchive(t *testing.T) {
m := readManifest(t)
a := m.resource(t, "wallpapers")
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)
}
a := resource(t, m, "wallpapers")
if a["type"] != "archive" || a["artifact"] != "wallpapers" || a["path"] != "${machine:account-home}/.local/share/feh/wallpapers" || a["owner"] != "${machine:account}" {
t.Fatalf("%v", a)
}
found := false
for _, art := range m.Build.Artifacts {
if art["name"] == "wallpapers" && art["kind"] == "archive" && art["from"] == "wallpaper" {
if art.Name == "wallpapers" && art.Kind == "archive" && art.From == "wallpaper" {
found = true
}
}
@@ -47,38 +65,71 @@ func TestTheWallpaperIsTheModulesOwnArchive(t *testing.T) {
}
func TestFehbgIsOwnedAndTheSessionStartRunsItOnce(t *testing.T) {
m := readManifest(t)
m.fromTemplate(t, "fehbg", "files/fehbg")
f := m.resource(t, "fehbg")
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, "fehbg", "files/fehbg")
f := resource(t, m, "fehbg")
if f["path"] != "${machine:account-home}/.fehbg" || f["mode"] != "0755" {
t.Fatalf("%v", f)
}
if c := m.text(t, "fehbg"); !strings.Contains(c, "$HOME/.local/share/feh/wallpapers/default.jpg") || strings.Contains(c, ".hal") {
if c := templateText(t, m, "fehbg"); !strings.Contains(c, "$HOME/.local/share/feh/wallpapers/default.jpg") || strings.Contains(c, ".hal") {
t.Fatalf("%s", c)
}
if len(m.shell(t)) != 1 || m.shell(t)[0].For != "xinitrc" || m.shell(t)[0].Slot != "normal" || strings.Count(m.shell(t)[0].Code, `"$HOME/.fehbg"`) != 1 {
t.Fatalf("%+v", m.shell(t))
if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" || strings.Count(shell(t, m)[0].Code, `"$HOME/.fehbg"`) != 1 {
t.Fatalf("%+v", shell(t, m))
}
}
func TestTheKeyThatRestoresTheWallpaperIsAnI3DropIn(t *testing.T) {
m := readManifest(t)
m.i3LinesAreSource(t, "files/i3/50-feh.conf")
if p := m.i3Lines(); p == "" {
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-feh.conf")
if p := i3Lines(m); p == "" {
t.Fatalf("path: %v", p)
}
if c := m.i3Lines(); !strings.Contains(c, "bindsym $mod+Shift+b exec --no-startup-id ~/.fehbg\n") {
if c := i3Lines(m); !strings.Contains(c, "bindsym $mod+Shift+b exec --no-startup-id ~/.fehbg\n") {
t.Fatalf("%s", c)
}
}
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)
}
@@ -1,12 +1,13 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// forticlient's shape (novox/hq ADR 0205, ADR 0207, ADR 0208): no package (the client is outside the
@@ -15,48 +16,17 @@ import (
// start), nothing of the VPN's configuration, and the Go bundle serving exactly the listed forticlient_
// tools.
type manifest struct {
Module string `json:"module"`
Version string `json:"version"`
Upgrade struct {
Policy string `json:"policy"`
Why string `json:"why"`
} `json:"upgrade"`
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 []struct {
Seat string `json:"seat"`
Kind string `json:"kind"`
Content string `json:"content"`
} `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 TestTheToolsAgreeWithTheManifest(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 TestTheToolsAgreeWithTheManifest(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
served := map[string]bool{}
for _, tool := range tools() {
served[tool.Name] = true
@@ -77,8 +47,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/forticlient-tools" || b["binary"] != "forticlient-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/forticlient-tools" || b.Binary != "forticlient-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -90,7 +60,16 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
}
func TestItDeclaresTheServiceAndNothingOfTheConfiguration(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)
// split-dns (novox/hq ADR 0247): the machine's own resolver, which its adapter hands the client's
// resolver file to. Required at the machine's reach, so the module is assigned only beside one.
if m.Module != "forticlient" || !reflect.DeepEqual(m.Requires, []string{"x11-display", "split-dns"}) ||
@@ -110,7 +89,7 @@ func TestItDeclaresTheServiceAndNothingOfTheConfiguration(t *testing.T) {
if m.Upgrade.Policy != "record" || m.Upgrade.Why == "" {
t.Error("a build of what routes the person's work names rolls out on its own")
}
if m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
t.Fatal("no seat, no environment, and no second start")
}
for _, never := range []string{"/etc/forticlient", "/opt/forticlient", "autostart", "\"package\"", "vpn.", "gateway", "profile"} {
@@ -1,64 +1,19 @@
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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Items []item `json:"items"`
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"`
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"`
}
// An item of a collection (novox/hq ADR 0349 clause 13): its text is the template file beside the manifest.
type item struct {
Collection string `json:"collection"`
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Template string `json:"template"`
}
// shell is the code the module adds to a shell's or the session's start, read from the templates of its items of
// the collections shell:<file>:<slot>, in the order they are declared.
func (m manifest) shell(t *testing.T) []shellCode {
func shell(t *testing.T, m catalogue.Manifest) []catalogue.ShellCode {
t.Helper()
var out []shellCode
var out []catalogue.ShellCode
for _, it := range m.Items {
parts := strings.Split(it.Collection, ":")
if len(parts) != 3 || parts[0] != "shell" {
@@ -68,15 +23,15 @@ func (m manifest) shell(t *testing.T) []shellCode {
if err != nil {
t.Fatal(err)
}
out = append(out, shellCode{For: parts[1], Slot: parts[2], Code: string(text)})
out = append(out, catalogue.ShellCode{For: parts[1], Slot: parts[2], Code: string(text)})
}
return out
}
// environmentOf is the variables the module sets, read from the templates of its items of the environment.
func (m manifest) environmentOf(t *testing.T) *environment {
func environmentOf(t *testing.T, m catalogue.Manifest) *catalogue.Environment {
t.Helper()
var env *environment
var env *catalogue.Environment
for _, it := range m.Items {
if it.Collection != "environment" || it.Attributes["kind"] != "variable" {
continue
@@ -86,30 +41,14 @@ func (m manifest) environmentOf(t *testing.T) *environment {
t.Fatal(err)
}
if env == nil {
env = &environment{Variables: map[string]string{}}
env = &catalogue.Environment{Variables: map[string]string{}}
}
env.Variables[it.Attributes["name"]] = strings.TrimSuffix(string(text), "\n")
}
return env
}
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)
}
m.Environment = m.environmentOf(t)
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 {
@@ -120,7 +59,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 {
@@ -136,9 +75,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"])
}
@@ -158,7 +97,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 {
@@ -167,10 +106,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)
}
}
}
@@ -180,9 +119,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)
}
@@ -195,7 +134,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() {
@@ -237,14 +176,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)
}
}
@@ -1,9 +1,13 @@
package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// gnome-keyring's shape (novox/hq ADR 0208, ADR 0102): it claims node-secret-service, writes its PAM
@@ -11,31 +15,47 @@ import (
// of its own: PAM and D-Bus do.
func TestItClaimsTheSecretServiceSeat(t *testing.T) {
m := readManifest(t)
if m.Module != "gnome-keyring" || m.Seats != nil || m.Requires != nil {
t.Fatalf("module %q, seats %v, requires %v", m.Module, m.Seats, m.Requires)
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(m.Claims, []claim{{Name: "node-secret-service", Scope: "node"}}) {
// 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 != "gnome-keyring" || m.DefinesSeats != nil || m.Requires != nil {
t.Fatalf("module %q, seats %v, requires %v", m.Module, m.DefinesSeats, m.Requires)
}
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-secret-service", Scope: "node"}}) {
t.Fatalf("claims: %+v", m.Claims)
}
if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"gnome-keyring", "libsecret", "seahorse"}) || absent != nil {
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"gnome-keyring", "libsecret", "seahorse"}) || absent != nil {
t.Fatalf("packages: %v, absent %v", present, absent)
}
}
func TestThePAMLinesAreBlocksWrittenIntoTheStacks(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, want := range map[string]struct{ path, source string }{
"pam-login": {"/etc/pam.d/login", "files/pam/login"},
"pam-passwd": {"/etc/pam.d/passwd", "files/pam/passwd"},
} {
m.fromTemplate(t, id, want.source)
r := m.resource(t, id)
fromTemplate(t, m, id, want.source)
r := resource(t, m, id)
if r["path"] != want.path || r["into"] != "block" || r["at"] != "end" || r["owner"] != nil {
t.Errorf("%s: %v", id, r)
}
}
login := m.text(t, "pam-login")
login := templateText(t, m, "pam-login")
if !strings.Contains(login, "\nauth optional pam_gnome_keyring.so\n") ||
!strings.Contains(login, "\nsession optional pam_gnome_keyring.so auto_start\n") {
t.Fatalf("%s", login)
@@ -43,27 +63,52 @@ func TestThePAMLinesAreBlocksWrittenIntoTheStacks(t *testing.T) {
}
func TestItStartsNoDaemonAndOnlyNamesTheAgentsSocket(t *testing.T) {
m := readManifest(t)
if len(m.shell(t)) != 1 || m.shell(t)[0].For != "xinitrc" || m.shell(t)[0].Slot != "first" {
t.Fatalf("%+v", m.shell(t))
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
code := m.shell(t)[0].Code
// 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 len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "first" {
t.Fatalf("%+v", shell(t, m))
}
code := shell(t, m)[0].Code
if strings.Contains(code, "gnome-keyring-daemon") || strings.Contains(code, "--unlock") ||
!strings.Contains(code, `SSH_AUTH_SOCK="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/gcr/ssh"`) {
t.Fatalf("%q", code)
}
if m.Environment != nil {
if environmentOf(t, m) != nil {
t.Fatal("SSH_AUTH_SOCK needs the runtime directory, which ADR 0203 forbids in a value; it is not an environment contribution yet")
}
}
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)
}
@@ -5,15 +5,25 @@ import (
"path/filepath"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// The blocks other modules contribute are a collection of text (design 57 L3, novox/hq ADR 0349 clause 13): each
// contributor gives its block in i3status-rust's grammar, and the bars place the collection where they want it.
func TestEachBarPlacesBothPlacesOnce(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 _, bar := range []string{"bottom", "top"} {
content := m.text(t, bar+"-bar")
content := templateText(t, m, bar+"-bar")
for _, place := range []string{"resources", "status"} {
ph := "${collected:contribution:node-bar:block:bar=" + bar + ",place=" + place + "}"
if strings.Count(content, ph) != 1 {
@@ -21,7 +31,7 @@ func TestEachBarPlacesBothPlacesOnce(t *testing.T) {
}
}
}
bottom := m.text(t, "bottom-bar")
bottom := templateText(t, m, "bottom-bar")
resources := strings.Index(bottom, "place=resources")
if !(strings.Index(bottom, `block = "memory"`) < resources && resources < strings.Index(bottom, `block = "docker"`)) ||
!(strings.Index(bottom, `block = "sound"`) < strings.Index(bottom, "place=status") &&
@@ -31,7 +41,16 @@ func TestEachBarPlacesBothPlacesOnce(t *testing.T) {
}
func TestTheMemoryIsWhatProgramsHoldNotTheCache(t *testing.T) {
bottom := readManifest(t).text(t, "bottom-bar")
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)
}
bottom := templateText(t, m, "bottom-bar")
if !strings.Contains(bottom, `format = "$icon $mem_used.eng(w:2) ($mem_used_percents.eng(w:2))"`) ||
strings.Contains(bottom, "mem_total_used") {
t.Fatal("the memory block counts the cache as used")
@@ -39,9 +58,17 @@ func TestTheMemoryIsWhatProgramsHoldNotTheCache(t *testing.T) {
}
func TestABarNamesNoTemplateOfItsOwnForTheBlocksItPlaces(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 := range []string{"top-bar", "bottom-bar"} {
if strings.Contains(m.text(t, id), "${contribution:") {
if strings.Contains(templateText(t, m, id), "${contribution:") {
t.Errorf("the %s still places a contribution the old way", id)
}
}
@@ -1,68 +1,19 @@
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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Items []item `json:"items"`
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.
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"`
// How the holder renders each kind its seat receives as data (novox/hq ADR 0255).
Renders map[string]string `json:"renders"`
}
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"`
}
// An item of a collection (novox/hq ADR 0349 clause 13): its text is the template file beside the manifest.
type item struct {
Collection string `json:"collection"`
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Template string `json:"template"`
}
// shell is the code the module adds to a shell's or the session's start, read from the templates of its items of
// the collections shell:<file>:<slot>, in the order they are declared.
func (m manifest) shell(t *testing.T) []shellCode {
func shell(t *testing.T, m catalogue.Manifest) []catalogue.ShellCode {
t.Helper()
var out []shellCode
var out []catalogue.ShellCode
for _, it := range m.Items {
parts := strings.Split(it.Collection, ":")
if len(parts) != 3 || parts[0] != "shell" {
@@ -72,15 +23,15 @@ func (m manifest) shell(t *testing.T) []shellCode {
if err != nil {
t.Fatal(err)
}
out = append(out, shellCode{For: parts[1], Slot: parts[2], Code: string(text)})
out = append(out, catalogue.ShellCode{For: parts[1], Slot: parts[2], Code: string(text)})
}
return out
}
// environmentOf is the variables the module sets, read from the templates of its items of the environment.
func (m manifest) environmentOf(t *testing.T) *environment {
func environmentOf(t *testing.T, m catalogue.Manifest) *catalogue.Environment {
t.Helper()
var env *environment
var env *catalogue.Environment
for _, it := range m.Items {
if it.Collection != "environment" || it.Attributes["kind"] != "variable" {
continue
@@ -90,30 +41,14 @@ func (m manifest) environmentOf(t *testing.T) *environment {
t.Fatal(err)
}
if env == nil {
env = &environment{Variables: map[string]string{}}
env = &catalogue.Environment{Variables: map[string]string{}}
}
env.Variables[it.Attributes["name"]] = strings.TrimSuffix(string(text), "\n")
}
return env
}
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)
}
m.Environment = m.environmentOf(t)
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 {
@@ -124,7 +59,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 {
@@ -140,9 +75,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"])
}
@@ -162,7 +97,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 {
@@ -171,10 +106,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)
}
}
}
@@ -184,9 +119,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)
}
@@ -199,7 +134,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() {
@@ -241,14 +176,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)
}
}
@@ -273,7 +208,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 {
@@ -289,7 +224,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)
@@ -303,7 +238,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)
}
}
@@ -1,9 +1,13 @@
package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// i3status-rust's shape (novox/hq ADR 0208): it claims node-bar, requires the X display on its own
@@ -12,12 +16,20 @@ import (
// devices.
func TestItClaimsTheBarSeatAndRequiresTheXDisplay(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)
}
if !m.Moved {
t.Fatal("the module is not marked moved")
}
if m.Module != "i3status-rust" || m.Seats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.Seats)
if m.Module != "i3status-rust" || m.DefinesSeats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
}
if len(m.Claims) != 1 || m.Claims[0].Name != "node-bar" || m.Claims[0].Scope != "node" ||
len(m.Claims[0].Renders) != 0 {
@@ -26,25 +38,41 @@ func TestItClaimsTheBarSeatAndRequiresTheXDisplay(t *testing.T) {
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
t.Fatalf("requires: %v", m.Requires)
}
if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"i3status-rust"}) || absent != nil {
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"i3status-rust"}) || 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, src := range map[string]string{
"top-bar": "files/top-bar.toml", "bottom-bar": "files/bottom-bar.toml", "icons": "files/icons/custom-icons.toml",
"updates": "files/bin/i3status-updates", "watchdog": "files/bin/i3bar-watchdog",
"value": "files/bin/i3status-value",
} {
m.fromTemplate(t, id, src)
fromTemplate(t, m, id, src)
}
}
func TestNoBlockFollowsAMachinesHardwareOrAPersonsDevicesOrCarriesAKey(t *testing.T) {
m := readManifest(t)
bottom := m.text(t, "bottom-bar")
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)
}
bottom := templateText(t, m, "bottom-bar")
for _, never := range []string{`block = "battery"`, `block = "amd_gpu"`, `block = "nvidia_gpu"`, "mac = ", "api_key", "city_id", "openweathermap", "~/scripts/"} {
if strings.Contains(bottom, never) {
t.Errorf("the bottom bar has %s", never)
@@ -53,26 +81,51 @@ func TestNoBlockFollowsAMachinesHardwareOrAPersonsDevicesOrCarriesAKey(t *testin
}
func TestTheBarsAreAContributionToTheWindowManagerAndTheWatchdogRunsOncePerSession(t *testing.T) {
m := readManifest(t)
m.i3LinesAreSource(t, "files/i3/60-i3status-rust.conf")
c := 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/60-i3status-rust.conf")
c := i3Lines(m)
if strings.Count(c, "bar {") != 2 || !strings.Contains(c, "status_command i3status-rs ~/.config/i3status-rust/bottom-bar.toml") ||
!strings.Contains(c, "font pango:JetBrainsMono Nerd Font 11") {
t.Fatalf("%s", c)
}
if len(m.shell(t)) != 1 || m.shell(t)[0].For != "xinitrc" || m.shell(t)[0].Slot != "normal" ||
!strings.Contains(m.shell(t)[0].Code, `"$HOME/.local/bin/i3bar-watchdog" "$$" &`) {
t.Fatalf("%+v", m.shell(t))
if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" ||
!strings.Contains(shell(t, m)[0].Code, `"$HOME/.local/bin/i3bar-watchdog" "$$" &`) {
t.Fatalf("%+v", shell(t, m))
}
}
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)
}
+12 -6
View File
@@ -37,7 +37,11 @@ Three read tools answer what the module stored in its own states, without the gu
forge-account provision's ssh name, so the account's own ssh files and git rewrite are used) into a workspace of the
work directory, then runs `go mod download` and `go mod verify` in every directory with a `go.mod` that does not vendor,
with `GOTOOLCHAIN=local`, `GOFLAGS=-mod=mod` and the module's cache directory. Every command runs with an
environment built from scratch (`StepRunner`): `PATH`, `HOME` and what the step passes.
environment built from scratch (`StepRunner`): `PATH`, `HOME` and what the step passes. The fetch downloads in two
passes: each pinned mesh package from the Go package registry seat alone (`GOPROXY=<seat>,off`; a version the seat does
not hold fails as `the Go package registry holds no <package>@<version>`, and with no binding of the seat the fetch
refuses: `no Go package registry bound`), then the rest of the build list through Go's public proxy alone, never `direct`;
every other go command runs with `GOPROXY=off` (design 47 H, H-A-494).
## Room to work and the workspace's end
@@ -53,11 +57,13 @@ The programs this module builds from a commit and keeps in its cache (composers
asks) are read by `build_go_kept` (kind, key, size, last use) and removed by `build_go_kept_drop {kind, key}`; one no ask used
for 30 days is swept with the workspaces (issue 1921).
A pin on a pull request's head (issue 1148): when `go mod download` fails on a `git.novox.be/novox/*` pseudo-version, the
fetch looks for that commit among the forge's `refs/pull/*/head`, places the repository at it under the workspace's
`pinned/beside/` as a plain directory, and hands it to Go (the fetch's commands, and the build with `GOPROXY=off`) through a
temporary `-modfile` in the workspace's `pins/` that replaces the module by that directory. A pin Go can fetch is left as
it is, a pin on no ref fails naming the module and the commit, and a directory that vendors is never resolved.
A pin on a pull request's head (issue 1148): when the ask pins a mesh package at a commit the Go package registry does not
hold, the fetch looks for that commit among the forge's `refs/pull/*/head`, places the repository at it under the
workspace's `pinned/beside/` as a plain directory, and hands it to Go (the fetch's commands, and the build with
`GOPROXY=off`) through a temporary `-modfile` in the workspace's `pins/` that replaces the module by that directory. A pin
on no ref fails naming the module and the commit, and a directory that vendors is never resolved. A go.mod names a mesh
package at the zero version only: one it names at another version is refused before any download (`<module> names
<package>@<version>; a mesh package is required at the zero version`), never placed (design 47 H, H-A-494).
The asked versions of the mesh's packages (novox/hq ADR 0573 §2, §4; issue 1585): a fetch given `packages` (a full commit
by Go module path, which the builder and the checker fill from the indexer's trunk values or a group's heads) writes each
+104 -56
View File
@@ -194,40 +194,63 @@ func (m *Module) fetchInto(ctx context.Context, req sdkstep.FetchRequest, id str
}
// The directories download side by side, up to the bound (ADR 0536 §2); the first failure in directory order is the
// step's. Resolving a pin places a repository beside the workspace, which two directories may share: one at a time.
// Two passes (design 47 H, H-A-494 addendum): every directory's mesh packages from the Go package registry first,
// then every directory's rest through the public proxy, so the module cache holds each mesh package before any
// download of the rest.
var pins sync.Mutex
errs := make([]error, len(dirs))
taken := make([][]TakenVersion, len(dirs))
slots := make(chan struct{}, m.parallel())
var wg sync.WaitGroup
for i, d := range dirs {
if _, err := os.Stat(filepath.Join(tree, d, "vendor", "modules.txt")); err == nil {
continue // a module that vendors resolves nothing
sideBySide := func(pass func(i int, d string)) {
var wg sync.WaitGroup
for i, d := range dirs {
if _, err := os.Stat(filepath.Join(tree, d, "vendor", "modules.txt")); err == nil {
continue // a module that vendors resolves nothing
}
if errs[i] != nil {
continue // failed in the first pass
}
wg.Add(1)
slots <- struct{}{}
go func() {
defer wg.Done()
defer func() { <-slots }()
pass(i, d)
}()
}
wg.Add(1)
slots <- struct{}{}
go func() {
defer wg.Done()
defer func() { <-slots }()
// The checked repository's own modules come from the fetched tree, at whatever version go.mod names them
// (pins.go takeOwnRequirements; design 47 H, S31).
if taken[i], errs[i] = m.takeOwnRequirements(root, repository, filepath.Join(tree, d), d); errs[i] != nil {
return
}
// The asked versions of the mesh's packages go into the modfile before anything is downloaded (versions.go).
more, err := m.takeVersions(ctx, root, repository, filepath.Join(tree, d), d, req.Packages, &pins)
if taken[i], errs[i] = append(taken[i], more...), err; errs[i] != nil {
return
}
// Then what only a module the directory replaces names, which the download would not miss (pins.go).
more, errs[i] = m.takeReplacedZeroPins(ctx, root, repository, filepath.Join(tree, d), d, req.Packages, taken[i], &pins)
if taken[i] = append(taken[i], more...); errs[i] != nil {
return
}
more, errs[i] = m.downloadModules(ctx, root, repository, filepath.Join(tree, d), d, &pins, req.Packages)
taken[i] = append(taken[i], more...)
}()
wg.Wait()
}
wg.Wait()
sideBySide(func(i int, d string) {
// A mesh package is required at the zero version only: one a go.mod names at another version is refused
// before either download, so the second can never carry a forge path to the public proxy (H-A-494 second addendum).
if errs[i] = namedForgeVersion(repository, filepath.Join(tree, d)); errs[i] != nil {
return
}
// The checked repository's own modules come from the fetched tree, at whatever version go.mod names them
// (pins.go takeOwnRequirements; design 47 H, S31).
if taken[i], errs[i] = m.takeOwnRequirements(root, repository, filepath.Join(tree, d), d); errs[i] != nil {
return
}
// The asked versions of the mesh's packages go into the modfile before anything is downloaded (versions.go).
more, err := m.takeVersions(ctx, root, repository, filepath.Join(tree, d), d, req.Packages, &pins)
if taken[i], errs[i] = append(taken[i], more...), err; errs[i] != nil {
return
}
// Then every requirement at the zero version of the directory's graph the asked versions did not take, its own
// and what only a module it replaces names, taken or refused before any download of the rest, so no forge
// path reaches the public proxy first (pins.go; H-A-494 third addendum).
more, errs[i] = m.takeZeroPinsFirst(ctx, root, repository, filepath.Join(tree, d), d, req.Packages, taken[i], &pins)
taken[i] = append(taken[i], more...)
})
for _, err := range errs {
if err != nil {
return nil, err
}
}
sideBySide(func(i int, d string) {
more, err := m.downloadModules(ctx, root, repository, filepath.Join(tree, d), d, &pins, req.Packages)
taken[i], errs[i] = append(taken[i], more...), err
})
for _, err := range errs {
if err != nil {
return nil, err
@@ -242,10 +265,10 @@ func (m *Module) fetchInto(ctx context.Context, req sdkstep.FetchRequest, id str
return res, nil
}
// downloadModules downloads and verifies the Go modules of the directory dir (d in the tree). A pin of a forge module
// that Go cannot fetch is looked for among the forge's pull request heads and handed to Go by a modfile (pins.go); a
// failure that names no such pin is the first failure. A requirement at the zero version is taken from the asked
// versions (pins.go takeZeroPins).
// downloadModules downloads and verifies the Go modules of the directory dir (d in the tree): the fetch's second
// download, after every mesh package was taken. A requirement at the zero version a failure still names is taken from
// the asked versions (pins.go takeZeroPins); any other failure is the first failure. A version a go.mod names is never
// placed from a pull request's head (H-A-494 third addendum): namedForgeVersion refused it before.
func (m *Module) downloadModules(ctx context.Context, root, repository, dir, d string, pins *sync.Mutex, asked sdkstep.PackageVersions) ([]TakenVersion, error) {
var taken []TakenVersion
for {
@@ -261,13 +284,7 @@ func (m *Module) downloadModules(ctx context.Context, root, repository, dir, d s
if err != nil {
return taken, err
}
pins.Lock()
progress, err := m.resolvePins(ctx, root, dir, failure.Error())
pins.Unlock()
if err != nil {
return taken, err
}
if !progress && len(took) == 0 {
if len(took) == 0 {
return taken, failure
}
}
@@ -444,10 +461,11 @@ func (m *Module) downloadAndVerify(ctx context.Context, dir, d string) error {
}
}
}
cmd, env := []string{"-C", dir, "mod", verb}, m.goEnvFor(dir)
// The second download: the rest of the build list through Go's public proxy alone (publicEnv).
cmd, env := []string{"-C", dir, "mod", verb}, publicEnv(m.goEnvFor(dir))
if modfile, ok := m.pinModfile(dir); ok && verb == "verify" {
// go mod verify takes no -modfile: it is run on the modfile itself, which names the placed repositories.
cmd, env = []string{"-C", filepath.Dir(modfile), "mod", verb}, m.goEnv()
cmd, env = []string{"-C", filepath.Dir(modfile), "mod", verb}, publicEnv(m.goEnv())
}
r := m.Run(ctx, env, "go", cmd...)
if r.Status != 0 || r.Err != "" {
@@ -521,8 +539,10 @@ func inTestdata(path string) bool {
}
// goEnv is what a go command of a step is given beyond the base environment: the installed go alone (GOTOOLCHAIN=local, ADR 0477 §1: no toolchain is ever downloaded),
// modules resolved by their go.mod and go.sum, the module's own caches, the mesh's own modules fetched directly (by
// git, through the account's rewrite of the forge's address to ssh), and nothing that asks a question. For a directory
// modules resolved by their go.mod and go.sum, the module's own caches, the checksum database off for the forge's paths
// (go.sum and the builder's h1: digest guard them, ADR 0605 §6), and no proxy at all (GOPROXY=off): only the fetch's two
// downloads reach the network, each with its own proxy (registryEnv, publicEnv; design 47 H, H-A-494 and its addendum),
// and every other step (the test and lint steps, the compile) reads the module cache the fetch filled. For a directory
// that vendors, see goEnvFor.
func (m *Module) goEnv() []string {
modcache := filepath.Join(m.Cache, "gomod")
@@ -534,20 +554,48 @@ func (m *Module) goEnv() []string {
"GOFLAGS=-mod=mod",
"GOMODCACHE=" + modcache,
"GOCACHE=" + filepath.Join(m.Cache, "gobuild"),
"GONOSUMDB=" + ForgeGoPaths,
"GOPROXY=off",
}
if proxy := m.goSeat(); proxy != "" {
// The Go seat first, the public proxy second, the forge's git last (CAT-BG3, E11: direct goes in the first
// change after mesh-sdk's and mesh-contracts' first numbered versions are in the Go seat); no GOPRIVATE, and
// the checksum database off for the forge's paths, which go.sum and the builder's h1: digest guard instead.
// The seat goes on to the public proxy only on a 404 or 410 (",": a package it does not hold), so a seat that
// fails otherwise (5xx, refused, timeout) fails the fetch loudly; the public proxy goes on to direct on any
// failure ("|"): a public proxy the node cannot reach stopped the fetch before direct, and direct reaches the
// forge's git for a package the seat does not hold (issue 1966, ADR 0605 §6).
env = append(env, "GOPROXY="+proxy+","+PublicGoProxy+"|direct", "GONOSUMDB="+ForgeGoPaths, "GOPRIVATE=")
} else {
env = append(env, "GOPRIVATE="+ForgeGoPaths)
return append(env, m.threadEnv()...)
}
// errNoRegistry is a fetch that needs a mesh package with no binding of the Go package registry seat: the package
// comes from that seat alone (design 47 H, H-A-494), never from the public proxy nor the forge's git.
var errNoRegistry = errors.New("no Go package registry bound")
// registryEnv is env for the fetch's first download, of each pinned mesh package (takeVersion): the Go package registry
// seat alone and nothing behind it (GOPROXY=<seat>,off), so a version the seat does not hold fails as its miss
// (registryMiss), never reaching the public proxy, which serves the forge's paths from git tags, nor the forge's git
// (design 47 H, H-A-494 addendum). With no binding it refuses (errNoRegistry).
func (m *Module) registryEnv(env []string) ([]string, error) {
seat := m.goSeat()
if seat == "" {
return nil, errNoRegistry
}
return append(append(env, "GIT_TERMINAL_PROMPT=0", "GIT_SSH_COMMAND=ssh -o BatchMode=yes"), m.threadEnv()...)
return withProxy(env, seat+",off"), nil
}
// publicEnv is env for the fetch's second download, of the rest of the build list: Go's public proxy alone, no direct
// (design 47 H, H-A-494 addendum). The module cache already holds the mesh packages the first download took, so a forge
// path never reaches the public proxy.
func publicEnv(env []string) []string { return withProxy(env, PublicGoProxy) }
// withProxy is env with its GOPROXY set to proxy, once.
func withProxy(env []string, proxy string) []string {
out := make([]string, 0, len(env)+1)
for _, e := range env {
if !strings.HasPrefix(e, "GOPROXY=") {
out = append(out, e)
}
}
return append(out, "GOPROXY="+proxy)
}
// registryMiss says whether a failure of the first download is the Go package registry seat not holding the version:
// the seat answered 404 or 410, and Go, with nothing behind the seat but off, words it as the lookup off.
func registryMiss(failure string) bool {
return strings.Contains(failure, "disabled by GOPROXY=off") || strings.Contains(failure, "404 Not Found") || strings.Contains(failure, "410 Gone")
}
// PublicGoProxy is Go's public module proxy; ForgeGoPaths the module paths the forge serves.
@@ -556,7 +604,7 @@ const (
ForgeGoPaths = "git.novox.be"
)
// goSeat is the Go seat's proxy URL from its binding (`at`, and `serves` scheme, port and go-path), empty when the
// goSeat is the Go package registry seat's proxy URL from its binding (`at`, and `serves` scheme, port and go-path), empty when the
// module holds no binding of it or the binding names no address.
func (m *Module) goSeat() string {
if m.GoSeatFile == "" {
@@ -95,9 +95,33 @@ func fetchModule(t *testing.T, f *fakeStep) (*Module, *keptStates) {
states := newStates()
m := moduleWith(states, "go1.27.1")
m.Run, m.Home, m.Work, m.Cache = f.run, t.TempDir(), t.TempDir(), t.TempDir()
bindRegistry(t, m)
return m, states
}
// testRegistry is the Go package registry seat's proxy a test binding names (bindRegistry).
const testRegistry = "http://forge.mesh:3000/api/packages/novox/go"
// bindRegistry gives m a binding of the Go package registry seat, as every build node has (go-package-registry).
func bindRegistry(t *testing.T, m *Module) {
t.Helper()
m.GoSeatFile = filepath.Join(t.TempDir(), "go-package-registry.json")
if err := os.WriteFile(m.GoSeatFile, []byte(`{"at":"forge.mesh","serves":{"scheme":"http","port":3000,"go-path":"/api/packages/novox/go"}}`), 0o600); err != nil {
t.Fatal(err)
}
}
// proxyValues are the GOPROXY settings of env.
func proxyValues(env []string) []string {
var out []string
for _, e := range env {
if strings.HasPrefix(e, "GOPROXY=") {
out = append(out, e)
}
}
return out
}
// fetchTool is the fetch tool as a build module is asked, always with its module's directory (A-447b): the root of the
// tree unless the args name one. rawFetchTool is the tool as it is.
func fetchTool(t *testing.T, m *Module) func(map[string]any) (any, error) {
@@ -132,10 +156,20 @@ var fetchArgs = map[string]any{"repository": "novox/mesh-sdk", "commit": commitS
// directory (not in one that vendors) with GOTOOLCHAIN=local, GOFLAGS=-mod=mod and the module's cache paths.
func TestFetchAsksGitForTheSshRemoteAndDownloadsEachModule(t *testing.T) {
// The root go.mod replaces the other two by directory: a fetch asked with a module's directory chooses what it replaces.
// Each Go module requires a mesh package at the zero version, which the ask pins (H-A-494 addendum: the first download).
const contracts = "git.novox.be/novox/mesh-contracts/go/x"
f := &fakeStep{gomods: "go.mod\nsub/dir/go.mod\nvend/go.mod\n", vendors: []string{"vend"},
files: map[string]string{"go.mod": "module fake\nreplace a => ./sub/dir\nreplace b => ./vend\n"}}
files: map[string]string{"go.mod": "module fake\nrequire " + contracts + " " + zeroVersion + "\nreplace a => ./sub/dir\nreplace b => ./vend\n",
"sub/dir/go.mod": "module fake/sub\nrequire " + contracts + " " + zeroVersion + "\n"},
goRule: func(line string) forgekey.Ran {
if strings.Contains(line, " mod download -json "+contracts+"@") {
return forgekey.Ran{Stdout: `{"Path":"` + contracts + `","Version":"v0.1.85","Sum":"h1:zip=","GoModSum":"h1:mod="}`}
}
return forgekey.Ran{}
}}
m, states := fetchModule(t, f)
if _, err := fetchTool(t, m)(fetchArgs); err != nil {
m.Parallel = 1 // one directory at a time, so the order of the commands is the fetch's own
if _, err := fetchTool(t, m)(map[string]any{"repository": "novox/mesh-sdk", "commit": commitSHA, "packages": map[string]any{contracts: "v0.1.85"}}); err != nil {
t.Fatal(err)
}
st := states.waitEnd(t)
@@ -165,27 +199,47 @@ func TestFetchAsksGitForTheSshRemoteAndDownloadsEachModule(t *testing.T) {
if strings.Contains(c.line, "vend") {
t.Errorf("a module that vendors was downloaded: %s", c.line)
}
// The second download (H-A-494 addendum): the rest of the build list through Go's public proxy alone.
env := strings.Join(c.env, " ")
for _, want := range []string{"GOTOOLCHAIN=local", "GOFLAGS=-mod=mod", "GOMODCACHE=" + filepath.Join(m.Cache, "gomod"), "GOCACHE=" + filepath.Join(m.Cache, "gobuild"), "GOPRIVATE=git.novox.be"} {
for _, want := range []string{"GOTOOLCHAIN=local", "GOFLAGS=-mod=mod", "GOMODCACHE=" + filepath.Join(m.Cache, "gomod"), "GOCACHE=" + filepath.Join(m.Cache, "gobuild"), "GOPROXY=" + PublicGoProxy} {
if !strings.Contains(env, want) {
t.Errorf("%s: environment lacks %s: %s", c.line, want, env)
}
}
}
// CAT-BG3: with the Go seat bound, the fetch goes through it first, Go's public proxy second and the forge's git
// last, with no GOPRIVATE and the checksum database off for the forge's paths.
seat := filepath.Join(t.TempDir(), "go-package-registry.json")
if err := os.WriteFile(seat, []byte(`{"at":"forge.mesh","serves":{"scheme":"http","port":3000,"go-path":"/api/packages/novox/go"}}`), 0o600); err != nil {
t.Fatal(err)
}
m.GoSeatFile = seat
env := strings.Join(m.goEnv(), " ")
for _, want := range []string{"GOPROXY=http://forge.mesh:3000/api/packages/novox/go,https://proxy.golang.org|direct", "GONOSUMDB=git.novox.be", "GOPRIVATE= "} {
if !strings.Contains(env+" ", want) {
t.Errorf("with the Go seat bound the environment lacks %q: %s", want, env)
if got := proxyValues(c.env); len(got) != 1 || got[0] != "GOPROXY="+PublicGoProxy {
t.Errorf("%s: GOPROXY settings %v, want the public proxy alone", c.line, got)
}
}
m.GoSeatFile = ""
// Design 51 *Go packages*, H-A-494: no go command of the fetch reaches the forge's git (Go's direct), and none is
// handed GOPRIVATE or the account's ssh; the checksum database stays off for the forge's paths (ADR 0605 §6), and a
// step's own environment has no proxy at all.
for _, c := range f.calls {
if !strings.HasPrefix(c.line, "go ") {
continue
}
for _, e := range c.env {
if strings.HasPrefix(e, "GOPROXY=") && strings.Contains(e, "direct") || strings.HasPrefix(e, "GOPRIVATE=") || strings.HasPrefix(e, "GIT_SSH_COMMAND=") {
t.Errorf("%s: the environment says %s", c.line, e)
}
}
}
// H-A-494 addendum: every download of the Go package registry seat comes before every download through the public proxy.
lastRegistry, firstPublic, registry := -1, -1, 0
for i, c := range f.calls {
switch got := proxyValues(c.env); {
case len(got) == 1 && got[0] == "GOPROXY="+testRegistry+",off":
lastRegistry, registry = i, registry+1
case len(got) == 1 && got[0] == "GOPROXY="+PublicGoProxy && firstPublic < 0:
firstPublic = i
}
}
if registry != 2 || firstPublic < 0 || lastRegistry > firstPublic {
t.Errorf("%d downloads from the seat, the last at %d, the first public at %d: want both directories' seat downloads before every public one:\n%s", registry, lastRegistry, firstPublic, lines)
}
env := strings.Join(m.goEnv(), " ")
if got := proxyValues(m.goEnv()); len(got) != 1 || got[0] != "GOPROXY=off" || !strings.Contains(env, "GONOSUMDB=git.novox.be") {
t.Errorf("a step's environment says GOPROXY %v, want off once, and GONOSUMDB=git.novox.be: %s", got, env)
}
if downloads != 2 || verifies != 2 {
t.Errorf("%d downloads and %d verifies, want 2 each (go.mod and sub/dir/go.mod):\n%s", downloads, verifies, lines)
}
@@ -265,18 +319,18 @@ func TestAVerifyThatFailsEndsTheStepNamingTheDirectoryAndTheLine(t *testing.T) {
loadedModuleMark + "github.com/nats-io/nats.go v1.54.0\n",
tagged: loadedModuleMark + "github.com/nats-io/nats-server/v2 v2.11.17\n",
files: map[string]string{
"tools/go.mod": "module fixture/tools\n\nrequire (\n\tgit.novox.be/novox/mesh-sdk/go " + zeroVersion + "\n\tgithub.com/nats-io/nats.go v1.54.0\n)\n",
"tools/go.mod": "module fixture/tools\n\nrequire (\n\tgit.novox.be/novox/mesh-sdk/go " + zeroVersion + "\n\tgithub.com/nats-io/nats.go v1.54.0\n)\n\nreplace git.novox.be/novox/mesh-sdk/go => ./sdk\n",
"tools/go.sum": "github.com/nats-io/nats.go v1.54.0 h1:a=\ngithub.com/nats-io/nats.go v1.54.0/go.mod h1:b=\n",
},
want: []string{"tools", "go.mod: require github.com/nats-io/nats-server/v2 v2.11.17",
"go.sum: github.com/nats-io/nats-server/v2 v2.11.17 h1:", "go.sum: github.com/nats-io/nats-server/v2 v2.11.17/go.mod h1:"},
notWant: "nats.go"},
// Issue 1966's kind: a mesh module reached only through another, which go.mod does not require, is lacked at the zero
// version (ADR 0573 §2); one go.mod names at a commit (§4) is not.
// version (ADR 0573 §2); one go.mod requires is not.
{name: "a mesh module the load reaches is not required", ran: "tools list -e -deps -test",
out: loadedModuleMark + seatPkg + " " + zeroVersion + "\n" +
loadedModuleMark + "git.novox.be/novox/mesh-sdk/go v0.0.0-20261112000000-0123456789ab\n",
files: map[string]string{"tools/go.mod": "module fixture/tools\n\nrequire git.novox.be/novox/mesh-sdk/go v0.0.0-20261112000000-0123456789ab\n"},
loadedModuleMark + "git.novox.be/novox/mesh-sdk/go " + zeroVersion + " /tree/sdk \n",
files: map[string]string{"tools/go.mod": "module fixture/tools\n\nrequire git.novox.be/novox/mesh-sdk/go " + zeroVersion + "\n\nreplace git.novox.be/novox/mesh-sdk/go => ./sdk\n"},
want: []string{"tools", "go.mod: require " + seatPkg + " " + zeroVersion}, notWant: "mesh-sdk"},
} {
t.Run(c.name, func(t *testing.T) {
@@ -45,6 +45,13 @@ func TestEveryStepEnvironmentSaysGotoolchainLocal(t *testing.T) {
if got := toolchainValues(env); len(got) != 1 || got[0] != "GOTOOLCHAIN=local" {
t.Errorf("%s: GOTOOLCHAIN settings %v, want exactly GOTOOLCHAIN=local", name, got)
}
// H-A-494: a step's own go commands reach no proxy (the test and lint steps, the compile); only the fetch's two
// downloads do, each with its own.
if strings.HasPrefix(name, "goEnv") {
if got := proxyValues(env); len(got) != 1 || got[0] != "GOPROXY=off" {
t.Errorf("%s: GOPROXY settings %v, want exactly GOPROXY=off", name, got)
}
}
// Issue 1806: and its threads, its part of the node's processor cap (probeEnv runs no build).
if procs := strings.Count(strings.Join(env, "\n"), "GOMAXPROCS="); name != "probeEnv" && procs != 1 {
t.Errorf("%s: GOMAXPROCS said %d times, want once: %v", name, procs, env)
@@ -83,9 +83,9 @@ type Module struct {
// Inside is the integration level's own process, started shut off in bubblewrap by a test step (level.go): its
// commands run as they are, never shut off a second time.
Inside bool
// GoSeatFile is the binding of the provision go-package-registry, the Go seat's read side (design 51 *Go
// packages*): bound, the mesh's Go modules are fetched through it first, Go's public proxy second, and the forge's
// git over the account's ssh last (Go's direct, kept for this milestone only); unbound, as before, directly.
// GoSeatFile is the binding of the provision go-package-registry, the Go package registry seat's read side (design
// 51 *Go packages*): the mesh's Go packages are fetched through it alone (design 47 H, H-A-494); unbound, a fetch
// that needs one refuses (errNoRegistry).
GoSeatFile string
// ArtifactStoreFile is the binding of the provision artifact-store, read for a group run's package members (§465).
ArtifactStoreFile string
+69 -55
View File
@@ -1,12 +1,13 @@
package main
// Pins on a pull request's head (novox/hq ADR 0482 §2, ADR 0500 §2; issue 1148): a group's Go members pin the head of
// the group's mesh-sdk pull request, a commit that only refs/pull/<n>/head of the forge carries until the merge. Go
// cannot fetch it by its pseudo-version, so a fetch that meets "unknown revision" for such a pin finds the commit among
// the forge's pull request heads, places that repository beside the workspace as a plain directory, and hands it to
// Go through a temporary -modfile, a copy of the directory's go.mod that replaces the module by that directory. The
// fetch's go commands and the build use the same modfile, and the build still runs with GOPROXY=off. A pin Go can
// fetch is not touched, and a directory that vendors is never resolved.
// Pins on a pull request's head (novox/hq ADR 0482 §2, ADR 0500 §2, ADR 0573 §4; issue 1148): a group's check asks a
// mesh package at the head of the group's pull request, a commit that only refs/pull/<n>/head of the forge carries until
// the merge. The Go package registry does not hold it, so the fetch finds the commit among the forge's pull request
// heads, places that repository beside the workspace as a plain directory, and hands it to Go through a temporary
// -modfile, a copy of the directory's go.mod that replaces the module by that directory. The fetch's go commands and
// the build use the same modfile, and the build still runs with GOPROXY=off. Only a pin the ask gives as a commit is
// placed; a version a go.mod names is refused, never placed (design 47 H, H-A-494 second and third addenda), and a
// directory that vendors is never resolved.
import (
"context"
@@ -111,44 +112,6 @@ func (m *Module) pinModfile(dir string) (string, bool) {
return p, err == nil
}
// resolvePins resolves the pins of dir that a go command failed on: those whose commit the failure names. It answers
// false when there is none, and the failure is then the caller's.
func (m *Module) resolvePins(ctx context.Context, root, dir, failure string) (bool, error) {
raw, err := os.ReadFile(filepath.Join(dir, "go.mod"))
if err != nil {
return false, nil
}
modfile, _ := m.pinModfile(dir)
done := ""
if modfile != "" {
if b, err := os.ReadFile(modfile); err == nil {
done = string(b)
}
}
progress := false
for _, p := range forgePins(string(raw)) {
if p.short == zeroShort {
continue // takeZeroPins': a requirement at the zero version names no commit to look for
}
if !strings.Contains(failure, p.short) || strings.Contains(done, "replace "+p.module+" =>") {
continue
}
where, err := m.placePin(ctx, root, p, failure)
if errors.Is(err, errNotAHead) {
// On no pull request head: go's failure is the caller's, in go's own words (issue 1748).
continue
}
if err != nil {
return false, err
}
if err := m.replaceInModfile(dir, p.module, where); err != nil {
return false, err
}
progress = true
}
return progress, nil
}
// errNotAHead is a pin whose commit no pull request head of the forge carries, when go's failure was not go knowing no
// such revision: the failure is the network's or the forge's, and the caller says it in go's words (issue 1748).
var errNotAHead = errors.New("on no pull request head")
@@ -359,21 +322,72 @@ func (m *Module) takeZeroPins(ctx context.Context, root, repository, dir, d, fai
return m.takeZeroRequirements(ctx, root, repository, dir, d, zeroRequirementsOf(dir), asked, pins)
}
// takeReplacedZeroPins takes, before anything is downloaded, the requirements at the zero version that only a module
// dir replaces by a directory names (zeroRequirementsOf): go mod download loads only what dir's own go.mod names, so it
// passes without them, and the shut-off steps would look them up on the network (issue 1966). One the asked versions
// took (before, takeVersions) is left as it is.
func (m *Module) takeReplacedZeroPins(ctx context.Context, root, repository, dir, d string, asked sdkstep.PackageVersions, before []TakenVersion, pins *sync.Mutex) ([]TakenVersion, error) {
var replaced []zeroRequirement
// takeZeroPinsFirst takes or refuses, before anything else is downloaded, every requirement at the zero version of
// dir's module graph (zeroRequirementsOf) the asked versions did not take (before, takeVersions): dir's own, and those
// only a module dir replaces by a directory names, which go mod download would not miss and the shut-off steps would
// look up on the network (issue 1966). So no forge path reaches the second download, the public proxy's, first (design
// 47 H, H-A-494 third addendum).
func (m *Module) takeZeroPinsFirst(ctx context.Context, root, repository, dir, d string, asked sdkstep.PackageVersions, before []TakenVersion, pins *sync.Mutex) ([]TakenVersion, error) {
raw, _ := os.ReadFile(filepath.Join(dir, "go.mod"))
_, replaced := goModRequirements(string(raw))
var reqs []zeroRequirement
for _, r := range zeroRequirementsOf(dir) {
if r.by != "" && !slices.ContainsFunc(before, func(tv TakenVersion) bool { return tv.Package == r.module }) {
replaced = append(replaced, r)
// One dir's go.mod replaces is decided by its replace.
if !replaced[r.module] && !slices.ContainsFunc(before, func(tv TakenVersion) bool { return tv.Package == r.module }) {
reqs = append(reqs, r)
}
}
if len(replaced) == 0 {
if len(reqs) == 0 {
return nil, nil
}
return m.takeZeroRequirements(ctx, root, repository, dir, d, replaced, asked, pins)
return m.takeZeroRequirements(ctx, root, repository, dir, d, reqs, asked, pins)
}
// namedForgeVersion refuses a mesh package (a module of the forge) that dir's module graph names at a version other
// than the zero version (ADR 0573 §4; design 47 H, H-A-494 second addendum), in the graph zeroRequirementsOf reads: dir's
// go.mod, then each module it replaces by a directory. A module of the checked repository (built from its tree) and one
// dir's go.mod replaces are left out. The first such requirement is named, before either download.
func namedForgeVersion(repository, dir string) error {
raw, err := os.ReadFile(filepath.Join(dir, "go.mod"))
if err != nil {
return nil
}
_, replaced := goModRequirements(string(raw))
check := func(gomod string) error {
required, _ := goModRequirements(gomod)
for _, pkg := range slices.Sorted(maps.Keys(required)) {
v := required[pkg]
if !strings.HasPrefix(pkg, forgePrefix) || v == zeroVersion || replaced[pkg] || sameRepository(pkg, repository) {
continue
}
return fmt.Errorf("%s names %s@%s; a mesh package is required at the zero version", modulePathOf(gomod), pkg, v)
}
return nil
}
if err := check(string(raw)); err != nil {
return err
}
local := localReplaces(string(raw))
for _, module := range slices.Sorted(maps.Keys(local)) {
b, err := os.ReadFile(filepath.Join(dir, filepath.FromSlash(local[module]), "go.mod"))
if err != nil {
continue // a replace to a directory with no go.mod: Go says so in its own words
}
if err := check(string(b)); err != nil {
return err
}
}
return nil
}
// modulePathOf is the module path a go.mod declares, "" when it declares none.
func modulePathOf(gomod string) string {
for _, line := range strings.Split(gomod, "\n") {
if f := strings.Fields(line); len(f) >= 2 && f[0] == "module" {
return strings.Trim(f[1], `"`)
}
}
return ""
}
// takeZeroRequirements takes, for each requirement at the zero version, the version it is built against (ADR 0573 §2,
@@ -17,9 +17,9 @@ import (
)
// 1148/AC2 as issue 1585 S15 has it (novox/hq ADR 0573 §4): given a forge with a mesh-sdk-like pull request whose branch
// is deleted (only refs/pull/7/head carries its commit) and a Go member whose go.mod names an older commit of it, when
// is deleted (only refs/pull/7/head carries its commit) and a Go member whose go.mod names it at the zero version, when
// build_go_fetch is asked that head as the package's version and build_go_build runs on the member, then both pass, the
// build with GOPROXY=off against the head: the older commit holds no Go package at all.
// build with GOPROXY=off against the head (a go.mod names a mesh package at the zero version only, design 47 H, H-A-494).
func TestRealFetchAndBuildOfAMemberAskedAPullHeadItsGoModDoesNotName(t *testing.T) {
t.Parallel()
// Not skipped when a tool is missing: a pass of the check must mean this test ran (the check prints no test log).
@@ -36,7 +36,7 @@ func TestRealFetchAndBuildOfAMemberAskedAPullHeadItsGoModDoesNotName(t *testing.
}, "refs/pull/7/head")
git(t, work, "checkout", "-q", "main") // no branch of the repository carries the head
member := map[string]string{
"go.mod": "module fixture/member\n\ngo 1.25.0\n\nrequire git.novox.be/novox/dep/go v0.0.0-20261021120000-" + fork[:12] + "\n",
"go.mod": "module fixture/member\n\ngo 1.25.0\n\nrequire git.novox.be/novox/dep/go " + zeroVersion + "\n",
"cmd/prog/main.go": "package main\n\nimport (\n\t\"fmt\"\n\n\tdep \"git.novox.be/novox/dep/go\"\n)\n\n" +
"func main() { fmt.Println(dep.Name) }\n",
"module.json": `{"module":"fixture-member","version":"1","build":{"artifacts":[{"name":"tools","kind":"bundle","language":"go","system":"arch","from":"cmd/prog","binary":"prog-bin","loads":["prog-bin"]}]}}`,
@@ -50,7 +50,7 @@ func TestRealFetchAndBuildOfAMemberAskedAPullHeadItsGoModDoesNotName(t *testing.
if st.State != sdkstep.StepPassed {
t.Fatalf("the fetch ended %s: %s", st.State, st.Reason)
}
if len(res.Packages) != 1 || res.Packages[0].Built != head || res.Packages[0].Named != "v0.0.0-20261021120000-"+fork[:12] {
if len(res.Packages) != 1 || res.Packages[0].Built != head || res.Packages[0].Named != zeroVersion {
t.Errorf("the fetch names what it built against: %+v, want the asked head %s", res.Packages, head)
}
if _, err := os.Stat(filepath.Join(m.Work, res.Workspace, "pinned", "dep@"+head, "beside", "dep", "go", "dep.go")); err != nil {
@@ -18,7 +18,11 @@ import (
// pinShort is the 12 digits of commitSHA a pseudo-version ends in.
const pinShort = "0123456789ab"
const pinnedGoMod = "module fixture/member\n\ngo 1.26\n\nrequire (\n\tgit.novox.be/novox/mesh-sdk/go v0.1.15-0.20261022120000-" + pinShort + "\n)\n"
// pinnedGoMod requires mesh-sdk at the zero version (ADR 0573 §4); the ask pins it (pinAsk).
const pinnedGoMod = "module fixture/member\n\ngo 1.26\n\nrequire (\n\tgit.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-" + zeroShort + "\n)\n"
// pinAsk asks mesh-sdk at the head of a group's pull request, commitSHA: only refs/pull/7/head of pullList carries it.
var pinAsk = map[string]any{"git.novox.be/novox/mesh-sdk/go": commitSHA}
// pinHarness runs a fetch of a tree whose only go.mod is gomod (a vendoring one when vendor is set) against a runner
// that stands for the forge and for go: a pull request's head is listed by ls-remote when pulls says so, and go mod
@@ -84,7 +88,7 @@ func (h *pinHarness) fetch(states *keptStates) (FetchResult, sdkstep.Step) {
h.t.Helper()
// A member of a repository other than mesh-sdk's, whose packages it pins: one of its own repository is built from the
// tree (S31).
if _, err := fetchTool(h.t, h.m)(map[string]any{"repository": "novox/mesh-member", "commit": commitSHA}); err != nil {
if _, err := fetchTool(h.t, h.m)(map[string]any{"repository": "novox/mesh-member", "commit": commitSHA, "packages": pinAsk}); err != nil {
h.t.Fatal(err)
}
st := states.waitEnd(h.t)
@@ -149,26 +153,40 @@ func TestAPinOnAPullHeadIsPlacedBesideAndHandedToGoByAModfile(t *testing.T) {
}
}
// 1148/AC3: a pin go downloads as it is (on the trunk or a tag) behaves as today: no listing of pull requests, no
// repository placed, no -modfile in the fetch or the build.
func TestAPinGoCanDownloadIsLeftAsToday(t *testing.T) {
h, states := newPinHarness(t, pinnedGoMod, false, pullList)
h.onTrunk = true
res, st := h.fetch(states)
if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
// H-A-494 second addendum: a go.mod naming a mesh package at a version other than the zero version (a pseudo-version, a
// release) is refused before either download, naming the module and the version, whether its own go.mod names it or a
// module it replaces by a directory; a module of the checked repository, and one the go.mod replaces, are not refused.
func TestAMeshPackageNamedAtARealVersionIsRefusedBeforeEitherDownload(t *testing.T) {
const sdk = "git.novox.be/novox/mesh-sdk/go"
for _, c := range []struct{ name, gomod, sib, refused string }{
{name: "a pseudo-version", gomod: "module fixture/member\n\nrequire " + sdk + " v0.1.15-0.20261022120000-" + pinShort + "\n",
refused: "fixture/member names " + sdk + "@v0.1.15-0.20261022120000-" + pinShort + "; a mesh package is required at the zero version"},
{name: "a release named by a module it replaces", gomod: "module fixture/member\n\nrequire fixture/sib " + zeroVersion + "\n\nreplace fixture/sib => ./sib\n",
sib: "module fixture/sib\n\nrequire " + sdk + " v0.1.85\n", refused: "fixture/sib names " + sdk + "@v0.1.85"},
{name: "replaced by the go.mod", gomod: "module fixture/member\n\nrequire " + sdk + " v0.1.85\n\nreplace " + sdk + " => ./sdk\n"},
{name: "of the checked repository", gomod: "module fixture/member\n\nrequire git.novox.be/novox/mesh-member/go v0.1.85\n"},
} {
t.Run(c.name, func(t *testing.T) {
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "go.mod"), []byte(c.gomod), 0o644)
if c.sib != "" {
os.MkdirAll(filepath.Join(dir, "sib"), 0o755)
os.WriteFile(filepath.Join(dir, "sib", "go.mod"), []byte(c.sib), 0o644)
}
err := namedForgeVersion("novox/mesh-member", dir)
if (err != nil) != (c.refused != "") || (err != nil && !strings.Contains(err.Error(), c.refused)) {
t.Fatalf("refused: %v, want %q", err, c.refused)
}
})
}
if h.ran("ls-remote") || h.ran("pinned") {
t.Errorf("a pin on the trunk made the fetch look for a pull request or place a repository:\n%s", strings.Join(h.f.lines(), "\n"))
// In a fetch: the step fails so, and runs no download at all.
h, states := newPinHarness(t, "module fixture/member\n\nrequire "+sdk+" v0.1.85\n", false, pullList)
_, st := h.fetch(states)
if st.State != sdkstep.StepFailed || !strings.Contains(st.Reason, "fixture/member names "+sdk+"@v0.1.85; a mesh package is required at the zero version") {
t.Fatalf("the step ended %s: %q", st.State, st.Reason)
}
dir := filepath.Join(h.m.Work, res.Workspace, "tree")
for _, e := range append(h.m.goEnvFor(dir), h.m.buildEnv(dir)...) {
if strings.Contains(e, "-modfile") {
t.Errorf("a -modfile is handed to go: %s", e)
}
}
if !h.ran(" mod download") || !h.ran(" mod verify") {
t.Errorf("go mod download and verify did not run as before")
if h.ran(" mod download") || h.ran("ls-remote") {
t.Errorf("a download or a listing ran before the refusal:\n%s", strings.Join(h.f.lines(), "\n"))
}
}
@@ -225,42 +243,6 @@ func TestTwoDirectoriesPinningOneHeadShareOneCopy(t *testing.T) {
}
}
// 1148/AC1: two directories pinning two different commits of one repository get two copies, each its own.
func TestTwoCommitsOfOneRepositoryGetTwoCopies(t *testing.T) {
other := "fedcba9876543210fedcba9876543210fedcba98"
h, states := newPinHarness(t, pinnedGoMod, false, commitSHA+"\trefs/pull/7/head\n"+other+"\trefs/pull/8/head\n")
h.f.gomods = "go.mod\nsub/go.mod\n"
base := h.m.Run
h.m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
if name == "git" && strings.Contains(strings.Join(args, " "), "pinned/mesh-sdk@"+other+"/") && strings.Contains(strings.Join(args, " "), " rev-parse HEAD") {
return forgekey.Ran{Stdout: other + "\n"}
}
// the second directory pins the other commit
if name == "git" && strings.Contains(strings.Join(args, " "), " checkout ") && !strings.Contains(strings.Join(args, " "), "pinned") {
r := base(ctx, env, name, args...)
for i, a := range args {
if a == "-C" {
os.WriteFile(filepath.Join(args[i+1], "sub", "go.mod"), []byte(strings.ReplaceAll(pinnedGoMod, pinShort, other[:12])), 0o644)
}
}
return r
}
if name == "go" && strings.Contains(strings.Join(args, " "), "/sub mod download") && !strings.Contains(strings.Join(env, " "), "-modfile=") {
return forgekey.Ran{Status: 1, Stderr: "go: git.novox.be/novox/mesh-sdk/go@v0.1.15-0.20261022120000-" + other[:12] + ": invalid version: unknown revision " + other[:12] + "\n"}
}
return base(ctx, env, name, args...)
}
_, st := h.fetch(states)
if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
}
for _, c := range []string{commitSHA, other} {
if !h.ran("pinned/mesh-sdk@" + c) {
t.Errorf("no copy of mesh-sdk at %s", c)
}
}
}
// A relative replace of a go.mod (a package of the module's own repository in a sibling directory, ADR 0593 §1) must still
// resolve in the temporary modfile, which `go mod verify` runs in its own directory: every relative target is made absolute
// under the tree it came from. The route-proxy failure of 2026-11-02 13:53 was a ./ replace met there; this takes real go.
@@ -340,8 +322,13 @@ func TestARequirementAtTheZeroVersionIsTakenFromItsPinOrRefused(t *testing.T) {
}
h, states := newPinHarness(t, gomod, false, pullList)
base := h.m.Run
var mu sync.Mutex
var ran []string // every command, in order
h.m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
line := name + " " + strings.Join(args, " ")
mu.Lock()
ran = append(ran, line)
mu.Unlock()
switch {
case c.replaced && name == "git" && strings.Contains(line, " checkout "):
r := base(ctx, env, name, args...)
@@ -381,6 +368,12 @@ func TestARequirementAtTheZeroVersionIsTakenFromItsPinOrRefused(t *testing.T) {
if h.ran(" mod download -json " + sdk + "@") {
t.Errorf("go was asked for a version of %s with no pin:\n%s", sdk, strings.Join(h.f.lines(), "\n"))
}
// H-A-494 third addendum: refused before any download of the rest, so no forge path reaches the public proxy.
for _, line := range ran {
if strings.HasSuffix(line, " mod download") {
t.Errorf("the rest was downloaded before the refusal: %s", line)
}
}
return
}
if st.State != sdkstep.StepPassed {
@@ -127,9 +127,18 @@ func (m *Module) takeVersion(ctx context.Context, root, dir string, tv *TakenVer
tagged := sdkstep.PackageSemver.MatchString(tv.Asked)
var r forgekey.Ran
var info downloadInfo
r = m.Run(ctx, m.goEnv(), "go", "-C", pinsDir, "mod", "download", "-json", tv.Package+"@"+tv.Asked)
// The first download: a mesh package from the Go package registry seat alone (design 47 H, H-A-494 and its addendum).
env, err := m.registryEnv(m.goEnv())
if err != nil {
return fmt.Errorf("%s@%s: %w", tv.Package, tv.Asked, err)
}
r = m.Run(ctx, env, "go", "-C", pinsDir, "mod", "download", "-json", tv.Package+"@"+tv.Asked)
_ = json.Unmarshal([]byte(r.Stdout), &info)
failed := r.Status != 0 || r.Err != "" || info.Version == "" || info.Error != ""
if failed && registryMiss(info.Error+"\n"+r.Err+"\n"+r.Stderr) && !commitOK.MatchString(tv.Asked) {
// Only a commit may still be a pull request's head (placePin); any other version the seat does not hold is its miss.
return registryMissed(tv.Package, tv.Asked, info.Error+"\n"+r.Err+"\n"+r.Stderr)
}
if failed && tagged {
failure := strings.TrimSpace(info.Error + "\n" + r.Err + "\n" + r.Stderr)
return downloadFailure(failure, "downloading the group's tagged version %s of %s through the Go seat failed", tv.Asked, tv.Package)
@@ -148,6 +157,9 @@ func (m *Module) takeVersion(ctx context.Context, root, dir string, tv *TakenVer
where, err := m.placePin(ctx, root, p, failure)
if errors.Is(err, errNotAHead) {
pins.Unlock()
if registryMiss(failure) {
return registryMissed(tv.Package, tv.Asked, failure)
}
// On no head, and go failed for another cause (the forge or the resolver did not answer): it fails with go's own
// words, and not as a kind the builder holds until the module changes (issue 1748).
return downloadFailure(failure, "downloading the asked version %s of %s failed", tv.Asked, tv.Package)
@@ -188,6 +200,12 @@ func (m *Module) takeVersion(ctx context.Context, root, dir string, tv *TakenVer
return m.takeRequirementsOf(ctx, pinsDir, info.GoMod)
}
// registryMissed is the first download's miss: the Go package registry seat holds no such version of the package, said
// in the module's words with Go's beside them (design 47 H, H-A-494: a missing version fails loudly as the registry's miss).
func registryMissed(pkg, version, failure string) error {
return fmt.Errorf("the Go package registry holds no %s@%s: %s", pkg, version, causeLine(strings.TrimSpace(failure)))
}
// appendSums writes the checksums of one download (the module's and its go.mod's) into the go.sum in pinsDir.
func appendSums(pinsDir, module string, info downloadInfo) error {
sums := ""
@@ -232,7 +250,8 @@ func (m *Module) takeRequirementsOf(ctx context.Context, pinsDir, gomodPath stri
if strings.HasPrefix(module, forgePrefix) || (named[module] != "" && compareVersions(named[module], version) >= 0) {
continue
}
r := m.Run(ctx, m.goEnv(), "go", "-C", pinsDir, "mod", "download", "-json", module+"@"+version)
// Never a module of the forge (above): the rest of the build list, through Go's public proxy alone (publicEnv).
r := m.Run(ctx, publicEnv(m.goEnv()), "go", "-C", pinsDir, "mod", "download", "-json", module+"@"+version)
var info downloadInfo
_ = json.Unmarshal([]byte(r.Stdout), &info)
if r.Status != 0 || r.Err != "" || info.Version == "" || info.Error != "" {
@@ -32,6 +32,7 @@ func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
passing bool // the step ends failed as a transport fault, which the bus gives again (ADR 0664 §1)
downloads int // the downloads asked in all (0: not counted)
requires string // the go.mod of the version taken, its requirements to be taken too
unbound bool // the module holds no binding of the Go package registry seat
}{
{name: "a trunk commit newer than go.mod's", asked: trunk,
answer: `{"Path":"` + sdk + `","Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip=","GoModSum":"h1:mod="}`,
@@ -42,9 +43,6 @@ func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
answer: `{"Path":"` + sdk + `","Version":"v0.1.16-0.20261116170327-aaaaaaaaaaaa","Sum":"h1:zip=","GoModSum":"h1:mod=","GoMod":"GOMOD"}`,
built: "v0.1.16-0.20261116170327-aaaaaaaaaaaa", edit: "-require=" + sdk + "@v0.1.16-0.20261116170327-aaaaaaaaaaaa",
requires: "module " + sdk + "\n\ngo 1.26\n\nrequire (\n\tgithub.com/nats-io/nats.go v1.54.0\n\tgithub.com/klauspost/compress v1.20.0\n\tgit.novox.be/novox/mesh-contracts/go/x v0.1.0\n)\n"},
{name: "go.mod names a newer one", asked: trunk,
answer: `{"Path":"` + sdk + `","Version":"v0.1.15-0.20261001000000-aaaaaaaaaaaa","Sum":"h1:zip="}`,
built: "v0.1.15-0.20261022120000-" + pinShort, said: "newer than the asked"},
{name: "a group's head Go cannot fetch", asked: commitSHA, failing: true,
answer: `{"Path":"` + sdk + `","Error":"invalid version: unknown revision ` + pinShort + `"}`,
built: commitSHA, said: "placed from the pull request's head"},
@@ -70,11 +68,17 @@ func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
{name: "a group's tagged version", asked: "v0.1.15-feat-x.2",
answer: `{"Path":"` + sdk + `","Version":"v0.1.15-feat-x.2","Sum":"h1:zip=","GoModSum":"h1:mod="}`,
built: "v0.1.15-feat-x.2", edit: "-require=" + sdk + "@v0.1.15-feat-x.2"},
{name: "a group's tagged version older than go.mod's", asked: "v0.1.14-feat-x.2",
answer: `{"Path":"` + sdk + `","Version":"v0.1.14-feat-x.2","Sum":"h1:zip=","GoModSum":"h1:mod="}`,
built: "v0.1.14-feat-x.2", said: "the group's tagged version", edit: "-require=" + sdk + "@v0.1.14-feat-x.2"},
{name: "a tagged version the Go seat lacks", asked: "v0.1.15-feat-x.3", failing: true, failsWith: "the group's tagged version v0.1.15-feat-x.3",
// H-A-494: a version the Go package registry seat does not hold fails as its miss, naming <pkg>@<v>: the seat's 404,
// or, as Go words it with off behind the seat, the lookup off; a commit only once no pull request head carries it.
{name: "a tagged version the Go seat lacks", asked: "v0.1.15-feat-x.3", failing: true, failsWith: "the Go package registry holds no " + sdk + "@v0.1.15-feat-x.3",
answer: `{"Path":"` + sdk + `","Error":"` + sdk + `@v0.1.15-feat-x.3: reading https://seat/go/@v/v0.1.15-feat-x.3.info: 404 Not Found"}`},
{name: "a release the Go seat lacks", asked: "v0.1.85", failing: true, failsWith: "the Go package registry holds no " + sdk + "@v0.1.85", downloads: 1,
answer: `{"Path":"` + sdk + `","Error":"` + sdk + `@v0.1.85: module lookup disabled by GOPROXY=off"}`},
{name: "a commit the Go seat lacks on no head", asked: offHead, failing: true, failsWith: "the Go package registry holds no " + sdk + "@" + offHead, downloads: 1,
answer: `{"Path":"` + sdk + `","Error":"` + sdk + `@` + offHead + `: module lookup disabled by GOPROXY=off"}`},
// H-A-494: with no binding of the seat, a mesh package is fetched from nowhere else: the fetch refuses.
{name: "no Go package registry bound", asked: trunk, unbound: true, failsWith: "no Go package registry bound",
answer: `{"Path":"` + sdk + `","Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip=","GoModSum":"h1:mod="}`},
// ADR 0664 §1 (issue 1748): one download; a failure of the network is a transport fault the bus gives the ask again for after a
// delay, no retry here; another failure is not one.
{name: "an unknown revision is not taken again", asked: offHead, failing: true, failsWith: "on no pull request head", downloads: 1,
@@ -85,6 +89,9 @@ func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
h, states := newPinHarness(t, pinnedGoMod, false, pullList)
h.f.gomods = "go.mod\nother/go.mod\n"
if c.unbound {
h.m.GoSeatFile = ""
}
downloads := 0
base := h.m.Run
h.m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
@@ -130,6 +137,14 @@ func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
t.Fatal(err)
}
st := states.waitEnd(t)
// H-A-494 addendum: a mesh package is downloaded from the Go package registry seat alone, off behind it.
for _, cmd := range h.cmds {
if strings.Contains(cmd.line, " mod download -json "+sdk+"@") {
if got := proxyValues(cmd.env); len(got) != 1 || got[0] != "GOPROXY="+testRegistry+",off" {
t.Errorf("%s: GOPROXY settings %v, want the seat alone and off", cmd.line, got)
}
}
}
if c.downloads != 0 && downloads != c.downloads {
t.Errorf("go downloaded %d times, want %d: no retry here", downloads, c.downloads)
}
@@ -167,7 +167,8 @@ func (m *Module) downloadBeside(ctx context.Context, root, tree string, dirs []s
if err := os.WriteFile(file, []byte(work), 0o600); err != nil {
return err
}
env := append(m.goEnv(), "GOWORK="+file, "GOFLAGS=-mod=readonly") // a workspace takes no -mod=mod
// The rest of a build list: through Go's public proxy alone (publicEnv; design 47 H, H-A-494 addendum).
env := publicEnv(append(m.goEnv(), "GOWORK="+file, "GOFLAGS=-mod=readonly")) // a workspace takes no -mod=mod
if res := m.Run(ctx, env, "go", "-C", r, "mod", "download"); res.Status != 0 || res.Err != "" {
return fmt.Errorf("go mod download of the graph of %s beside: %s", filepath.Base(r), causeLine(res.Err+"\n"+res.Stdout+"\n"+res.Stderr))
}
+16 -12
View File
@@ -35,21 +35,24 @@ puts the call on the bus, as every agent session on the machine does. The consol
- **Who judges.** The seat that owns the job: a change of assignments is a proposal the operator approves
(`mesh-module-assigner.propose`), a config value is set with its why (`mesh-config.config`), a silence or a hand act is
recorded as one. Until novox/hq issue 1126 the controller ran these lines and judged the account (ADR 0272); with
the controller unassigned, that judgement went with it.
- **The map.** Every line the controller ran, and the seat verb or tool that does its job now, or none, is
`commands.go`'s table (and hq's `.work/1126/nox-map.md` while issue 1126 runs). A line no seat or module owns says
that it was the controller's, that the controller is unassigned, and what to use instead, and exits 1 having called
nothing. A line nox cannot read says how it is written and exits 2.
recorded as one.
- **The map.** Every line nox takes, and the seat verb or tool that does its job, is `commands.go`'s table. A line
nox does not know, or cannot read, says so and how lines are found or written, and exits 2 having called nothing.
- **Any address.** `nox call <address> [json]` calls any seat verb or tool; `nox search <words>` and
`nox describe <address>` find one and its arguments.
- **What is printed.** The owner's answer as the console gave it (JSON), on standard output with exit 0; an answer the
- **What is printed.** The owner's answer as the console gave it (JSON), or the line's table (`nox nodes`,
`nox licence`, `nox licence usage`; `--json` prints the answer raw), on standard output with exit 0; an answer the
console marks an error (a refusal, nothing serving, no answer within its bound) on standard error with exit 1. A
console that does not answer is said as nothing having been called; no answer in time is said as a call that may
have run.
- **`nox status`** is the delivery view's (`mesh-delivery-view.view_status`). When the view does not answer, nox says
so first, shows the open conditions and the deliveries under their own addresses, and exits 1: they are never
passed off as the status.
- **`nox licence`** (and `nox licence list`) is the operator's overview of the licences in one line
(one-question-one-tool): the licence manager's `licences` as one table (licence, kind, bound nodes, weekly, session
and sonnet usage with their resets, the token's expiry, failures, conditions, whether it is the target), then its
`bindings` (node, licence, since, why), every time local; with `--json` the two answers as one object
`{licences, bindings}`. `nox licence usage [<licence>]` is the manager's `usage` readings as a table.
- **`nox enrol open --key <file>`** runs here and asks nothing of the mesh (ADR 0587 §8).
A process that runs for a verb (it carries `MESH_VERB`) is refused before anything is called: a verb is never the
@@ -57,15 +60,16 @@ operator.
## What it does not do yet
- **No formatting beyond `nox nodes`.** Answers are the owners' JSON.
- **Lines with no owner.** Accepting a secret from a person, making or setting the operator key, opening a sealed
secret locally, registering a module from another repository and forgetting a module have no seat verb yet; nox
names what to use meanwhile.
- **No formatting beyond `nox nodes` and the licence lines.** Answers are the owners' JSON.
- **No line without a seat verb.** Accepting a secret from a person, making or setting the operator key, opening a
sealed secret locally, registering a module from another repository and forgetting a module have no seat verb yet,
so nox has no line for them.
## Tests
`go test ./...`: every owned line calls its owner's address with the arguments it reads, against a stand-in console
answering MCP `tools/call` as node-tools does; a line with no owner or not read calls nothing and says why; an error
answering MCP `tools/call` as node-tools does; a line not known or not read calls nothing and says why; the licence
lines print their tables from the manager's answers; an error
answer, a silent console and a verb's process are said; the status's fallback is labelled and exits 1; the console's
address is found; `enrol open` opens a sealed token locally; the module places the program and the console's address
and nothing else.
+22 -36
View File
@@ -1,8 +1,7 @@
package main
// Every command line nox takes, and the seat verb or module tool that owns its job now that the controller is
// unassigned (novox/hq issue 1126; the map is hq's .work/1126/nox-map.md). A line no seat or module owns says so and
// names what to use instead: it never fails silently, and it never pretends to have run.
// Every command line nox takes, and the seat verb or module tool that owns its job. A line nox does not know says so
// and calls nothing: it never fails silently, and it never pretends to have run.
import (
"encoding/json"
@@ -93,18 +92,25 @@ type command struct {
words []string
usage string
does string
// build reads the line and answers the call; nil for a line no seat owns.
// build reads the line and answers the call.
build func(l line) (call, error)
// allowed are the flags the line reads; any other is refused before anything is called.
allowed []string
// instead says, for a line with no owner, what to use; empty for one that is owned.
instead string
// render shapes a successful answer for reading; nil prints it as the console gave it.
// render shapes a successful answer for reading; nil prints it as the console gave it. With --json the answer is
// printed raw.
render func(text string) string
// also is a second call the line makes after the first, its answer read beside the first's; nil for a line of one
// call.
also *second
}
// gone is the reason every unowned line gives.
const gone = "this was the controller's, and the controller is unassigned (novox/hq issue 1126). Nothing was called"
// second is a line's second call: its address, asked with no arguments, the keys the two raw answers are printed
// under with --json, and the render that reads both answers.
type second struct {
address string
keys [2]string
render func(first, second string) string
}
// commands is every line, longest words first within a word.
var commands = []command{
@@ -120,8 +126,6 @@ var commands = []command{
{words: []string{"node", "public-domain"}, usage: "<node> [<domain> | --clear] [--why <text>]",
does: "the domain a node composes its routed names under; with a domain or --clear, proposed to assignments",
allowed: []string{"clear", "why"}, build: publicDomain},
{words: []string{"node", "add"}, instead: "a new machine joins through the seat mesh-node-enroller: nox enrol issue <node> --why <text>"},
{words: []string{"node", "networks"}, instead: "no seat keeps a node's routed networks yet; mesh-module-assigner.assignments shows what a node decides"},
{words: []string{"plan"}, usage: "<node>", does: "what the assigner wants the node to run", build: optNode("mesh-delivery-view.assigner_wants")},
{words: []string{"haves"}, usage: "[<node>]", does: "what each node runs, as its node-engine said", build: optNode("mesh-delivery-view.node_haves")},
{words: []string{"switch"}, does: "what each node runs, as its node-engine said", build: fixed("mesh-delivery-view.node_haves")},
@@ -135,7 +139,6 @@ var commands = []command{
{words: []string{"seats"}, does: "who holds each seat, and where", build: func(line) (call, error) {
return call{"mesh-module-assigner.assignments", map[string]any{"seats": "true"}}, nil
}},
{words: []string{"seat"}, instead: "a seat is held by placing its module: nox assign <node> <module> --why <text> (mesh-module-assigner.propose)"},
{words: []string{"assign"}, usage: "<node> <module>... --why <text>", does: "propose placing modules on a node",
allowed: []string{"why"}, build: placeModules("place")},
{words: []string{"unassign"}, usage: "<node> <module>... --why <text>", does: "propose taking modules off a node",
@@ -157,7 +160,6 @@ var commands = []command{
}},
{words: []string{"proposals"}, usage: "[<id>]", does: "the open proposals of assignments", build: optArg("mesh-module-assigner.proposals", "id")},
{words: []string{"overlay", "show"}, does: "every node's assignments, with its tunnel", build: fixed("mesh-module-assigner.assignments")},
{words: []string{"overlay"}, instead: "a node's tunnel is a decided field of its assignments: mesh-module-assigner.propose with op decide"},
// Deliveries and builds.
{words: []string{"deliveries"}, usage: "[--state s] [--repository owner/repo] [--group g] [--all]",
@@ -291,11 +293,7 @@ var commands = []command{
c, err := fixed("mesh-vault.secret_vault_export")(l)
return warranted(c, "the vault's sealed copies"), err
}},
{words: []string{"secret", "accept"}, instead: "mesh-vault.accept takes a value from the controller alone, and no seat takes one from a person yet; a module's own secret is asked at a desk (mesh-vault.secret-ask)"},
{words: []string{"secret", "recover"}, instead: "opening a sealed copy locally is not built yet (beside nox enrol open); nox secret export gives the sealed copies"},
{words: []string{"secret"}, instead: "nox secret export; mesh-vault.rotate makes one anew"},
{words: []string{"operator", "key", "show"}, does: "what needs a person's eye in the vault, the operator key among it", build: fixed("mesh-vault.vault_status")},
{words: []string{"operator"}, instead: "no seat sets or makes the operator key yet; nox operator key show reads it (mesh-vault.vault_status)"},
{words: []string{"rotate"}, usage: "[--node n --module m --name s | --provider n --provision p] --why <text>",
does: "make a secret anew", allowed: []string{"node", "module", "name", "provider", "provision", "consumer", "consumer_module", "why"},
build: func(l line) (call, error) {
@@ -353,7 +351,13 @@ var commands = []command{
}},
{words: []string{"images"}, usage: "<node>", does: "every container image a machine's wants and haves name", build: needArg("mesh-artifact-sweep.images", "node")},
{words: []string{"mirrors"}, does: "the bases the mesh copied into its store", build: fixed("mesh-artifact-sweep.mirrors")},
{words: []string{"licence", "list"}, does: "every licence the manager holds", build: fixed("anthropic-licence-manager.licences")},
// The operator's overview of the licences, in one line (one-question-one-tool).
{words: []string{"licence"}, does: "every licence: kind, bound nodes, usage and its resets, token expiry, failures, conditions, target; then the bindings",
build: fixed("anthropic-licence-manager.licences"), also: licenceBindings},
{words: []string{"licence", "list"}, does: "every licence: kind, bound nodes, usage and its resets, token expiry, failures, conditions, target; then the bindings",
build: fixed("anthropic-licence-manager.licences"), also: licenceBindings},
{words: []string{"licence", "usage"}, usage: "[<licence>]", does: "the usage readings, the latest first, of every licence or one",
build: optArg("anthropic-licence-manager.usage", "licence"), render: renderUsage},
{words: []string{"licence", "use"}, usage: "<consumer> <licence>", does: "move a node's agent to another licence",
build: func(l line) (call, error) {
if len(l.pos) != 2 {
@@ -363,7 +367,6 @@ var commands = []command{
}},
{words: []string{"licence", "refresh"}, usage: "[<licence>]", does: "refresh a licence now, or every due one", build: optArg("anthropic-licence-manager.refresh", "licence")},
{words: []string{"licence", "key"}, does: "the manager's public key", build: fixed("anthropic-licence-manager.public-key")},
{words: []string{"licence"}, instead: "anthropic-licence-manager.adopt takes an API key from a file on the manager's node; nox licence list|use|refresh|key"},
{words: []string{"module", "list"}, does: "every module the indexer holds", build: fixed("mesh-delivery-view.indexer_modules")},
{words: []string{"module", "show"}, usage: "<module>", does: "what the indexer holds of one module", build: needArg("mesh-delivery-view.indexer_module", "module")},
{words: []string{"head", "take"}, usage: "<owner/repository> <branch> --why <text>", does: "take a held head in by hand (design 47 H §742, H-A-105)", allowed: []string{"why"},
@@ -374,8 +377,6 @@ var commands = []command{
return call{"mesh-delivery-gate.gate_head_take", map[string]any{"repository": l.pos[0], "branch": l.pos[1], "why": l.flags["why"]}}, nil
}},
{words: []string{"head", "list"}, does: "every untaken head the gate holds", build: fixed("mesh-delivery-gate.gate_heads")},
{words: []string{"module"}, instead: "the indexer takes modules in from their repositories; nox module list|show, nox head take for a held head, and nothing forgets one by hand yet"},
{words: []string{"register"}, instead: "no seat registers a module from another repository yet (novox/hq ADR 0501 §4); nox head take <repository> <branch> takes a held head in"},
{words: []string{"account", "issue"}, usage: "<user>", does: "mint one bus account the grants part wants, now", build: needArg("mesh-vault.issue-account", "user")},
// Issues and records.
@@ -479,21 +480,6 @@ var commands = []command{
}},
}
// unowned are the controller's own lines that no seat or module took over, and what to use where there is anything.
var unowned = map[string]string{
"migrate": "", "prepare": "", "serve": "", "declare": "", "broker": "", "board": "", "api": "", "facts": "",
"rehearse": "", "take": "", "converge": "", "adopt": "", "move-placement": "", "move-config": "", "durations": "",
"data": "each machine's backups: nox call <node>/node-backup.backed-up",
"forget-checks": "nox checks <owner/repo>", "queue": "nox builds; nox stuck", "cancel": "nox deliveries",
"clear": "nox deliveries", "kill": "nox deliveries", "replay": "nox dead-letters",
"pause": "nox call <node>/node-build-go.pause (or node-build-node, node-build-image)",
"resume": "nox call <node>/node-build-go.resume (or node-build-node, node-build-image)",
"push": "a merge is delivered by mesh-delivery: nox deliveries; one version on one machine is mesh-delivery-assigner.assigner_put",
"deliver": "nox deliveries", "plans": "nox deliveries", "delivery-stop": "nox stalled",
"delivery-backups-again": "nox deliveries", "delivery-walks": "nox deliveries", "delivery-order": "nox deliveries",
"rollout": "nox upgrade <module>; delivery is mesh-delivery's: nox deliveries",
}
// find answers the command whose words begin the line, the longest first, and what follows them.
func find(args []string) (*command, []string) {
var best *command
+2 -3
View File
@@ -1,8 +1,7 @@
package main
// How mesh-cli reaches the mesh now that the controller is unassigned (novox/hq issue 1126): through this machine's
// console, the mesh MCP server the module node-tools serves on loopback (provision mcp-endpoint, ADR 0152: the
// machine's login is the authority). mesh-cli calls `mesh_call` with a seat verb's or a module tool's address, and the
// How mesh-cli reaches the mesh: through this machine's console, the mesh MCP server the module node-tools serves on
// loopback (provision mcp-endpoint, ADR 0152: the machine's login is the authority). mesh-cli calls `mesh_call` with a seat verb's or a module tool's address, and the
// console puts the call on the bus, the way every agent session on the machine does. mesh-cli holds no credential and
// keeps no bus account of its own.
+1 -1
View File
@@ -4,7 +4,7 @@ package main
//
// The seat mesh-node-enroller's `tokens` answers the token sealed to the operator key, which only the operator's private key
// opens; the mesh never holds it. This subcommand is local: it asks nothing of the node-engine's socket and nothing of
// the controller or the bus. It reads the sealed token (the base64 of the sealed box) on standard input and the private
// the bus. It reads the sealed token (the base64 of the sealed box) on standard input and the private
// key from a file (`--key`, the raw X25519 key in base64 that `operator key make` wrote), opens the box, and prints the
// token text a joining machine's `enrol` takes. The key is read from the file named and nowhere else, and never printed.
+176
View File
@@ -0,0 +1,176 @@
package main
// The operator's overview of the licences in one line (one-question-one-tool): the licence manager's licences and
// bindings as two tables, and its usage readings as one; every time is local.
import (
"encoding/json"
"fmt"
"strings"
"text/tabwriter"
"time"
)
// licenceBindings is the second call of `nox licence`: which licence each node is bound to, since when and why.
var licenceBindings = &second{address: "anthropic-licence-manager.bindings", keys: [2]string{"licences", "bindings"},
render: renderLicences}
// splitAnswer is the console's answer as its first JSON value and what the console said after it ("answered by ace").
func splitAnswer(text string) (json.RawMessage, string) {
dec := json.NewDecoder(strings.NewReader(text))
var v json.RawMessage
if err := dec.Decode(&v); err != nil {
return nil, text
}
return v, strings.TrimSpace(text[dec.InputOffset():])
}
// localTime is an RFC 3339 time in this machine's zone, to the minute; "-" for none, and the text itself when it is
// not one.
func localTime(s string) string {
if s == "" {
return "-"
}
t, err := time.Parse(time.RFC3339Nano, s)
if err != nil {
return s
}
return t.Local().Format("2006-01-02 15:04")
}
// percent is a reading with its reset when it has one; "-" for a reading the vendor did not give.
func percent(pct *float64, resets string) string {
if pct == nil {
return "-"
}
if resets == "" {
return fmt.Sprintf("%g %%", *pct)
}
return fmt.Sprintf("%g %% (resets %s)", *pct, localTime(resets))
}
func dashed(s string) string {
if s == "" {
return "-"
}
return s
}
// conditionNames are a licence's open conditions as their keys; a condition that is not a key is said as given.
func conditionNames(cs []json.RawMessage) string {
names := make([]string, 0, len(cs))
for _, c := range cs {
var s string
if json.Unmarshal(c, &s) == nil {
names = append(names, s)
continue
}
var o struct {
Key string `json:"key"`
}
if json.Unmarshal(c, &o) == nil && o.Key != "" {
names = append(names, o.Key)
continue
}
names = append(names, string(c))
}
return dashed(strings.Join(names, " "))
}
// renderLicences is the licences as one table, then the bindings as another; an answer it cannot read is printed as
// given.
func renderLicences(licences, bindings string) string {
var ls []struct {
Name string `json:"name"`
Kind string `json:"kind"`
Bound []string `json:"bound"`
Usage struct {
WeeklyPct *float64 `json:"weeklyPct"`
WeeklyResetsAt string `json:"weeklyResetsAt"`
SessionPct *float64 `json:"sessionPct"`
SessionResetsAt string `json:"sessionResetsAt"`
SonnetPct *float64 `json:"sonnetPct"`
} `json:"usage"`
AccessExpiresAt string `json:"accessExpiresAt"`
Failures int `json:"failures"`
Conditions []json.RawMessage `json:"conditions"`
Target bool `json:"target"`
}
var bs []struct {
Consumer string `json:"consumer"`
Licence string `json:"licence"`
Since string `json:"since"`
Why string `json:"why"`
}
lv, lafter := splitAnswer(licences)
bv, bafter := splitAnswer(bindings)
if lv == nil || json.Unmarshal(lv, &ls) != nil || bv == nil || json.Unmarshal(bv, &bs) != nil {
return licences + "\n" + bindings
}
var b strings.Builder
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "LICENCE\tKIND\tBOUND\tWEEKLY\tSESSION\tSONNET\tTOKEN EXPIRES\tFAILURES\tCONDITIONS\tTARGET")
for _, l := range ls {
target := "no"
if l.Target {
target = "yes"
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\n", l.Name, dashed(l.Kind), dashed(strings.Join(l.Bound, " ")),
percent(l.Usage.WeeklyPct, l.Usage.WeeklyResetsAt), percent(l.Usage.SessionPct, l.Usage.SessionResetsAt),
percent(l.Usage.SonnetPct, ""), localTime(l.AccessExpiresAt), l.Failures, conditionNames(l.Conditions), target)
}
w.Flush()
b.WriteString("\n")
w = tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NODE\tLICENCE\tSINCE\tWHY")
for _, x := range bs {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", x.Consumer, x.Licence, localTime(x.Since), dashed(x.Why))
}
w.Flush()
// Which machine answered each call, said once when both say the same.
for i, a := range []string{lafter, bafter} {
if a != "" && (i == 0 || a != lafter) {
b.WriteString(a + "\n")
}
}
return b.String()
}
// renderUsage is the usage readings as one table, the latest first as the manager answers them; an answer it cannot
// read is printed as given.
func renderUsage(text string) string {
var rs []struct {
At int64 `json:"at"`
Licence string `json:"licence"`
Reading struct {
WeeklyPct *float64 `json:"weeklyPct"`
WeeklyResetsAt string `json:"weeklyResetsAt"`
SessionPct *float64 `json:"sessionPct"`
SessionResetsAt string `json:"sessionResetsAt"`
SonnetResetsAt string `json:"sonnetResetsAt"`
} `json:"reading"`
}
v, after := splitAnswer(text)
if v == nil || json.Unmarshal(v, &rs) != nil {
return text
}
var b strings.Builder
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "LICENCE\tREAD AT\tWEEKLY\tSESSION\tRESETS")
for _, r := range rs {
var resets []string
for _, x := range [][2]string{{"weekly", r.Reading.WeeklyResetsAt}, {"session", r.Reading.SessionResetsAt},
{"sonnet", r.Reading.SonnetResetsAt}} {
if x[1] != "" {
resets = append(resets, x[0]+" "+localTime(x[1]))
}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", r.Licence, time.UnixMilli(r.At).Local().Format("2006-01-02 15:04"),
percent(r.Reading.WeeklyPct, ""), percent(r.Reading.SessionPct, ""), dashed(strings.Join(resets, ", ")))
}
w.Flush()
if after != "" {
b.WriteString(after + "\n")
}
return b.String()
}
+58 -26
View File
@@ -1,8 +1,8 @@
// Command mesh-cli is the operator's command on every node: `mesh-cli <command line>`, in interactive zsh also `nox`.
//
// Each line calls the seat verb or the module tool that owns its job (novox/hq issue 1126: the controller that ran
// these lines before is unassigned), through this machine's console, the mesh MCP server on loopback (console.go).
// A line no seat or module owns says so and names what to use instead. `enrol open` runs here and asks nothing.
// Each line calls the seat verb or the module tool that owns its job, through this machine's console, the mesh MCP
// server on loopback (console.go). A line nox does not know says so and calls nothing. `enrol open` runs here and asks
// nothing.
package main
import (
@@ -75,16 +75,10 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
}
c, rest := find(args)
if c == nil {
if instead, ok := unowned[args[0]]; ok {
return noOwner(args[0], instead, stderr)
}
fmt.Fprintf(stderr, "mesh-cli: %q is not a command. nox help lists them; nox search <words> finds a seat verb "+
"or a tool, and nox call <address> calls it\n", args[0])
return 2
}
if c.build == nil {
return noOwner(strings.Join(c.words, " "), c.instead, stderr)
}
k, err := c.read(rest)
if err != nil {
fmt.Fprintf(stderr, "mesh-cli: %v. Nothing was called\n nox %s %s\n", err, strings.Join(c.words, " "), c.usage)
@@ -100,7 +94,59 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
if k.Address == "mesh-delivery-view.view_status" {
return status(ctx, stdout, stderr)
}
return show(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args}, c.render, stdout, stderr)
render := c.render
l, _ := parseLine(rest)
if l.has("json") {
render = nil
}
if c.also != nil {
return showTwo(ctx, k, c.also, !l.has("json"), stdout, stderr)
}
return show(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args}, render, stdout, stderr)
}
// showTwo calls a line's two addresses in turn and prints both answers: through the line's render, or raw as one
// object under the line's two keys. The second is not called when the first fails, and either failing is said with
// exit 1.
func showTwo(ctx context.Context, first call, also *second, rendered bool, stdout, stderr io.Writer) int {
var texts [2]string
for i, k := range []call{first, {also.address, map[string]any{}}} {
a, err := consoleTool(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args})
if err != nil {
return failed(err, stderr)
}
if a.IsError {
fmt.Fprintln(stderr, "mesh-cli: "+k.Address+": "+strings.TrimRight(a.Text, "\n"))
return 1
}
texts[i] = a.Text
}
if rendered {
fmt.Fprintln(stdout, strings.TrimRight(also.render(texts[0], texts[1]), "\n"))
return 0
}
whole := map[string]json.RawMessage{}
var after []string
for i, text := range texts {
v, rest := splitAnswer(text)
if v == nil {
fmt.Fprintf(stderr, "mesh-cli: %s answered no JSON: %q\n", []string{first.Address, also.address}[i], text)
return 1
}
whole[also.keys[i]] = v
if rest != "" && (len(after) == 0 || after[0] != rest) {
after = append(after, rest)
}
}
b, err := json.MarshalIndent(whole, "", " ")
if err != nil {
return failed(err, stderr)
}
fmt.Fprintln(stdout, string(b))
for _, a := range after {
fmt.Fprintln(stdout, a)
}
return 0
}
// recordAct records the hand act a sensitive vault verb is warranted by, through mesh-hand-acts, and answers its id;
@@ -127,17 +173,6 @@ func recordAct(ctx context.Context, h handAct, stderr io.Writer) (string, int) {
return rec.Act.ID, 0
}
// noOwner says a line has no owner since the controller went, and what to use.
func noOwner(what, instead string, stderr io.Writer) int {
fmt.Fprintf(stderr, "mesh-cli: nox %s: %s.\n", what, gone)
if instead != "" {
fmt.Fprintf(stderr, " instead: %s\n", instead)
} else {
fmt.Fprintln(stderr, " no seat or module does this now; nox search <words> finds what does nearby")
}
return 1
}
// show calls one of the console's tools and prints what it answered: an answer marked an error on standard error, with
// exit 1.
func show(ctx context.Context, tool string, args map[string]any, render func(string) string, stdout, stderr io.Writer) int {
@@ -218,14 +253,11 @@ func usage() string {
b.WriteString(`mesh-cli: the operator's command (nox in interactive zsh)
Each line calls the seat verb or module tool that owns the job, through this machine's console (the mesh MCP
server on loopback). The controller that ran these lines before is unassigned (novox/hq issue 1126).
server on loopback).
`)
lines := make([]string, 0, len(commands))
for _, c := range commands {
if c.build == nil {
continue
}
lines = append(lines, fmt.Sprintf(" nox %s %s\n %s", strings.Join(c.words, " "), c.usage, c.does))
}
sort.Strings(lines)
@@ -239,7 +271,7 @@ server on loopback). The controller that ran these lines before is unassigned (n
open an enrolment token sealed to the operator key, here; asks nothing of the mesh
nox version
Every answer is the owner's own, as JSON. A line the controller ran that no seat owns says so and what to use.
Every answer is the owner's own, as JSON, or a table where the line says so; --json prints it raw.
`)
return b.String()
}
+112 -35
View File
@@ -77,8 +77,8 @@ func runLine(args ...string) (int, string, string) {
return code, out.String(), errOut.String()
}
// Every owned line calls the seat verb or module tool that owns its job, with the arguments the owner reads
// (novox/hq issue 1126; hq .work/1126/nox-map.md), and prints its answer.
// Every line calls the seat verb or module tool that owns its job, with the arguments the owner reads, and prints its
// answer.
func TestEachLineCallsItsOwner(t *testing.T) {
now = func() time.Time { return time.Date(2026, 11, 2, 10, 0, 0, 0, time.UTC) }
t.Cleanup(func() { now = time.Now })
@@ -121,14 +121,14 @@ func TestEachLineCallsItsOwner(t *testing.T) {
{"settings clear zsh execute --node g14 --why test", "mesh-config.config", `{"action":"clear","key":"execute","module":"zsh","node":"g14","why":"test"}`},
{"config history --key k --limit 5", "mesh-config.config", `{"action":"history","key":"k","limit":5}`},
{"operator key show", "mesh-vault.vault_status", `{}`},
// A cleanup without --confirm deletes nothing, so no hand act is recorded for it (issue 1126 review 2).
// A cleanup without --confirm deletes nothing, so no hand act is recorded for it.
{"cleanup delete ace.plex --why dry", "mesh-vault.provisioner_delete", `{"consumer":"ace.plex","why":"dry"}`},
{"collect --confirm --why space", "mesh-artifact-sweep.collect", `{"confirm":"true","why":"space"}`},
{"images ace", "mesh-artifact-sweep.images", `{"node":"ace"}`},
{"licence use g14 work", "anthropic-licence-manager.switch", `{"consumer":"g14","licence":"work"}`},
{"module show plex", "mesh-delivery-view.indexer_module", `{"module":"plex"}`},
{"issues apostrophe bug --status open --limit 5", "issue-tracker.list", `{"limit":5,"search":"apostrophe bug","status":"open"}`},
{"issue 1126 --brief", "issue-tracker.get", `{"brief":true,"number":1126}`},
{"issue 294 --brief", "issue-tracker.get", `{"brief":true,"number":294}`},
{"kb ask what holds about the merge window", "knowledge-base.ask", `{"question":"what holds about the merge window"}`},
{"kb get 587 --reasoning", "knowledge-base.get", `{"number":587,"reasoning":true}`},
{"progress 47", "knowledge-base.progress", `{"of":"design 47"}`},
@@ -154,42 +154,43 @@ func TestEachLineCallsItsOwner(t *testing.T) {
}
}
// A line the controller ran that no seat owns says so and what to use, exits 1 and calls nothing; a line nox cannot
// read says how it is written, exits 2 and calls nothing.
func TestALineWithNoOwnerOrNotReadCallsNothingAndSaysWhy(t *testing.T) {
// 1126/AC4: a line nox cannot read says how it is written, exits 2 and calls nothing; the controller's retired lines are gone with
// it, not mapped to a refusal (the operator, 2026-11-22: "why are there still references to the controller?"), and
// nothing nox says names the controller.
func TestALineNotReadCallsNothingAndSaysWhy(t *testing.T) {
for _, c := range []struct {
line string
code int
err string
}{
{"push ace", 1, "mesh-delivery-assigner.assigner_put"},
{"migrate", 1, "no seat or module does this now"},
{"secret accept ace plex token", 1, "mesh-vault.secret-ask"},
{"node add new1", 1, "nox enrol issue"},
{"pause", 1, "node-build-go.pause"},
{"operator key make", 1, "operator key show"},
{"assign ace plex", 2, "needs --why"},
{"issue twelve", 2, "not an issue's number"},
{"conditions --bogus x", 2, "--bogus is not a flag"},
{"settings set zsh {\"execute\":\"withhold\"} --node g14 --why x", 2, "set each key"},
{"healers --days soon", 2, "takes a number"},
{"config propose --pull novox/x#1", 2, "--pull is not a flag"},
{"frobnicate", 2, "is not a command"},
{"push ace", "is not a command"},
{"migrate", "is not a command"},
{"secret accept ace plex token", "is not a command"},
{"node add new1", "is not a command"},
{"pause", "is not a command"},
{"operator key make", "is not a command"},
{"module forget plex", "is not a command"},
{"assign ace plex", "needs --why"},
{"issue twelve", "not an issue's number"},
{"conditions --bogus x", "--bogus is not a flag"},
{"settings set zsh {\"execute\":\"withhold\"} --node g14 --why x", "set each key"},
{"healers --days soon", "takes a number"},
{"config propose --pull novox/x#1", "--pull is not a flag"},
{"frobnicate", "is not a command"},
// The checker and the groups go whole (design 47 H §764): nox calls neither.
{"try novox/mesh-catalog abc123 --level unit", 2, "is not a command"},
{"groups", 2, "is not a command"},
{"checks novox/mesh-catalog --number 591", 2, "is not a command"},
{"try novox/mesh-catalog abc123 --level unit", "is not a command"},
{"groups", "is not a command"},
{"checks novox/mesh-catalog --number 591", "is not a command"},
} {
got := console(t, nil)
args := strings.Fields(c.line)
code, _, errOut := runLine(args...)
if code != c.code || len(*got) != 0 || !strings.Contains(errOut, c.err) {
t.Errorf("nox %s: exit %d, asked %+v, stderr %q; want exit %d saying %q", c.line, code, *got, errOut, c.code, c.err)
}
if c.code == 1 && !strings.Contains(errOut, "issue 1126") {
t.Errorf("nox %s does not say the controller is unassigned: %q", c.line, errOut)
if code != 2 || len(*got) != 0 || !strings.Contains(errOut, c.err) || strings.Contains(errOut, "controller") {
t.Errorf("nox %s: exit %d, asked %+v, stderr %q; want exit 2 saying %q", c.line, code, *got, errOut, c.err)
}
}
if strings.Contains(usage(), "controller") {
t.Errorf("the help still names the controller:\n%s", usage())
}
}
// What the console says is printed as said: an answer it marks an error on standard error with exit 1, a console that
@@ -279,16 +280,13 @@ func TestEveryLineIsInTheHelpOnce(t *testing.T) {
if c.build != nil && !strings.Contains(help, "nox "+w+" ") {
t.Errorf("nox %s is not in the help", w)
}
if c.build == nil && c.instead == "" {
t.Errorf("nox %s has neither an owner nor an instead", w)
}
if _, dup := unowned[c.words[0]]; dup && len(c.words) == 1 {
t.Errorf("nox %s is both owned and unowned", w)
if c.build == nil {
t.Errorf("nox %s has no owner", w)
}
}
}
// ADR 0590 §8 (issue 1126 review 1): each sensitive vault verb judges its own caller, and nox reaches the vault as its
// ADR 0590 §8: each sensitive vault verb judges its own caller, and nox reaches the vault as its
// machine's runtime, so nox first records the hand act that warrants the line through mesh-hand-acts (the vault verb as
// its verb, what it acts on as its what) and names it as `act`; a recording refused calls the vault not at all.
func TestASensitiveLineRecordsItsHandActAndNamesIt(t *testing.T) {
@@ -322,3 +320,82 @@ func TestASensitiveLineRecordsItsHandActAndNamesIt(t *testing.T) {
t.Errorf("a refused recording: exit %d, asked %+v, %q", code, *got, errOut)
}
}
// 1126/AC1, 1126/AC2, 1126/AC3: the operator's overview of the licences is one line (one-question-one-tool): `nox licence` and
// `nox licence list` call the licence manager's licences and bindings and print one table of each, every time local;
// `nox licence usage` prints the readings; --json prints the raw answers, the two as one object.
func TestTheLicencesAreOneTable(t *testing.T) {
local := time.Local
time.Local = time.FixedZone("CET", 3600)
t.Cleanup(func() { time.Local = local })
licences := `[{"name":"work","account":"a@example.org","kind":"subscription","bound":["ace","novox"],
"usage":{"readAt":"2026-11-22T19:32:27Z","weeklyPct":2,"weeklyResetsAt":"2026-11-25T01:59:59.5+00:00",
"sessionPct":7,"sessionResetsAt":"2026-11-23T00:29:59+00:00","sonnetPct":null},
"accessExpiresAt":"2026-11-23T01:56:57Z","refreshExpiresAt":"2026-12-14T01:48:16Z","room":98,
"failures":0,"conditions":[],"target":true},
{"name":"home","account":"b@example.org","kind":"subscription","bound":[],
"usage":{"weeklyPct":99,"weeklyResetsAt":"2026-11-25T10:59:59+00:00","sessionPct":null,"sonnetPct":40},
"accessExpiresAt":"2026-11-23T02:02:57Z","failures":2,"conditions":["licence.home.full"],"target":false}]`
bindings := `[{"consumer":"g14","licence":"home","kind":"subscription","generation":3,"since":"2026-11-22T19:32:28Z",
"why":"work reached 99 % of its weekly window","by":"usage"}]`
usage := `[{"at":1795376250078,"licence":"work","reading":{"weeklyPct":4,"weeklyResetsAt":"2026-11-29T17:59:59+00:00",
"sessionPct":null,"sonnetPct":null}}]`
answers := map[string]string{"anthropic-licence-manager.licences": licences,
"anthropic-licence-manager.bindings": bindings, "anthropic-licence-manager.usage": usage}
for _, words := range []string{"licence", "licence list"} {
got := console(t, answers)
code, out, errOut := runLine(strings.Fields(words)...)
if code != 0 || errOut != "" || len(*got) != 2 || (*got)[0].Address != "anthropic-licence-manager.licences" ||
(*got)[1].Address != "anthropic-licence-manager.bindings" || (*got)[1].Args != `{}` {
t.Fatalf("nox %s: exit %d, stderr %q, asked %+v", words, code, errOut, *got)
}
for _, want := range []string{
"LICENCE", "KIND", "BOUND", "WEEKLY", "SESSION", "SONNET", "TOKEN EXPIRES", "FAILURES", "CONDITIONS", "TARGET",
"work", "ace novox", "2 % (resets 2026-11-25 02:59)", "7 % (resets 2026-11-23 01:29)", "2026-11-23 02:56", "yes",
"home", "99 % (resets 2026-11-25 11:59)", "40 %", "licence.home.full",
"NODE", "SINCE", "WHY", "g14", "2026-11-22 20:32", "work reached 99 % of its weekly window",
} {
if !strings.Contains(out, want) {
t.Errorf("nox %s does not print %q:\n%s", words, want, out)
}
}
if strings.Contains(out, "2026-12-14") || strings.Contains(out, "98") {
t.Errorf("nox %s prints the refresh-token expiry or the room:\n%s", words, out)
}
}
// 1126/AC3: --json prints the raw answers, the two calls' as one object.
console(t, answers)
code, out, _ := runLine("licence", "--json")
var raw struct {
Licences []map[string]any `json:"licences"`
Bindings []map[string]any `json:"bindings"`
}
if err := json.Unmarshal([]byte(strings.SplitN(out, "\nanswered by", 2)[0]), &raw); code != 0 || err != nil ||
len(raw.Licences) != 2 || len(raw.Bindings) != 1 {
t.Errorf("nox licence --json: exit %d, %v:\n%s", code, err, out)
}
// 1126/AC3: on every rendered line, as on the nodes.
nodes := `{"keys":{"ace":{"assignments":{"decided":{"address":"10.0.0.1"},"modules":[]}}}}`
console(t, map[string]string{"mesh-module-assigner.assignments": nodes})
if code, out, _ := runLine("nodes", "--json"); code != 0 || !strings.HasPrefix(out, nodes) {
t.Errorf("nox nodes --json: exit %d, does not print the raw answer:\n%s", code, out)
}
// 1126/AC2: the usage readings as one table.
got := console(t, answers)
code, out, errOut := runLine("licence", "usage", "work")
if code != 0 || len(*got) != 1 || (*got)[0].Address != "anthropic-licence-manager.usage" || (*got)[0].Args != `{"licence":"work"}` {
t.Fatalf("nox licence usage work: exit %d, stderr %q, asked %+v", code, errOut, *got)
}
for _, want := range []string{"LICENCE", "READ AT", "WEEKLY", "SESSION", "RESETS", "work",
time.UnixMilli(1795376250078).Local().Format("2006-01-02 15:04"), "4 %", "weekly 2026-11-29 18:59"} {
if !strings.Contains(out, want) {
t.Errorf("nox licence usage does not print %q:\n%s", want, out)
}
}
if code, _, _ := runLine("licence", "usage", "--limit", "5"); code != 2 {
t.Errorf("nox licence usage --limit is read (exit %d); it takes no limit", code)
}
}
@@ -24,8 +24,8 @@ func TestTheArchivePlacesExactlyOneFileAndTheConsolesAddressOne(t *testing.T) {
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
// Beside the program, one directory and one file: the console's address, from the mcp-endpoint it requires
// (novox/hq issue 1126). Nothing else.
// Beside the program, one directory and one file: the console's address, from the mcp-endpoint it requires.
// Nothing else.
var r map[string]any
for _, res := range m.Resources {
switch {
@@ -43,7 +43,7 @@ func TestTheArchivePlacesExactlyOneFileAndTheConsolesAddressOne(t *testing.T) {
if len(m.Resources) != 3 || r == nil || r["path"] != "/usr/local/bin" {
t.Fatalf("its resources are %v", m.Resources)
}
// The build has a second artifact, the files archive the controller reads the templates back from; it
// The build has a second artifact, the files archive the templates are read back from; it
// places no file. The artifact the resource unpacks is the one that does.
var a map[string]any
for _, candidate := range m.Build.Artifacts {
@@ -1,52 +1,29 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// nextcloud-client's shape (novox/hq ADR 0208, ADR 0210, ADR 0182): one official package, no seat,
// the X display on its own machine, no start of its own (the client's own autostart entry is the one
// start), no file of the client's, and the Go bundle serving exactly the listed nextcloud_ 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 TestItInstallsTheClientAndNothingElse(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 TestItInstallsTheClientAndNothingElse(t *testing.T) {
m, _ := readManifest(t)
if m.Module != "nextcloud-client" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) ||
!reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
t.Fatalf("%+v", m)
@@ -54,13 +31,22 @@ func TestItInstallsTheClientAndNothingElse(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 TestItAddsNoSecondStartAndOwnsNoneOfTheClientsFiles(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 client writes its own 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 {
@@ -74,7 +60,16 @@ func TestItAddsNoSecondStartAndOwnsNoneOfTheClientsFiles(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
@@ -95,8 +90,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/nextcloud-client-tools" || b["binary"] != "nextcloud-client-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/nextcloud-client-tools" || b.Binary != "nextcloud-client-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -1,12 +1,13 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// nm-applet's shape (novox/hq ADR 0208, ADR 0210): the applet's one official package, no seat, the X
@@ -14,44 +15,17 @@ import (
// nothing of the networkmanager module's (its package, its configuration, its service), and the Go
// bundle serving exactly the listed nm_applet_ 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 []struct {
Seat string `json:"seat"`
Kind string `json:"kind"`
Content string `json:"content"`
} `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 TestTheToolsAgreeWithTheManifest(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 TestTheToolsAgreeWithTheManifest(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
served := map[string]bool{}
for _, tool := range tools() {
served[tool.Name] = true
@@ -72,8 +46,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/nm-applet-tools" || b["binary"] != "nm-applet-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/nm-applet-tools" || b.Binary != "nm-applet-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -85,7 +59,16 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
}
func TestItInstallsTheAppletAndNothingOfNetworkManager(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)
if m.Module != "nm-applet" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) ||
!reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
t.Fatalf("%+v", m)
@@ -93,7 +76,7 @@ func TestItInstallsTheAppletAndNothingOfNetworkManager(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 || m.Shell != nil || m.Contributions != nil {
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
t.Fatal("no seat, no environment, and no second start")
}
for _, never := range []string{"\"networkmanager\"", "nm-connection-editor", "libnma", "/etc/NetworkManager", "autostart", "service"} {
@@ -1,12 +1,13 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// openrazer's shape (novox/hq ADR 0207, ADR 0208, ADR 0210): the three official packages of the
@@ -14,44 +15,17 @@ import (
// its own (D-Bus activation through the package's unit is the one start), nothing of the tray's (the
// polychromatic module's), and the Go bundle serving exactly the listed openrazer_ 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 []struct {
Seat string `json:"seat"`
Kind string `json:"kind"`
Content string `json:"content"`
} `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 TestTheToolsAgreeWithTheManifest(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 TestTheToolsAgreeWithTheManifest(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
served := map[string]bool{}
for _, tool := range tools() {
served[tool.Name] = true
@@ -72,8 +46,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/openrazer-tools" || b["binary"] != "openrazer-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/openrazer-tools" || b.Binary != "openrazer-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -85,7 +59,16 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
}
func TestItInstallsTheStackAndStartsNothing(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)
if m.Module != "openrazer" || m.Requires != nil || !reflect.DeepEqual(m.Capabilities, []string{"package-manager"}) {
t.Fatalf("%+v", m)
}
@@ -114,7 +97,7 @@ func TestItInstallsTheStackAndStartsNothing(t *testing.T) {
if len(accounts) != 1 || !reflect.DeepEqual(accounts[0], want) {
t.Fatalf("the account: %v, want %v", accounts, want)
}
if m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
if m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil || m.Contributions != nil {
t.Fatal("it holds no seat, sets no environment and adds no start")
}
// The tray is polychromatic's, from outside the official repositories; the kernel headers DKMS
@@ -14,6 +14,8 @@ import (
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// rawManifest is the manifest as written, every field kept.
@@ -41,7 +43,15 @@ func strs(v any) []string {
}
func testTheWeeklyTimerAndItsServiceAreGone(t *testing.T) {
m := manifest(t)
manifestJSON, err := os.ReadFile("../../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 _, r := range m.Resources {
id, _ := r["id"].(string)
path, _ := r["path"].(string)
@@ -59,12 +69,20 @@ func testTheWeeklyTimerAndItsServiceAreGone(t *testing.T) {
}
func testTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing.T) {
m := manifest(t)
user := m.resource(t, "keeper-account")
manifestJSON, err := os.ReadFile("../../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)
}
user := resourceOf(t, m, "keeper-account")
if user["type"] != "user" || user["name"] != "pacman-keeper" || user["shell"] != "/usr/bin/nologin" {
t.Fatalf("the keeper's account: %v", user)
}
k := m.resource(t, "keeper")
k := resourceOf(t, m, "keeper")
if k["type"] != "process" || k["name"] != "pacman-keeper" || k["artifact"] != "tools" ||
strings.Join(strs(k["run"]), " ") != "./"+binaryName+" keeper" {
t.Fatalf("the keeper: %v", k)
@@ -82,7 +100,7 @@ func testTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing
if broker["path"] != env[EnvBroker] || broker["owner"] != "pacman-keeper" || len(secrets) != 1 {
t.Errorf("the bus account is the keeper's own secret, owned by its account: %v", secrets)
}
state := m.resource(t, "state")
state := resourceOf(t, m, "state")
if state["type"] != "directory" || state["place"] != "mesh" || state["unknown"] == nil {
t.Errorf("the state directory: %v", state)
}
@@ -96,8 +114,17 @@ func testTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing
}
func testTheKeeperDeclaresTheModulesStatesAndEvents(t *testing.T) {
manifestJSON, err := os.ReadFile("../../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 := rawManifest(t)
k := manifest(t).resource(t, "keeper")
k := resourceOf(t, m, "keeper")
bus, _ := k["bus"].(map[string]any)
var events []string
for _, e := range Events {
@@ -120,9 +147,9 @@ func testTheKeeperDeclaresTheModulesStatesAndEvents(t *testing.T) {
t.Errorf("the keeper reads its asks' answers and the module uses the operator's channel: %v %v", bus["asks"], raw["uses"])
}
// The tools read round-start-minutes from the keeper's config file.
for _, a := range manifest(t).Build.Artifacts {
if env, _ := a["env"].(map[string]any); a["name"] == "tools" && env[EnvConfig] != "${dir:state}/keeper.json" {
t.Errorf("the tools bundle is not named the keeper's config file: %v", a["env"])
for _, a := range m.Build.Artifacts {
if a.Name == "tools" && a.Env[EnvConfig] != "${dir:state}/keeper.json" {
t.Errorf("the tools bundle is not named the keeper's config file: %v", a.Env)
}
}
if got := strs(raw["state"]); !reflect.DeepEqual(got, States) {
@@ -168,15 +195,23 @@ func testTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt(t *testing.T)
if len(config) != 3 {
t.Errorf("config: %v", config)
}
m := manifest(t)
f := m.resource(t, "keeper-config")
manifestJSON, err := os.ReadFile("../../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)
}
f := resourceOf(t, m, "keeper-config")
if f["type"] != "file" || f["path"] != "${dir:state}/keeper.json" || f["merge"] != "json" || f["trusted"] != true || f["mode"] != "0644" {
t.Fatalf("the keeper's config file: %v", f)
}
if got := strs(f["takes-config"]); strings.Join(got, " ") != "upgrade-order record-days round-start-minutes" {
if got := strs(f[catalogue.TakesSettingsField]); strings.Join(got, " ") != "upgrade-order record-days round-start-minutes" {
t.Errorf("the file takes every config value: %v", got)
}
if got := strs(m.resource(t, "keeper")["restart-on"]); strings.Join(got, " ") != "keeper-config" {
if got := strs(resourceOf(t, m, "keeper")["restart-on"]); strings.Join(got, " ") != "keeper-config" {
t.Errorf("a changed config file restarts the keeper, which reads it at its start: %v", got)
}
// The template is the file a node starts with: the defaults, read as the keeper reads them.
@@ -12,22 +12,32 @@ import (
"path/filepath"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
func testItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) {
m := manifest(t)
if len(m.Claims) != 1 || m.Claims[0]["name"] != "node-package-manager" || m.Claims[0]["scope"] != "node" || m.Claims[0]["serves"] != nil {
manifestJSON, err := os.ReadFile("../../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 len(m.Claims) != 1 || m.Claims[0].Name != "node-package-manager" || m.Claims[0].Scope != "node" || m.Claims[0].Serves != nil {
t.Fatalf("claims: %v", m.Claims)
}
for id, pkg := range map[string]string{"package": "pacman", "contrib": "pacman-contrib", "reflector": "reflector"} {
if r := m.resource(t, id); r["package"] != pkg || r["absent"] != nil {
if r := resourceOf(t, m, id); r["package"] != pkg || r["absent"] != nil {
t.Errorf("%s: %v", id, r)
}
}
// ADR 0585 §3: reflector's weekly timer is declared stopped and disabled, the mesh's list ranked in the round instead.
for id, unit := range map[string][3]string{"mirror-refresh": {"reflector.timer", "stopped", "disabled"},
"cache-cleaning": {"paccache.timer", "running", "enabled"}} {
r := m.resource(t, id)
r := resourceOf(t, m, id)
if r["unit"] != unit[0] || r["state"] != unit[1] || r["boot"] != unit[2] {
t.Errorf("%s: %v", id, r)
}
@@ -35,7 +45,16 @@ func testItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) {
}
func testPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions(t *testing.T) {
f := manifest(t).resource(t, "config")
manifestJSON, err := os.ReadFile("../../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)
}
f := resourceOf(t, m, "config")
content := templateText(t, f)
if f["path"] != "/etc/pacman.conf" || f["into"] != nil || !strings.HasPrefix(content, MeshHeader) {
t.Fatalf("%v", f)
@@ -80,7 +99,16 @@ func testPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions(t *testing
// nothing of the machine: the unit level runs shut off (novox/hq ADR 0448), where /etc/pacman.d is not there
// (issue 1891).
func testTheProvenConfReadsNothingOfTheMachine(t *testing.T) {
content := templateText(t, manifest(t).resource(t, "config"))
manifestJSON, err := os.ReadFile("../../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 := templateText(t, resourceOf(t, m, "config"))
if n := strings.Count(content, "Include = "+Mirrorlist+"\n"); n != 3 || strings.Count(content, "Include") != n {
t.Fatalf("every repository reads %s, and nothing else is included: %d of 3\n%s", Mirrorlist, n, content)
}
@@ -106,7 +134,16 @@ func provenConf(t *testing.T, content, dir string) string {
}
func testReflectorRanksWithTheModulesOptionsAndSavesNoList(t *testing.T) {
content := templateText(t, manifest(t).resource(t, "mirrors"))
manifestJSON, err := os.ReadFile("../../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 := templateText(t, resourceOf(t, m, "mirrors"))
opts := map[string]string{}
for _, l := range strings.Split(content, "\n") {
if l == "" || strings.HasPrefix(l, "#") {
@@ -119,14 +156,23 @@ func testReflectorRanksWithTheModulesOptionsAndSavesNoList(t *testing.T) {
if _, saves := opts["--save"]; saves || opts["--protocol"] != "https" || opts["--latest"] != "20" || opts["--sort"] != "rate" || opts["--country"] == "" {
t.Fatalf("%v", opts)
}
if manifest(t).resource(t, "mirrors")["path"] != ReflectorConf {
if resourceOf(t, m, "mirrors")["path"] != ReflectorConf {
t.Fatal("reflector reads its options from " + ReflectorConf)
}
}
func testTheReflectorPackageIsDeclaredBeforeTheFileItShips(t *testing.T) {
manifestJSON, err := os.ReadFile("../../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)
}
order := map[string]int{}
for i, r := range manifest(t).Resources {
for i, r := range m.Resources {
order[r["id"].(string)] = i
}
if order["reflector"] > order["mirrors"] || order["contrib"] > order["cache-cleaning"] || order["reflector"] > order["mirror-refresh"] {
@@ -137,8 +183,17 @@ func testTheReflectorPackageIsDeclaredBeforeTheFileItShips(t *testing.T) {
// TestThePackageManagersConfigIsDeclaredBeforeItsPackage holds design 42 zfs-owns-zfs §1 and A-26: the
// apply stops at the first failure, and the package fails while its config file is missing.
func testThePackageManagersConfigIsDeclaredBeforeItsPackage(t *testing.T) {
manifestJSON, err := os.ReadFile("../../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)
}
order := map[string]int{}
for i, r := range manifest(t).Resources {
for i, r := range m.Resources {
order[r["id"].(string)] = i
}
if order["config"] >= order["package"] {
+13 -3
View File
@@ -17,6 +17,8 @@ import (
"strings"
"sync/atomic"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// rootBed is a helper over a recording runner, a stand-in process table and a plan directory of its own.
@@ -259,8 +261,16 @@ func testTheClientCarriesTheRootActsAndSaysARefusal(t *testing.T) {
}
func testTheRootHelperIsRootWithNoBusAndNoSudoRule(t *testing.T) {
m := manifest(t)
r := m.resource(t, "root-helper")
manifestJSON, err := os.ReadFile("../../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)
}
r := resourceOf(t, m, "root-helper")
if r["type"] != "process" || r["name"] != "pacman-root" || r["artifact"] != "tools" ||
strings.Join(strs(r["run"]), " ") != "./"+binaryName+" root" {
t.Fatalf("the root helper: %v", r)
@@ -275,7 +285,7 @@ func testTheRootHelperIsRootWithNoBusAndNoSudoRule(t *testing.T) {
if env[EnvRootSocket] != RootSocketPath || env[EnvRootPeer] != "pacman-keeper" {
t.Errorf("the root helper's environment names its socket and the keeper's account: %v", env)
}
k := m.resource(t, "keeper")
k := resourceOf(t, m, "keeper")
kenv, _ := k["env"].(map[string]any)
if kenv[EnvRootSocket] != RootSocketPath {
t.Errorf("the keeper is told the helper's socket: %v", kenv)
+19 -35
View File
@@ -1,39 +1,15 @@
package main
import (
"encoding/json"
"os"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
type resource map[string]any
type manifestShape struct {
Module string `json:"module"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Claims []map[string]any `json:"claims"`
Tools []string `json:"tools"`
Resources []resource `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
func manifest(t *testing.T) manifestShape {
t.Helper()
raw, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
}
var m manifestShape
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
return m
}
func (m manifestShape) resource(t *testing.T, id string) resource {
func resourceOf(t *testing.T, m catalogue.Manifest, id string) resource {
t.Helper()
for _, r := range m.Resources {
if r["id"] == id {
@@ -47,7 +23,15 @@ func (m manifestShape) resource(t *testing.T, id string) resource {
// TestToolsAreTheManifests holds the served tools and the manifest's list to one another, and the
// bundle to the shape the builder compiles and the runtime loads.
func TestToolsAreTheManifests(t *testing.T) {
m := manifest(t)
manifestJSON, err := os.ReadFile("../../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)
}
names := map[string]bool{}
for _, tool := range tools(machine(nil, 1000)) {
if names[tool.Name] {
@@ -64,17 +48,17 @@ func TestToolsAreTheManifests(t *testing.T) {
if len(names) != 0 {
t.Errorf("served and not listed: %v", names)
}
var tools map[string]any
var tools *catalogue.Artifact
for _, a := range m.Build.Artifacts {
if a["name"] == "tools" {
tools = a
if a.Name == "tools" {
tools = &a
}
}
if tools == nil || tools["kind"] != "bundle" || tools["language"] != "go" || tools["system"] != "arch" ||
tools["from"] != "cmd/"+binaryName || tools["binary"] != binaryName {
if tools == nil || tools.Kind != "bundle" || tools.Language != "go" || tools.System != "arch" ||
tools.From != "cmd/"+binaryName || tools.Binary != binaryName {
t.Fatalf("the tools artifact: %v", tools)
}
if loads, _ := tools["loads"].([]any); len(loads) != 1 || loads[0] != binaryName {
t.Fatalf("loads: %v", tools["loads"])
if len(tools.Loads) != 1 || tools.Loads[0] != binaryName {
t.Fatalf("loads: %v", tools.Loads)
}
}
@@ -1,81 +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"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Requires []string `json:"requires"`
Claims []claim `json:"claims"`
Seats []any `json:"seats"`
Tools []string `json:"tools"`
Config map[string]config `json:"config"`
Environment *environment `json:"environment"`
Shell []shellCode `json:"shell"`
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
// config is one config value as the definition declares it (novox/hq ADR 0348 §4).
type config struct {
Type string `json:"type"`
Description string `json:"description"`
Enum []any `json:"enum"`
Minimum *float64 `json:"minimum"`
Maximum *float64 `json:"maximum"`
Pattern string `json:"pattern"`
Trusted bool `json:"trusted"`
Predefined string `json:"predefined"`
Default any `json:"default"`
Required bool `json:"required"`
Runtime bool `json:"runtime"`
}
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 {
@@ -86,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 {
@@ -102,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"])
}
@@ -124,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 {
@@ -133,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)
}
}
}
@@ -146,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)
}
@@ -161,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() {
@@ -203,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)
}
}
+70 -17
View File
@@ -1,9 +1,13 @@
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
@@ -11,34 +15,58 @@ import (
// XDG autostart entry, never by the window manager or the session's start as well.
func TestItClaimsTheCompositorSeatAndRequiresTheXDisplay(t *testing.T) {
m := readManifest(t)
if m.Module != "picom" || 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-compositor", Scope: "node"}}) {
// 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 := m.packages(); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil {
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) {
m := readManifest(t)
m.fromTemplate(t, "configuration", "files/picom.conf")
if p := m.resource(t, "configuration")["path"]; p != "${machine:account-home}/.config/picom/picom.conf" {
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 := m.resource(t, "configuration-dir"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/picom" {
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) {
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)
}
// 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 {
@@ -55,7 +83,15 @@ func TestThePackagesAutostartEntryIsItsOnlyStart(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)
}
@@ -66,14 +102,22 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
// (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) {
m := readManifest(t)
b, d := m.Config["backend"], m.Config["use-damage"]
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.Config)
t.Fatalf("config: %+v", m.Settings)
}
r := m.resource(t, "configuration")
c := m.text(t, "configuration")
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)
@@ -98,5 +142,14 @@ func withDefaults(c string) string {
// 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)
}
@@ -1,13 +1,14 @@
package main
import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// polychromatic's shape (novox/hq ADR 0205, ADR 0208, ADR 0212): no package (the tray is outside the
@@ -15,46 +16,17 @@ import (
// window manager's configuration that is the tray's one start, nothing of the openrazer module's, and
// the Go bundle serving exactly the listed polychromatic_ 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"`
Moved bool `json:"moved"`
Contributions []any `json:"contributions"`
Items []struct {
Collection string `json:"collection"`
Name string `json:"name"`
Template string `json:"template"`
} `json:"items"`
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 TestTheToolsAgreeWithTheManifest(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 TestTheToolsAgreeWithTheManifest(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
served := map[string]bool{}
for _, tool := range tools() {
served[tool.Name] = true
@@ -75,8 +47,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/polychromatic-tools" || b["binary"] != "polychromatic-tools" {
if b.Kind != "bundle" || b.Language != "go" || b.System != "arch" ||
b.From != "cmd/polychromatic-tools" || b.Binary != "polychromatic-tools" {
t.Errorf("the Go tools bundle: %v", b)
}
s := strings.ToLower(raw)
@@ -88,11 +60,20 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
}
func TestItDeclaresNoPackageAndContributesTheTraysOneStart(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)
if m.Module != "polychromatic" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
t.Fatalf("%+v", m)
}
if m.Resources != nil || m.Capabilities != nil || m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil {
if m.Resources != nil || m.Capabilities != nil || m.Claims != nil || m.DefinesSeats != nil || m.Environment != nil || m.Shell != nil {
t.Fatal("no package (outside the official repositories), no seat, no environment, no xinitrc start")
}
var code []string
@@ -118,7 +99,15 @@ func TestTheContributionParsesInI3(t *testing.T) {
if err != nil {
t.Skip("no i3 here to check with")
}
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)
}
path := filepath.Join(t.TempDir(), "config")
os.WriteFile(path, []byte("set $mod Mod4\n"+displayLines(t, m)), 0o644)
if out, err := exec.Command(i3, "-C", "-c", path).CombinedOutput(); err != nil || strings.Contains(string(out), "ERROR") {
@@ -128,7 +117,7 @@ func TestTheContributionParsesInI3(t *testing.T) {
// 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 manifest) string {
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" {
@@ -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"`
}
+81 -20
View File
@@ -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)
}
@@ -9,6 +9,8 @@ import (
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
const nobody = 4194400
@@ -185,8 +187,16 @@ func TestAnInhibitionTurnsIdleOffAndRestoresWhatWasThereWhenItEndsOrIsStopped(t
}
func TestTheDeclaredTimeoutsAreTheSessionStartsOwn(t *testing.T) {
m := readManifest(t)
code := m.shell(t)[0].Code
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)
}
code := shell(t, m)[0].Code
if !strings.Contains(code, "xset s "+strconv.Itoa(declaredLock)+" "+strconv.Itoa(declaredLock)+"\n") ||
!strings.Contains(code, "xset dpms "+strconv.Itoa(declaredStandby)+" "+strconv.Itoa(declaredSuspend)+" "+strconv.Itoa(declaredOff)+"\n") {
t.Fatalf("the tools' declared values and the session start's disagree:\n%s", code)
@@ -1,64 +1,19 @@
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"`
Version string `json:"version"`
Moved bool `json:"moved"`
Items []item `json:"items"`
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"`
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"`
}
// An item of a collection (novox/hq ADR 0349 clause 13): its text is the template file beside the manifest.
type item struct {
Collection string `json:"collection"`
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Template string `json:"template"`
}
// shell is the code the module adds to a shell's or the session's start, read from the templates of its items of
// the collections shell:<file>:<slot>, in the order they are declared.
func (m manifest) shell(t *testing.T) []shellCode {
func shell(t *testing.T, m catalogue.Manifest) []catalogue.ShellCode {
t.Helper()
var out []shellCode
var out []catalogue.ShellCode
for _, it := range m.Items {
parts := strings.Split(it.Collection, ":")
if len(parts) != 3 || parts[0] != "shell" {
@@ -68,15 +23,15 @@ func (m manifest) shell(t *testing.T) []shellCode {
if err != nil {
t.Fatal(err)
}
out = append(out, shellCode{For: parts[1], Slot: parts[2], Code: string(text)})
out = append(out, catalogue.ShellCode{For: parts[1], Slot: parts[2], Code: string(text)})
}
return out
}
// environmentOf is the variables the module sets, read from the templates of its items of the environment.
func (m manifest) environmentOf(t *testing.T) *environment {
func environmentOf(t *testing.T, m catalogue.Manifest) *catalogue.Environment {
t.Helper()
var env *environment
var env *catalogue.Environment
for _, it := range m.Items {
if it.Collection != "environment" || it.Attributes["kind"] != "variable" {
continue
@@ -86,30 +41,14 @@ func (m manifest) environmentOf(t *testing.T) *environment {
t.Fatal(err)
}
if env == nil {
env = &environment{Variables: map[string]string{}}
env = &catalogue.Environment{Variables: map[string]string{}}
}
env.Variables[it.Attributes["name"]] = strings.TrimSuffix(string(text), "\n")
}
return env
}
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)
}
m.Environment = m.environmentOf(t)
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 {
@@ -120,7 +59,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 {
@@ -136,9 +75,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"])
}
@@ -158,7 +97,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 {
@@ -167,10 +106,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)
}
}
}
@@ -180,9 +119,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)
}
@@ -195,7 +134,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() {
@@ -237,14 +176,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)
}
}
@@ -1,9 +1,13 @@
package main
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// screen-lock's shape (novox/hq ADR 0208, research 026/04): it claims node-lock-screen serving lock,
@@ -12,11 +16,19 @@ import (
// the timeouts once, from the session's start. The lock key is the window manager's.
func TestItClaimsTheLockScreenSeatServingLockAndRequiresTheXDisplay(t *testing.T) {
m := readManifest(t)
if m.Module != "screen-lock" || 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-lock-screen", Scope: "node", Serves: []string{"lock"}}}) {
// 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 != "screen-lock" || m.DefinesSeats != nil {
t.Fatalf("module %q declares seats %v", m.Module, m.DefinesSeats)
}
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-lock-screen", Scope: "node", Serves: []string{"lock"}}}) {
t.Fatalf("claims: %+v", m.Claims)
}
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
@@ -25,17 +37,25 @@ func TestItClaimsTheLockScreenSeatServingLockAndRequiresTheXDisplay(t *testing.T
}
func TestTheColourBuildIsKeptWithAFallbackAndXscreensaverGoes(t *testing.T) {
m := readManifest(t)
present, absent := m.packages()
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)
}
present, absent := packages(m)
if !reflect.DeepEqual(present, []string{"xss-lock", "i3lock"}) || !reflect.DeepEqual(absent, []string{"xscreensaver"}) {
t.Fatalf("packages: %v, absent %v", present, absent)
}
m.fromTemplate(t, "wrapper", "files/bin/screen-lock")
wrapper := m.resource(t, "wrapper")
fromTemplate(t, m, "wrapper", "files/bin/screen-lock")
wrapper := resource(t, m, "wrapper")
if wrapper["mode"] != "0755" || wrapper["path"] != "${machine:account-home}/.local/bin/screen-lock" {
t.Fatalf("the locker: %v", wrapper)
}
c := m.text(t, "wrapper")
c := templateText(t, m, "wrapper")
// The colour build's options only once it has said it is the colour build: the distribution's
// i3lock refuses an option it does not know, and the screen would not lock at all.
check := strings.Index(c, `i3lock --version 2>&1 | grep -qE '[0-9]\.c\.[0-9]'`)
@@ -52,11 +72,19 @@ func TestTheColourBuildIsKeptWithAFallbackAndXscreensaverGoes(t *testing.T) {
}
func TestTheSessionStartSetsTheTimeoutsAndKeepsOneWatcherForTheSession(t *testing.T) {
m := readManifest(t)
if len(m.shell(t)) != 1 || m.shell(t)[0].For != "xinitrc" || m.shell(t)[0].Slot != "normal" {
t.Fatalf("one xinitrc contribution in normal: %+v", m.shell(t))
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
code := m.shell(t)[0].Code
// 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 len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "normal" {
t.Fatalf("one xinitrc contribution in normal: %+v", shell(t, m))
}
code := shell(t, m)[0].Code
if strings.Count(code, "xss-lock --") != 1 || !strings.Contains(code, "--transfer-sleep-lock") ||
!strings.Contains(code, "while kill -0 $$") || !strings.HasSuffix(strings.TrimSpace(code), "&") {
t.Fatalf("the watcher: %q", code)
@@ -72,7 +100,15 @@ func TestTheSessionStartSetsTheTimeoutsAndKeepsOneWatcherForTheSession(t *testin
}
func TestTheLockKeyIsTheWindowManagersNotThisModules(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)
}
// The i3 module binds $mod+Delete to logind's lock, which names no locker; a binding here as well
// would be i3's duplicate.
for _, r := range m.Resources {
@@ -83,12 +119,29 @@ func TestTheLockKeyIsTheWindowManagersNotThisModules(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)
}
+31 -42
View File
@@ -1,12 +1,13 @@
package main
import (
"encoding/json"
"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
@@ -14,46 +15,17 @@ import (
// 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.
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"`
Moved bool `json:"moved"`
Contributions []any `json:"contributions"`
Items []struct {
Collection string `json:"collection"`
Name string `json:"name"`
Template string `json:"template"`
} `json:"items"`
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 TestItInstallsNothingAndOwnsNoFile(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 TestItInstallsNothingAndOwnsNoFile(t *testing.T) {
m, raw := readManifest(t)
raw := string(manifestJSON)
if m.Module != "slack" || !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
t.Fatalf("%+v", m)
}
@@ -61,7 +33,7 @@ func TestItInstallsNothingAndOwnsNoFile(t *testing.T) {
if m.Resources != nil || m.Capabilities != nil {
t.Fatalf("no package, no file: %v %v", m.Resources, m.Capabilities)
}
if m.Claims != nil || m.Seats != nil || m.Environment != nil || m.Shell != nil {
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.
@@ -73,7 +45,15 @@ func TestItInstallsNothingAndOwnsNoFile(t *testing.T) {
}
func TestTheOneContributionIsTheStartAndTheWindowRules(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)
}
content := displayLines(t, m)
if !strings.HasSuffix(content, "\n") {
t.Fatalf("%q", content)
@@ -121,7 +101,16 @@ func TestTheOneContributionIsTheStartAndTheWindowRules(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
@@ -142,8 +131,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/slack-tools" || b["binary"] != "slack-tools" {
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)
@@ -156,7 +145,7 @@ func TestTheToolsAgreeWithTheManifest(t *testing.T) {
// 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 manifest) string {
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" {
+11 -1
View File
@@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// Slack's settings as Slack writes them, with keys no answer may carry.
@@ -108,7 +110,15 @@ func newSlack(t *testing.T) (*fake, map[string]string) {
}
func contribution(t *testing.T) string {
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)
}
return displayLines(t, m)
}