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
+39 -11
View File
@@ -8,6 +8,20 @@ import { readFileSync } from "node:fs";
const m = JSON.parse(readFileSync(new URL("../module.json", import.meta.url), "utf8"));
const resource = (id: string) => m.resources.find((r: { id: string }) => r.id === id);
// A file's text is its template's, in the module's files/ (novox/hq ADR 0349 §2).
const text = (r: { id: string; template?: string }): string => {
assert.ok(r.template, `${r.id} names no template`);
return readFileSync(new URL(`../${r.template}`, import.meta.url), "utf8");
};
test("no file carries its text inline: each names its template, and the build packs files/ into one archive", () => {
for (const r of m.resources) {
assert.equal(r.content, undefined, `${r.id} keeps its text inline`);
if (r.type === "file") text(r);
}
const packs = m.build.artifacts.filter((a: { kind: string; from?: string }) => a.kind === "archive" && a.from === "files");
assert.deepEqual(packs.map((a: { name: string }) => a.name), ["files"]);
});
test("it claims node-login-shell serving execute, and declares no seat", () => {
assert.equal(m.seats, undefined);
@@ -19,7 +33,7 @@ test("the .zshrc block is at the start and holds the three slots in order, after
assert.equal(rc.path, "${machine:account-home}/.zshrc");
assert.equal(rc.into, "block");
assert.equal(rc.at, "start");
const c: string = rc.content;
const c = text(rc);
const first = c.indexOf("${shell:zsh:first}");
const normal = c.indexOf("${shell:zsh:normal}");
const last = c.indexOf("${shell:zsh:last}");
@@ -30,7 +44,7 @@ test("the .zshrc block is at the start and holds the three slots in order, after
});
test("the .zshrc block carries the shared defaults and none of the operator's own lines", () => {
const c: string = resource("rc").content;
const c = text(resource("rc"));
for (const want of ["precmd_functions+=(set_terminal_title)", "alias egrep='egrep --color=auto'", "alias ll='ls -alhF'", "alias drun=", "disksize()", "sudo-disksize()"]) {
assert.ok(c.includes(want), want);
}
@@ -45,17 +59,28 @@ test("the .zshenv block sources exactly the environment file node-environment fi
assert.equal(env.path, "${machine:account-home}/.zshenv");
assert.equal(env.into, "block");
assert.equal(env.at, "start");
const sourced = [...(env.content as string).matchAll(/^\s*(?:source|\.)\s+"?([^"\s]+)"?/gm)].map((x) => x[1]);
const sourced = [...text(env).matchAll(/^\s*(?:source|\.)\s+"?([^"\s]+)"?/gm)].map((x) => x[1]);
assert.deepEqual(sourced, ["${machine:account-home}/.config/mesh/environment.sh"]);
});
test("its environment is a contribution: the editor, the configuration home, and three PATH entries at the start", () => {
assert.deepEqual(m.environment.variables, { EDITOR: "vim", VISUAL: "vim", XDG_CONFIG_HOME: "${machine:account-home}/.config" });
assert.deepEqual(m.environment.path, [
// The contribution is typed items of the environment collection, each with its value in a template (ADR 0348, 0349).
const items = m.items.filter((i: { collection: string }) => i.collection === "environment");
const value = (i: { template: string }) => readFileSync(new URL(`../${i.template}`, import.meta.url), "utf8").trim();
const variables = Object.fromEntries(
items.filter((i: { attributes: { kind: string } }) => i.attributes.kind === "variable").map((i: { attributes: { name: string }; template: string }) => [i.attributes.name, value(i)]),
);
assert.deepEqual(variables, { EDITOR: "vim", VISUAL: "vim", XDG_CONFIG_HOME: "${machine:account-home}/.config" });
const path = items
.filter((i: { attributes: { kind: string } }) => i.attributes.kind === "path")
.sort((a: { attributes: { order: string } }, b: { attributes: { order: string } }) => Number(a.attributes.order) - Number(b.attributes.order))
.map((i: { attributes: { at: string }; template: string }) => ({ entry: value(i), at: i.attributes.at }));
assert.deepEqual(path, [
{ entry: "${machine:account-home}/.local/bin", at: "start" },
{ entry: "${machine:account-home}/scripts", at: "start" },
{ entry: "${machine:account-home}/scripts/bin", at: "start" },
]);
assert.equal(m.environment, undefined);
});
test("it keeps the package and sets the login shell through the user shape", () => {
@@ -70,11 +95,14 @@ test("the tools bundle registers the seat's verb under node-login-shell", () =>
assert.doesNotMatch(src, /runuser|"login-shell"/);
});
test("execute is a per-machine setting, served unless a machine withholds it (ADR 0268)", () => {
assert.deepEqual(Object.keys(m.settings), ["execute"]);
assert.equal(m.settings.execute.kind, "preference");
assert.equal(m.settings.execute.default, "serve");
assert.match(m.settings.execute.why, /withhold/);
test("execute is a per-machine config value, served unless a machine withholds it (ADR 0268, ADR 0348 §4)", () => {
assert.equal(m.settings, undefined);
assert.deepEqual(Object.keys(m.config), ["execute"]);
assert.equal(m.config.execute.type, "string");
assert.deepEqual(m.config.execute.enum, ["serve", "withhold"]);
assert.equal(m.config.execute.trusted, true, "it decides what runs, so it is set at the terminal or on an approval");
assert.equal(m.config.execute.default, "serve");
assert.match(m.config.execute.description, /withhold/);
const dir = resource("state");
assert.deepEqual(dir, { id: "state", type: "directory", place: ".", owner: "root", mode: "0755" });
const conf = resource("tools-conf");
@@ -82,7 +110,7 @@ test("execute is a per-machine setting, served unless a machine withholds it (AD
assert.equal(conf.path, "${dir:state}/tools.conf");
assert.equal(conf.owner, "root", "the account the runtime runs as may read it, never change it");
assert.equal(conf.mode, "0644");
assert.match(conf.content, /^execute=\$\{setting:execute\}$/m);
assert.match(text(conf), /^execute=\$\{config:execute\}$/m);
const [bundle] = m.build.artifacts;
assert.deepEqual(bundle.env, { ZSH_TOOLS_CONF: conf.path }, "the word names the file exactly, so its change restarts the runtime");
});