Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)

This commit is contained in:
2026-10-16 07:37:43 +00:00
parent 1a2c917abf
commit 9652b2d5ce
771 changed files with 52063 additions and 1774 deletions
@@ -15,16 +15,16 @@ func TestTheFilesSayWhatTheToolsCompareAgainst(t *testing.T) {
t.Fatalf("%s %s", m.Module, m.Version)
}
locale := m.resource(t, "locale")
if locale["path"] != "/etc/locale.conf" || locale["into"] != nil || !strings.Contains(locale["content"].(string), "\nLANG="+MeshLang+"\n") {
if locale["path"] != "/etc/locale.conf" || locale["into"] != nil || !strings.Contains(templateText(t, locale), "\nLANG="+MeshLang+"\n") {
t.Fatalf("locale: %v", locale)
}
keymap := m.resource(t, "keymap")
if keymap["path"] != "/etc/vconsole.conf" || !strings.Contains(keymap["content"].(string), "\nKEYMAP="+MeshKeymap+"\n") {
if keymap["path"] != "/etc/vconsole.conf" || !strings.Contains(templateText(t, keymap), "\nKEYMAP="+MeshKeymap+"\n") {
t.Fatalf("keymap: %v", keymap)
}
for _, r := range []resource{locale, keymap} {
var settings []string
for _, l := range strings.Split(r["content"].(string), "\n") {
for _, l := range strings.Split(templateText(t, r), "\n") {
if l != "" && !strings.HasPrefix(l, "#") {
settings = append(settings, l)
}
@@ -0,0 +1,64 @@
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
// The module's directory, where its manifest and its files/ are.
const moduleDir = "../.."
// templateText is the text a file resource places on the machine: its template's, in the module's files/
// (novox/hq ADR 0349 §2). A resource that names no template, or a template that is not there, fails the test.
func templateText(t *testing.T, r map[string]any) string {
t.Helper()
name, _ := r["template"].(string)
if name == "" {
t.Fatalf("resource %v names no template", r["id"])
}
raw, err := os.ReadFile(filepath.Join(moduleDir, filepath.FromSlash(name)))
if err != nil {
t.Fatalf("resource %v names %s: %v", r["id"], name, err)
}
return string(raw)
}
// No file resource carries its text inline: each names its template in files/, and the build packs files/
// into the one archive the controller reads the templates back from (novox/hq ADR 0349 §2).
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Resources []map[string]any `json:"resources"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
for _, r := range m.Resources {
if _, inline := r["content"]; inline {
t.Errorf("resource %v keeps its text inline: keep it in files/ and name it as the template", r["id"])
}
if r["type"] == "file" {
templateText(t, r)
}
}
packs := 0
for _, a := range m.Build.Artifacts {
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 packs != 1 {
t.Errorf("the build packs files/ into %d archives, not one", packs)
}
}
+3
View File
@@ -0,0 +1,3 @@
# The mesh's (module localization, novox/hq to-be 42): the system locale. Written whole at every
# push; an edit here is overwritten. Read at the next login.
LANG=en_US.UTF-8
+3
View File
@@ -0,0 +1,3 @@
# The mesh's (module localization, novox/hq to-be 42): the console keymap. Written whole at every
# push; an edit here is overwritten. Read at the next boot.
KEYMAP=us
+7 -2
View File
@@ -16,14 +16,14 @@
"type": "file",
"path": "/etc/locale.conf",
"mode": "0644",
"content": "# The mesh's (module localization, novox/hq to-be 42): the system locale. Written whole at every\n# push; an edit here is overwritten. Read at the next login.\nLANG=en_US.UTF-8\n"
"template": "files/locale.conf"
},
{
"id": "keymap",
"type": "file",
"path": "/etc/vconsole.conf",
"mode": "0644",
"content": "# The mesh's (module localization, novox/hq to-be 42): the console keymap. Written whole at every\n# push; an edit here is overwritten. Read at the next boot.\nKEYMAP=us\n"
"template": "files/vconsole.conf"
},
{
"id": "time-zone",
@@ -50,6 +50,11 @@
"loads": [
"localization-tools"
]
},
{
"name": "files",
"kind": "archive",
"from": "files"
}
]
}