PR #1916 rule: a refusal names the field or file, never a config value or a host path. readJsonFile's three refusals and parseJsonFileText now name the file by its `what` label only. Callers whose label alone is ambiguous add a name that already passed a strict pattern (business id, role name, org id, turn id, project key) or a fixed path under the data root. Exit codes, refusal codes and check order are unchanged. organization: util, access, project, config-command, library-seats, org-service deleteOrg receipt, agent-levels regex; T1 files role.mjs and organization-config.mjs change only the readJsonFile label. cli: access lock, accounts owner, host state/lock, notifier journal, notify-config, run-evidence, dev-fixture, git-socket, org-bus, org-console. discord: turn record label names the turn id. Sentinel tests (sk-test-NOT-A-SECRET-1234 as a path component) cover each changed refusal and fail on BASE; old path pins updated.
40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
// The project file, <root>/.mosaic/project.json. It lives in the project's
|
|
// repository and changes by reviewed commits there. The stack only reads it.
|
|
|
|
import { isAbsolute, join, normalize } from "node:path";
|
|
import { refuse } from "./errors.mjs";
|
|
import { checkVars } from "./vars.mjs";
|
|
import { requireObject, rejectUnknownKeys, requireId, readJsonFile, deepFreeze } from "./util.mjs";
|
|
|
|
export function projectFilePath(root) {
|
|
return join(root, ".mosaic", "project.json");
|
|
}
|
|
|
|
// Refusals name the project file by label: its path is the project root from
|
|
// the business file, a config value, so no refusal quotes it (PR #1916). An
|
|
// instance name is quoted only after requireId passed it.
|
|
export function validateProjectDocument(document, file) {
|
|
requireObject(document, "project file");
|
|
rejectUnknownKeys(document, ["projectVersion", "id", "vars", "roles"], "project file");
|
|
if (document.projectVersion !== 1) refuse(`project file "projectVersion" must be 1`);
|
|
requireId(document.id, "project id");
|
|
const vars = checkVars(document.vars ?? {}, "project", "project file vars");
|
|
const roles = {};
|
|
if (document.roles !== undefined) {
|
|
requireObject(document.roles, "project file roles");
|
|
for (const [instance, entry] of Object.entries(document.roles)) {
|
|
requireId(instance, "project file role instance");
|
|
requireObject(entry, `project file roles.${instance}`);
|
|
rejectUnknownKeys(entry, ["vars"], `project file roles.${instance}`);
|
|
roles[instance] = { vars: checkVars(entry.vars ?? {}, "project", `project file roles.${instance}.vars`) };
|
|
}
|
|
}
|
|
return deepFreeze({ projectVersion: 1, id: document.id, file, vars, roles });
|
|
}
|
|
|
|
export function loadProject(root) {
|
|
if (typeof root !== "string" || !isAbsolute(root) || normalize(root) !== root) refuse(`project root must be a normalized absolute path`);
|
|
const file = projectFilePath(root);
|
|
return validateProjectDocument(readJsonFile(file, "project file"), file);
|
|
}
|