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:
@@ -56,7 +56,7 @@ type fcDoc struct {
|
||||
|
||||
func TestTheFontconfigFileMapsEachGenericToTheDecidedFaceStronglyAndFallsBackLast(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
content, _ := m.resource("defaults")["content"].(string)
|
||||
content := templateText(t, m.resource("defaults"))
|
||||
if !strings.HasPrefix(content, "<?xml") || !strings.Contains(content, `<!DOCTYPE fontconfig`) {
|
||||
t.Fatal("not a fontconfig document")
|
||||
}
|
||||
|
||||
@@ -86,8 +86,10 @@ func holdsTheBundle(t *testing.T, m manifest, prefix string) {
|
||||
if strings.Join(registered, ",") != strings.Join(m.Tools, ",") {
|
||||
t.Errorf("registered %v, listed %v", registered, m.Tools)
|
||||
}
|
||||
if len(m.Build.Artifacts) != 1 {
|
||||
t.Fatalf("one artifact, got %d", len(m.Build.Artifacts))
|
||||
// The bundle, and beside it only the archive the build packs the templates in files/ into (novox/hq ADR
|
||||
// 0349 §2).
|
||||
if len(m.Build.Artifacts) != 2 || m.Build.Artifacts[1]["name"] != "files" {
|
||||
t.Fatalf("the bundle and the templates archive, got %v", m.Build.Artifacts)
|
||||
}
|
||||
cwd, _ := os.Getwd()
|
||||
binary := filepath.Base(cwd)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
|
||||
<!--
|
||||
The mesh's file (module fonts, novox/hq research 026/04): which face each generic family means for
|
||||
this account, so every program that asks for monospace, sans-serif, serif or emoji gets the same
|
||||
face. Replaced at every push. Other files in this directory are yours.
|
||||
-->
|
||||
<fontconfig>
|
||||
<description>The mesh: the faces monospace, sans-serif, serif and emoji mean</description>
|
||||
|
||||
<!--
|
||||
Families the desktop's files named before this module, mapped to monospace for as long as they
|
||||
are not installed: a configuration still naming one gets the chosen monospace face rather than
|
||||
fontconfig's last resort, sans-serif. Where the family is still installed, it is used as before.
|
||||
Placed first, so the monospace they lead to is resolved by the rule below.
|
||||
-->
|
||||
<alias><family>Hack Nerd Font</family><accept><family>monospace</family></accept></alias>
|
||||
<alias><family>MesloLGS NF</family><accept><family>monospace</family></accept></alias>
|
||||
<alias><family>Iosevka Nerd Font</family><accept><family>monospace</family></accept></alias>
|
||||
<alias><family>JetBrains Mono Nerd Font</family><accept><family>JetBrainsMono Nerd Font</family></accept></alias>
|
||||
|
||||
<!--
|
||||
The decided faces, bound the same as the request: a program asking for monospace asks strongly,
|
||||
and a face added weakly loses to the distribution's own choice (measured with fontconfig 2.18).
|
||||
-->
|
||||
<alias binding="same"><family>monospace</family><prefer><family>JetBrainsMono Nerd Font</family></prefer></alias>
|
||||
<alias binding="same"><family>sans-serif</family><prefer><family>Inter</family><family>Noto Sans</family></prefer></alias>
|
||||
<alias binding="same"><family>system-ui</family><prefer><family>Inter</family></prefer></alias>
|
||||
<alias binding="same"><family>serif</family><prefer><family>Noto Serif</family></prefer></alias>
|
||||
<alias binding="same"><family>emoji</family><prefer><family>Noto Color Emoji</family></prefer></alias>
|
||||
|
||||
<!--
|
||||
Fallbacks for any face: an icon a face lacks comes from the Nerd Fonts symbols, an emoji from
|
||||
Noto Color Emoji. Appended last, so they never displace a face that has the character.
|
||||
-->
|
||||
<match target="pattern">
|
||||
<edit name="family" mode="append_last"><string>Symbols Nerd Font</string></edit>
|
||||
<edit name="family" mode="append_last"><string>Noto Color Emoji</string></edit>
|
||||
</match>
|
||||
</fontconfig>
|
||||
@@ -44,7 +44,7 @@
|
||||
"path": "${machine:account-home}/.config/fontconfig/conf.d/50-mesh-fonts.conf",
|
||||
"owner": "${machine:account}",
|
||||
"mode": "0644",
|
||||
"content": "<?xml version=\"1.0\"?>\n<!DOCTYPE fontconfig SYSTEM \"urn:fontconfig:fonts.dtd\">\n<!--\n The mesh's file (module fonts, novox/hq research 026/04): which face each generic family means for\n this account, so every program that asks for monospace, sans-serif, serif or emoji gets the same\n face. Replaced at every push. Other files in this directory are yours.\n-->\n<fontconfig>\n <description>The mesh: the faces monospace, sans-serif, serif and emoji mean</description>\n\n <!--\n Families the desktop's files named before this module, mapped to monospace for as long as they\n are not installed: a configuration still naming one gets the chosen monospace face rather than\n fontconfig's last resort, sans-serif. Where the family is still installed, it is used as before.\n Placed first, so the monospace they lead to is resolved by the rule below.\n -->\n <alias><family>Hack Nerd Font</family><accept><family>monospace</family></accept></alias>\n <alias><family>MesloLGS NF</family><accept><family>monospace</family></accept></alias>\n <alias><family>Iosevka Nerd Font</family><accept><family>monospace</family></accept></alias>\n <alias><family>JetBrains Mono Nerd Font</family><accept><family>JetBrainsMono Nerd Font</family></accept></alias>\n\n <!--\n The decided faces, bound the same as the request: a program asking for monospace asks strongly,\n and a face added weakly loses to the distribution's own choice (measured with fontconfig 2.18).\n -->\n <alias binding=\"same\"><family>monospace</family><prefer><family>JetBrainsMono Nerd Font</family></prefer></alias>\n <alias binding=\"same\"><family>sans-serif</family><prefer><family>Inter</family><family>Noto Sans</family></prefer></alias>\n <alias binding=\"same\"><family>system-ui</family><prefer><family>Inter</family></prefer></alias>\n <alias binding=\"same\"><family>serif</family><prefer><family>Noto Serif</family></prefer></alias>\n <alias binding=\"same\"><family>emoji</family><prefer><family>Noto Color Emoji</family></prefer></alias>\n\n <!--\n Fallbacks for any face: an icon a face lacks comes from the Nerd Fonts symbols, an emoji from\n Noto Color Emoji. Appended last, so they never displace a face that has the character.\n -->\n <match target=\"pattern\">\n <edit name=\"family\" mode=\"append_last\"><string>Symbols Nerd Font</string></edit>\n <edit name=\"family\" mode=\"append_last\"><string>Noto Color Emoji</string></edit>\n </match>\n</fontconfig>\n"
|
||||
"template": "files/50-mesh-fonts.conf"
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
@@ -59,6 +59,11 @@
|
||||
"loads": [
|
||||
"fonts-tools"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "files",
|
||||
"kind": "archive",
|
||||
"from": "files"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user