M8 networkmanager: the manifest declares the sign-in parts

The manifest declares the watcher as a process run as the account with uplink_health
as its health, the folder the two parts share (the account's, 0700), the running event
the bundle consumes, the three verbs it invokes and its five tools.

Builds: design 08 sign-in-page §11, §12, §13, §27
This commit is contained in:
jochen
2026-11-24 21:26:14 +01:00
parent 1dec6eb02c
commit dc27af2227
2 changed files with 103 additions and 0 deletions
@@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
)
@@ -62,3 +63,64 @@ func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
t.Errorf("the build packs files/ into %d archives, not one", packs)
}
}
// The manifest declares the watcher's process as the account, with the health of its tool; the folder the two parts
// share, the account's alone; the event the bundle consumes and the verbs it invokes; and the five tools, the health
// tool among them (design 08 sign-in-page §11, §12, §13, §27).
func TestTheManifestDeclaresTheSignInParts(t *testing.T) {
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Consumes []string `json:"consumes"`
Invokes []string `json:"invokes"`
Tools []string `json:"tools"`
Claims []map[string]any `json:"claims"`
Resources []map[string]any `json:"resources"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
same := func(got []string, want ...string) bool {
return strings.Join(got, " ") == strings.Join(want, " ")
}
if !same(m.Consumes, "node-engine.running") {
t.Errorf("consumes %v", m.Consumes)
}
if !same(m.Invokes, "seat:mesh-module-assigner.assignments", "seat:node-resolver.uplink-names", "seat:node-resolver.routes") {
t.Errorf("invokes %v", m.Invokes)
}
var served []string
for _, tool := range (&bundle{}).tools() {
served = append(served, tool.Name)
}
if !same(m.Tools, served...) {
t.Errorf("lists the tools %v, serves %v", m.Tools, served)
}
if len(m.Claims) != 1 || m.Claims[0]["name"] != "node-uplink" {
t.Errorf("claims %v", m.Claims)
}
byID := map[string]map[string]any{}
for _, r := range m.Resources {
byID[r["id"].(string)] = r
}
dir := byID["sign-in-state"]
if dir["type"] != "directory" || dir["path"] != "${machine:account-home}/"+stateHome ||
dir["owner"] != "${machine:account}" || dir["mode"] != "0700" {
t.Errorf("the folder is %v", dir)
}
p := byID["sign-in"]
run, _ := json.Marshal(p["run"])
h, _ := json.Marshal(p["health"])
if p["type"] != "process" || p["name"] != "networkmanager-sign-in" || p["artifact"] != "tools" ||
string(run) != `["./uplink-tools","watch"]` || p["user"] != "${machine:account}" ||
string(h) != `{"grace":"60s","interval":"60s","kind":"tool","looks":2,"timeout":"20s","tool":"uplink_health"}` {
t.Errorf("the watcher is %v", p)
}
for _, id := range []string{"package", "config", "service"} {
if byID[id] == nil {
t.Errorf("the resource %s is gone", id)
}
}
}
+41
View File
@@ -21,6 +21,21 @@
"scope": "node"
}
],
"consumes": [
"node-engine.running"
],
"invokes": [
"seat:mesh-module-assigner.assignments",
"seat:node-resolver.uplink-names",
"seat:node-resolver.routes"
],
"tools": [
"uplink_sign_in",
"uplink_names_again",
"uplink_rating_again",
"uplink_publish_again",
"uplink_health"
],
"build": {
"artifacts": [
{
@@ -67,6 +82,32 @@
"reload-on": [
"config"
]
},
{
"id": "sign-in-state",
"type": "directory",
"path": "${machine:account-home}/.local/state/mesh/networkmanager",
"owner": "${machine:account}",
"mode": "0700"
},
{
"id": "sign-in",
"type": "process",
"name": "networkmanager-sign-in",
"artifact": "tools",
"run": [
"./uplink-tools",
"watch"
],
"user": "${machine:account}",
"health": {
"kind": "tool",
"tool": "uplink_health",
"interval": "60s",
"timeout": "20s",
"looks": 2,
"grace": "60s"
}
}
]
}