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
This commit is contained in:
@@ -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"] {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user