Files
mesh-host/packaging/operator_keys_test.go
T
jschoubben 0c01c81c3f E8: run each file's unit tests as subtests of one test
The node-engine held 1,707 top-level unit tests against the budget of 500
a module. Each unit test file with two or more tests now runs them as
subtests of one test named for the file, each named as its function was,
in the same order: every check is kept, and the check counts 383. Files
with a TestMain, a re-run of a test by its name, or the integration tag
are left. Four files of this branch's earlier commits are formatted.

Builds: design 47 H2 §819; H-A-349 DQ-14
2026-11-22 00:30:05 +01:00

159 lines
9.2 KiB
Go

package packaging_test
import (
"encoding/json"
"os"
"reflect"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/declaration"
)
// The operator's public keys reach every node as a file beside the state file, fed by a setting of the node-engine
// (novox/hq ADR 0539 clauses 3 and 11): the node agent reads it, and a composition made by hand is applied only when one
// of these keys signed it. The setting may be empty, and then no operator key is trusted.
func testTheManifestDeclaresTheOperatorKeysFileFedByASetting(t *testing.T) {
raw, err := os.ReadFile("../module.json")
if err != nil {
t.Fatal(err)
}
if _, err := catalogue.Decode(raw); err != nil {
t.Fatalf("the manifest no longer parses: %v", err)
}
var m struct {
Config map[string]struct {
Type string `json:"type"`
Default any `json:"default"`
} `json:"config"`
Resources []struct {
ID string `json:"id"`
Type string `json:"type"`
Path string `json:"path"`
Mode string `json:"mode"`
Content string `json:"content"`
} `json:"resources"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
setting, ok := m.Config["operator-signers"]
if !ok || setting.Type != "string" || setting.Default != "" {
t.Fatalf("the setting operator-signers is %+v: a string that may be empty", setting)
}
for _, r := range m.Resources {
if r.ID != "operator-keys" {
continue
}
if r.Type != "file" || r.Path != "/var/lib/mesh-host/operator-keys" || r.Mode != "0644" ||
!strings.Contains(r.Content, "${config:operator-signers}") {
t.Fatalf("the file is %+v: it is declared beside the state file, 0644, its content the setting", r)
}
return
}
t.Fatal("module.json declares no operator-keys file")
}
// The node agent hears the end of a backup on the event of node-backup's holder, so the manifest consumes it.
func testTheManifestConsumesTheBackupEvent(t *testing.T) {
raw, err := os.ReadFile("../module.json")
if err != nil {
t.Fatal(err)
}
var m struct {
Consumes []string `json:"consumes"`
Uses []string `json:"uses"`
Invokes []any `json:"invokes"` // a verb, or the long form {verb, fields} (§558)
Config map[string]struct {
Default any `json:"default"`
} `json:"config"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
// Design 47 G §630, §633, A-77: the recovery module's three verbs it asks, and its bound as a config key of 90.
// §635, §558, §617: it invokes `withheld` and names no `uses`; the catalog's revision in the long form with the field none-yet.
if len(m.Uses) != 0 {
t.Errorf("uses is %v, want none: the invoke of seat:mesh-grants.withheld is the edge (§635, A-307)", m.Uses)
}
for _, v := range []any{"seat:mesh-recovery.kept-points", "seat:mesh-recovery.restore-kept", "seat:mesh-recovery.snapshot-kept",
"seat:mesh-grants.withheld", "seat:mesh-catalog.module", map[string]any{"verb": "seat:mesh-catalog.revision", "fields": []any{"none-yet"}}} {
if !slices.ContainsFunc(m.Invokes, func(have any) bool { return reflect.DeepEqual(have, v) }) {
t.Errorf("invokes %v lacks %v", m.Invokes, v)
}
}
if !strings.Contains(string(raw), `"content": "${config:view-waits-minutes}\n"`) || m.Config["view-waits-minutes"].Default != float64(5) {
t.Errorf("module.json declares no file with the content ${config:view-waits-minutes} or its default is not 5 (§633)")
}
if !strings.Contains(string(raw), `"content": "${config:recovery-wait-minutes}\n"`) {
t.Errorf("module.json declares no file with the content ${config:recovery-wait-minutes} (design 47 G A-112)")
}
if !strings.Contains(string(raw), `"content": "${config:entry-asks}\n"`) || m.Config["entry-asks"].Default != float64(5) {
t.Errorf("module.json declares no file with the content ${config:entry-asks} or its default is not 5 (design 47 H, H-A-60)")
}
if !strings.Contains(string(raw), `"content": "${config:resolve-again-minutes}\n"`) || m.Config["resolve-again-minutes"].Default != float64(1) {
t.Errorf("module.json declares no file with the content ${config:resolve-again-minutes} or its default is not 1 (design 47 H, H-A-146)")
}
// Design 08 control-verbs §1, H-A-314 (3), (5): the compose-ask bound, ten seconds by default, fed into its file; allowed invoked.
if !strings.Contains(string(raw), `"content": "${config:compose-ask-bound}\n"`) || m.Config["compose-ask-bound"].Default != float64(10) ||
!strings.Contains(string(raw), `"seat:node-packet-filter.allowed"`) {
t.Errorf("module.json declares no file with the content ${config:compose-ask-bound}, its default is not 10, or it invokes no seat:node-packet-filter.allowed")
}
if m.Config["recovery-wait-minutes"].Default != float64(90) {
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
}
// The backup event, the status view's settled, and the two events of the seat that serves the seat list (ADR 0636 §4), the keeper's ask (design 47 G §387), the seat's running (§199) and the builder's build ends (A-293).
if want := []string{"mesh-catalog.catalog-revision", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "node-packet-filter.allowances-changed", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
t.Fatalf("consumes %v, want %v", m.Consumes, want)
}
// 774: the acts bucket mesh-host_acts is not declared as state for now: a declared state of a module with no account
// of its own is carried by every node's tool runner, which would be a second writer of the engine's own keys and
// has the grants part refuse the whole user list (2026-10-30). It comes back once the runtime never carries the engine.
parsed, err := catalogue.Decode(raw)
if err != nil {
t.Fatal(err)
}
// ADR 0614 §4: the node-engine's own manifest uses only words every running engine reads (the baseline, what an engine
// stating none is read as), so its new build is never held for a word only it reads; but for its class and the
// declaration Version it reads, which an engine before them cannot state, so its build is held for a yes once at that
// delivery (H-A-388 and its addendum, H-A-394).
if needs, err := catalogue.ManifestNeeds(raw); err != nil || len(needs) == 0 {
t.Fatalf("the manifest's needs: %v, %v", needs, err)
} else if missing := catalogue.MissingManifestReads(needs, nil); !slices.Equal(missing, []string{"word:class", "word:declaration-reads"}) {
t.Errorf("the manifest needs %v, which an engine stating nothing does not read: its new build would be held", missing)
}
// Design 47 H2 §813 (12), H-A-388: it states the declaration Version it reads, the one its contract parses, so the
// delivery plan orders the composer that writes that Version after it.
// H-A-394 (1): a module that claims a seat is core.
if parsed, err := catalogue.Decode(raw); err != nil || parsed.Class != catalogue.ClassCore {
t.Errorf("the manifest's class is %q, and the node-engine claims a seat (%v)", parsed.Class, err)
}
if parsed, err := catalogue.Decode(raw); err != nil || parsed.DeclarationReads != declaration.Version {
t.Errorf("the manifest states it reads declaration Version %d, and the engine reads %d (%v)", parsed.DeclarationReads, declaration.Version, err)
}
// 774 (the alert table): the state health, one key per node, the node's own health report, kept until
// written again (no TTL: a node that stops writing keeps its last word, which the watchman reads with its time).
// ADR 0577 clause 1: and the state data, one key per module placed on the node that declares data items, kept until
// the module leaves the node; created by the grants part from this manifest as health is.
// ADR 0565 clause 6: and the state packages, one key per node, its compositions' declared packages, read by pacman.
// ADR 0564 §2, ADR 0636 §1: and the state findings, the node's finding that it waits for the seat list (no TTL: the
// finding stays until the first full read deletes its key).
// Design 47 G A-92: and the state bounds, each key a wait's bound with its own lifetime, one value a key.
// Design 47 H2 §775, §820, H-A-364: and the state taken, the asks taken once, each key for its ask's bound, 8 MiB.
if len(parsed.State) != 6 || parsed.State[0].Name != "health" || parsed.State[0].TTLSeconds != 0 ||
parsed.State[1].Name != "findings" || parsed.State[1].TTLSeconds != 0 ||
parsed.State[2].Name != "data" || parsed.State[2].TTLSeconds != 0 || parsed.State[3].Name != "packages" ||
parsed.State[3].TTLSeconds != 0 || parsed.State[4].Name != "bounds" || !parsed.State[4].KeyTTL || parsed.State[4].History != 1 ||
parsed.State[5].Name != "taken" || !parsed.State[5].KeyTTL || parsed.State[5].History != 1 || parsed.State[5].MaxMiB != 8 {
t.Fatalf("the manifest declares the state %+v", parsed.State)
}
}
// TestOperatorKeys runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestOperatorKeys(t *testing.T) {
t.Run("TheManifestDeclaresTheOperatorKeysFileFedByASetting", testTheManifestDeclaresTheOperatorKeysFileFedByASetting)
t.Run("TheManifestConsumesTheBackupEvent", testTheManifestConsumesTheBackupEvent)
}