Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

feat(blueprint): a rule names its source, and its row keeps it [S1]

Corey Olsond38541a23950
diff --git a/docs/formats.md b/docs/formats.md
index dfc0bce0..e7d345e4 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -40,7 +40,7 @@ The identifier expression, statuses and tiers below come from the parser:
| `aim` | An aim; no gate is required. |
<!-- tiers:end -->
-After the requirement text, `gate:` names the check, `serves:` names comma-separated ids, and `signers:` names comma-separated SSH principals; each field may be omitted. Each signer is one unique principal with no spaces, commas or leading `#`; the list names the exact principals required for signed sign-offs. An approved row is met only when every listed principal has a verified SSH receipt for its current text; missing, stale or unverified receipts leave it unmet. Other trailing keys are recorded as unknown and rejected by `spec check`. A malformed row-like line is an error, and rows inside fenced code blocks are examples rather than input. IDs are permanent: mark a cut row `wont` or `retired` instead of deleting it.
+After the requirement text, `gate:` names the check, `serves:` names comma-separated ids, and `signers:` names comma-separated SSH principals; each field may be omitted. Each signer is one unique principal with no spaces, commas or leading `#`; the list names the exact principals required for signed sign-offs. An approved row is met only when every listed principal has a verified SSH receipt for its current text; missing, stale or unverified receipts leave it unmet. A row may also carry `source:`, the reference a blueprint rule came from, written as its name, then its id and address when it has them (`| source: Example Framework OPS 8 https://example.com/ops-8`). The parsed row gains a `source` string only when the field is written, so a row without one parses exactly as before; an empty `source:` is an error. `spec show` prints the source and `spec --json` rows carry it. Other trailing keys are recorded as unknown and rejected by `spec check`. A malformed row-like line is an error, and rows inside fenced code blocks are examples rather than input. IDs are permanent: mark a cut row `wont` or `retired` instead of deleting it.
The row object returned by `parseSpec` has these fields:
@@ -65,6 +65,10 @@ A bare id names a row in `SPEC.md`. A doctrine row is cited as `doctrine:<id>` i
| `line` | 1-based source line. |
<!-- parser-fields:end -->
+### Blueprint rule sources
+
+A blueprint is one JSON file (format 1, described at the top of `src/blueprints.js`). Its `kind` is `product`, `architecture`, `practice` or `beyond-code`; a file that says `infrastructure`, the old name, loads as `architecture`. A rule may carry `source: { name, id, url }`: `name` is required, `id` and `url` are optional, each is one line without `|`, and `url` is an `http` or `https` address. `pullboard blueprint add` and `init --blueprint` copy it onto the drafted row's `source:` field; the row's text stays the rule and its reason. Every rule of an architecture blueprint names its source, since it paraphrases a known-good reference: a rule without one refuses the blueprint with `BLUEPRINT_NO_SOURCE`, naming the blueprint and the rule, when it is loaded or saved.
+
## Resume release notes
<!-- resume-release-notes:start -->
diff --git a/src/blueprints.js b/src/blueprints.js
index 98f80bff..8486eda5 100644
--- a/src/blueprints.js
+++ b/src/blueprints.js
@@ -10,18 +10,23 @@
* name "web-app" required, lowercase letters, digits and dashes
* title "Web app" required, one line; the section heading
* version 1 required, a positive integer, the blueprint's own version
- * kind "product" optional: product, infrastructure, practice or beyond-code
+ * kind "product" optional: product, architecture, practice or beyond-code;
+ * a file that says infrastructure (the old name) loads as architecture
* by "Pullboard" optional, who made it
* summary "..." optional, one line
* prefix "W" optional, the row id prefix it prefers; a free one is used if taken
* gate "npm test" optional, set in pullboard.json only when it has no gate
- * rules [{ key, text, why, tier?, gate? }] tier must|aim (must), gate (review)
+ * rules [{ key, text, why, tier?, gate?, source? }] tier must|aim (must), gate (review)
+ * source { name, id?, url? }: the reference the rule paraphrases, such as a standard
+ * and its numbered practice; the drafted row keeps it as | source: <name> <id> <url>
* questions [{ key, ask, choices, default }] default is one of choices
* items [{ key, title, cites?, after?, lane?, route?, criterion, brief?, check }]
*
* Every starter item carries a criterion and a check, or the blueprint is refused with
* BLUEPRINT_ITEM_UNCHECKED when it is read or saved: a starter that cannot be verified cannot be
- * accepted. An item's route is light, mid or strong (strong when left out), as pullboard add takes
+ * accepted. Every rule of an architecture blueprint names its source, or the blueprint is refused
+ * with BLUEPRINT_NO_SOURCE when it is read or saved: an architecture rule paraphrases a known-good
+ * reference, so the row it drafts must say which one. An item's route is light, mid or strong (strong when left out), as pullboard add takes
* it. Its brief, criterion and check pass through to add unchanged, so a light or mid item is filed when it
* carries what add requires for that route and refused with add's own refusal when it does not.
* A check is stored on the item and never run during add: no check baseline starts, so nothing a
@@ -40,7 +45,10 @@ import { insertSectionRows, nextRowId } from './spec.js';
export const BLUEPRINT_FORMAT = 1;
/** The kinds the gallery files blueprints under. */
-export const BLUEPRINT_KINDS = ['product', 'infrastructure', 'practice', 'beyond-code'];
+export const BLUEPRINT_KINDS = ['product', 'architecture', 'practice', 'beyond-code'];
+
+/** Old kind names a blueprint file may still carry, by the kind each loads as. */
+const LEGACY_KINDS = { infrastructure: 'architecture' };
const BUNDLED_DIR = fileURLToPath(new URL('./blueprints/', import.meta.url));
const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
@@ -99,7 +107,7 @@ export function readBlueprint(reference, cwd) {
* @property {string} [summary]
* @property {string} [prefix]
* @property {string} [gate]
- * @property {{ key: string, text: string, why: string, tier: string, gate: string }[]} rules
+ * @property {{ key: string, text: string, why: string, tier: string, gate: string, source?: { name: string, id?: string, url?: string } }[]} rules
* @property {{ key: string, ask: string, choices: string[], default: string }[]} questions
* @property {{ key: string, title: string, cites: string[], after: string[], lane?: string, route: string, criterion: string, brief: string, check: string }[]} items
*/
@@ -127,7 +135,8 @@ export function validateBlueprint(value, source = 'blueprint') {
if (typeof value.name !== 'string' || !NAME_RE.test(value.name)) fail('name', 'must be lowercase letters, digits and dashes, such as web-app');
line('title', value.title);
if (!Number.isInteger(value.version) || value.version < 1) fail('version', 'must be a positive integer');
- if (value.kind !== undefined && !BLUEPRINT_KINDS.includes(value.kind)) fail('kind', `must be one of ${BLUEPRINT_KINDS.join(', ')}`);
+ const kind = Object.hasOwn(LEGACY_KINDS, value.kind ?? '') ? LEGACY_KINDS[value.kind] : value.kind;
+ if (kind !== undefined && !BLUEPRINT_KINDS.includes(kind)) fail('kind', `must be one of ${BLUEPRINT_KINDS.join(', ')}`);
line('by', value.by, { required: false });
line('summary', value.summary, { required: false });
line('gate', value.gate, { required: false });
@@ -150,6 +159,16 @@ export function validateBlueprint(value, source = 'blueprint') {
line(`${at}.why`, rule.why);
if (rule.tier !== undefined && !['must', 'aim'].includes(rule.tier)) fail(`${at}.tier`, 'must be must or aim');
line(`${at}.gate`, rule.gate, { required: false });
+ if (rule.source !== undefined) {
+ const source = rule.source;
+ if (!source || typeof source !== 'object' || Array.isArray(source)) fail(`${at}.source`, 'must be an object: { name, id, url }');
+ else {
+ line(`${at}.source.name`, source.name);
+ line(`${at}.source.id`, source.id, { required: false });
+ line(`${at}.source.url`, source.url, { required: false });
+ if (typeof source.url === 'string' && !/^https?:\/\/\S+$/u.test(source.url)) fail(`${at}.source.url`, 'must be one http or https address without spaces');
+ }
+ }
});
questions.forEach((question, index) => {
const at = `questions[${index}]`;
@@ -189,15 +208,45 @@ export function validateBlueprint(value, source = 'blueprint') {
if (problems.length) {
throw new Refused('BAD_BLUEPRINT', `${source} is not a valid blueprint: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? `; and ${problems.length - 5} more` : ''}; fix the file and run pullboard blueprint add again`);
}
+ refuseUnsourcedRules(value.name, kind, rules);
refuseUncheckedItems(value.name, items);
return {
...value,
+ ...(kind === undefined ? {} : { kind }),
rules: rules.map((rule) => ({ ...rule, tier: rule.tier ?? 'must', gate: rule.gate ?? 'review' })),
questions,
items: items.map((item) => ({ ...item, cites: item.cites ?? [], after: item.after ?? [], route: item.route ?? 'strong', criterion: item.criterion ?? '', brief: item.brief ?? '' })),
};
}
+/**
+ * Refuse an architecture blueprint with a rule that names no source, naming the blueprint and the
+ * rule. An architecture rule paraphrases a known-good reference (a standard, a vendor's framework),
+ * so its drafted row must say which one; a rule with no reference has no place in one (#719).
+ *
+ * @param {string} name - The blueprint's name, already checked.
+ * @param {string | undefined} kind - The blueprint's kind, with old names already mapped.
+ * @param {{ key: string, text: string, source?: object }[]} rules
+ * @returns {void}
+ */
+function refuseUnsourcedRules(name, kind, rules) {
+ if (kind !== 'architecture') return;
+ const rule = rules.find((entry) => entry.source === undefined);
+ if (!rule) return;
+ throw new Refused('BLUEPRINT_NO_SOURCE', `architecture blueprint ${name} rule ${rule.key} (${JSON.stringify(rule.text)}) names no source; give every rule of an architecture blueprint the reference it paraphrases as source { name, id, url }, then run pullboard blueprint add again`);
+}
+
+/**
+ * Where a rule came from, as its drafted row's source field carries it: the name, then the id and
+ * the address when the rule gives them, one line.
+ *
+ * @param {{ name: string, id?: string, url?: string }} source
+ * @returns {string}
+ */
+export function sourceText(source) {
+ return [source.name, source.id, source.url].filter((part) => typeof part === 'string' && part.trim()).map((part) => part.trim()).join(' ');
+}
+
/**
* Refuse a blueprint whose starter item has no criterion or no check, naming the blueprint and the
* item. A starter without both cannot be built against a bar or verified, so it could never reach
@@ -364,7 +413,7 @@ export function landBlueprint(blueprint, answers) {
* @param {{ source: string, spec: any, doctrine: any, existingItems: { id: number, title: string, specIds: string[] }[], gate: string }} board
* source is SPEC.md's text and spec its parse; doctrine is loadDoctrine's result; existingItems
* are the items on the board; gate is pullboard.json's gate now.
- * @returns {{ marked: boolean, resumed: boolean, section: { prefix: string, name: string, isNew: boolean }, rows: { key: string, id: string, status: string, text: string, line: string }[], specRows: string, specAfter: string, ids: Record<string, string>, items: { key: string, title: string, specIds: string[], after: string[], lane?: string, route: string, criterion: string, brief: string }[], existing: Record<string, number>, gate: string | null }}
+ * @returns {{ marked: boolean, resumed: boolean, section: { prefix: string, name: string, isNew: boolean }, rows: { key: string, id: string, status: string, text: string, source?: string, line: string }[], specRows: string, specAfter: string, ids: Record<string, string>, items: { key: string, title: string, specIds: string[], after: string[], lane?: string, route: string, criterion: string, brief: string }[], existing: Record<string, number>, gate: string | null }}
* specRows is the text to write before the items (rows and the under-way marker), specAfter the
* text once they are all added (the finished marker); existing maps starter keys already on the
* board to their item ids.
@@ -405,7 +454,10 @@ export function planBlueprint(blueprint, { source, spec, doctrine, existingItems
const id = allocate();
const text = ruleText(rule);
ids[rule.key] = id;
- rows.push({ key: rule.key, id, status: 'draft', text, line: `- ${id} [draft, ${rule.tier}] ${text} | gate: ${rule.gate}` });
+ // The rule's source rides on its row as a field, so the text the person approves stays the rule.
+ const source = rule.source ? sourceText(rule.source) : '';
+ rows.push({ key: rule.key, id, status: 'draft', text, ...(source ? { source } : {}),
+ line: `- ${id} [draft, ${rule.tier}] ${text} | gate: ${rule.gate}${source ? ` | source: ${source}` : ''}` });
}
for (const question of blueprint.questions) {
const id = allocate();
diff --git a/src/blueprints/data-pipeline.json b/src/blueprints/data-pipeline.json
index a24835b0..26ecba25 100644
--- a/src/blueprints/data-pipeline.json
+++ b/src/blueprints/data-pipeline.json
@@ -3,13 +3,13 @@
"name": "data-pipeline",
"title": "Data pipeline",
"version": 1,
- "kind": "infrastructure",
+ "kind": "architecture",
"by": "Pullboard",
"summary": "Every table has an owner, a schema check and a freshness check.",
"prefix": "DP",
"rules": [
- { "key": "DP1", "text": "A schema change ships with its migration.", "why": "a schema that changes without its migration breaks every job that reads the old shape." },
- { "key": "DP2", "text": "A failed job names the rows and the reason.", "why": "a failure that names no rows means rerunning everything to find what broke." }
+ { "key": "DP1", "text": "A schema change ships with its migration.", "why": "a schema that changes without its migration breaks every job that reads the old shape.", "source": { "name": "Pullboard data pipeline blueprint", "id": "DP1", "url": "https://github.com/pullboard-dev/pullboard/blob/main/src/blueprints/data-pipeline.json" } },
+ { "key": "DP2", "text": "A failed job names the rows and the reason.", "why": "a failure that names no rows means rerunning everything to find what broke.", "source": { "name": "Pullboard data pipeline blueprint", "id": "DP2", "url": "https://github.com/pullboard-dev/pullboard/blob/main/src/blueprints/data-pipeline.json" } }
],
"questions": [
{ "key": "Q1", "ask": "The warehouse is", "choices": ["Snowflake", "BigQuery", "Postgres", "Something else"], "default": "Snowflake" },
diff --git a/src/blueprints/serverless.json b/src/blueprints/serverless.json
index ff454e7c..ac08afa3 100644
--- a/src/blueprints/serverless.json
+++ b/src/blueprints/serverless.json
@@ -3,13 +3,13 @@
"name": "serverless",
"title": "Serverless",
"version": 1,
- "kind": "infrastructure",
+ "kind": "architecture",
"by": "Pullboard",
"summary": "Pick your cloud once, and your agents never drift from it.",
"prefix": "SV",
"rules": [
- { "key": "SV1", "text": "Every function has an alarm before it ships.", "why": "a function that fails quietly is found by your users first." },
- { "key": "SV2", "text": "No function runs past its platform's time limit.", "why": "the platform stops a function at its limit, so longer work has to be split before it fails in production." }
+ { "key": "SV1", "text": "Every function has an alarm before it ships.", "why": "a function that fails quietly is found by your users first.", "source": { "name": "Pullboard serverless blueprint", "id": "SV1", "url": "https://github.com/pullboard-dev/pullboard/blob/main/src/blueprints/serverless.json" } },
+ { "key": "SV2", "text": "No function runs past its platform's time limit.", "why": "the platform stops a function at its limit, so longer work has to be split before it fails in production.", "source": { "name": "Pullboard serverless blueprint", "id": "SV2", "url": "https://github.com/pullboard-dev/pullboard/blob/main/src/blueprints/serverless.json" } }
],
"questions": [
{ "key": "Q1", "ask": "It runs on", "choices": ["AWS", "Google Cloud", "Azure", "Cloudflare"], "default": "AWS" },
diff --git a/src/cli.js b/src/cli.js
index ccf54309..c78ecaa5 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -2384,7 +2384,7 @@ export async function addBlueprintHere(io, reference, { report = true, blueprint
* @typedef {object} BlueprintAdded
* @property {{ name: string, title: string, version: number }} blueprint
* @property {string} section - The SPEC.md section heading the rows are in.
- * @property {{ key: string, id: string, status: string, text: string }[]} rows - New rows; each waits for the person.
+ * @property {{ key: string, id: string, status: string, text: string, source?: string }[]} rows - New rows; each waits for the person, with the source its rule names.
* @property {{ id: number, key: string, title: string, lane: string, askedLane?: string, specIds: string[], after: number[], check?: string }[]} items - New open items.
* @property {string | null} gate - The gate set in pullboard.json, or null when it was left alone.
* @property {boolean} marked - This blueprint version was already on the board, so nothing was added.
@@ -2465,7 +2465,7 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true } = {}) {
writeRowApply(ctx.info.root, { records: [], files: [{ file: ctx.config.spec, before: plan.specRows, after: plan.specAfter }], signoffs: { before: null, receipts: [] } });
}
if (plan.specAfter !== source && !files.some((file) => file.file === ctx.config.spec)) files.unshift({ file: ctx.config.spec });
- const rows = plan.rows.map(({ key, id, status, text }) => ({ key, id, status, text }));
+ const rows = plan.rows.map(({ key, id, status, text, source }) => ({ key, id, status, text, ...(source ? { source } : {}) }));
const summary = { blueprint: { name: blueprint.name, title: blueprint.title, version: blueprint.version },
section: plan.section.name, rows, items: added, gate: plan.gate, marked: plan.marked, proposedLanes: added.length ? proposedLanes : [],
// Item checks are stored and never run during add; the caller tells the reader so.
@@ -3534,9 +3534,9 @@ async function specCommand(io, { first, second, rest, values }) {
unnamed.forEach((problem) => messages.push(`${ctx.config.spec}: error: ${problem}`));
errors += unnamed.length;
if (values.json && !errors) {
- const rows = files.flatMap(([file, parsed]) => parsed.rows.map(({ id, status, tier, text, gate, serves, signers = [], section, line, origin, version, reason, file: source }) => (
+ const rows = files.flatMap(([file, parsed]) => parsed.rows.map(({ id, status, tier, text, gate, serves, signers = [], section, line, origin, version, reason, file: source, source: from }) => (
{ id, status, tier, text, gate, serves, signers, section, line, file: source ?? file,
- ...(origin ? { origin, version, reason } : {}) }
+ ...(from === undefined ? {} : { source: from }), ...(origin ? { origin, version, reason } : {}) }
)));
io.result({ rows });
} else messages.forEach((message) => io.say(message));
@@ -3584,6 +3584,7 @@ async function specCommand(io, { first, second, rest, values }) {
if (row.reason) io.say(`reason: ${row.reason}`);
if (row.gate) io.say(`gate: ${row.gate}`);
if (row.serves.length) io.say(`serves: ${row.serves.join(', ')}`);
+ if (row.source) io.say(`source: ${row.source}`);
io.say(`signed: ${standing.met.map((entry) => `${entry.by} ${entry.on}`).join(', ') || 'no'}${standing.stale.length ? `; stale: ${standing.stale.length}` : ''}`);
for (const entry of [...standing.met, ...standing.stale]) if (entry.note) io.say(`note (${entry.by}): ${entry.note}`);
return 0;
diff --git a/src/next-steps.js b/src/next-steps.js
index 83fd45c4..47fdae65 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -68,6 +68,7 @@ export const NEXT_STEPS = Object.freeze({
BLOCKED: 'take another item with pullboard next, or shout the lane it waits on: pullboard shout <lane> "<text>"',
BLUEPRINT_EXISTS: 'choose a file that does not exist: pullboard blueprint save <new-file>',
BLUEPRINT_ITEM_UNCHECKED: 'give the starter item named in the message a criterion and a check command, then run pullboard blueprint add <file> again',
+ BLUEPRINT_NO_SOURCE: 'give the rule named in the message the reference it paraphrases as source { name, id, url }, then run pullboard blueprint add <file> again',
BLUEPRINT_URL: 'download and read the blueprint yourself, then run pullboard blueprint add <local-file>',
BOARD_BUSY: 'wait for the other pullboard process to finish, then retry',
BOARD_NOT_WRITABLE: 'give the agent write access to the repo\'s .git/pullboard folder, or run the command outside the sandbox',
diff --git a/src/spec.js b/src/spec.js
index 03a2f2ea..8a4c91be 100644
--- a/src/spec.js
+++ b/src/spec.js
@@ -30,7 +30,7 @@ const SECTION_RE = /^##\s+(.+)$/;
const SIGNER_RE = /^(?!#)[^\s,]+$/u;
const LEGACY_SIGNER_RE = /^[A-Z][A-Za-z]{1,11}$/;
-const FIELD_NAMES = ['gate', 'serves', 'signers', 'count', 'runs', 'mode', 'files'];
+const FIELD_NAMES = ['gate', 'serves', 'signers', 'count', 'runs', 'mode', 'files', 'source'];
const CHECK_FIELDS = ['count', 'runs', 'mode', 'files'];
/**
@@ -38,10 +38,12 @@ const CHECK_FIELDS = ['count', 'runs', 'mode', 'files'];
* A doctrine rule may add `| count: N`, `| runs: nightly`, `| mode: watch` and `| files: <paths>`
* to a `gate: check`;
* those keys appear on the row only when written, so rows without them parse exactly as before.
+ * Any row may add `| source: <name> <id> <url>`, the reference a blueprint rule came from; it too
+ * appears only when written.
* A check command may itself contain ` | `: a part that names no known field continues it.
*
* @param {string} rest
- * @returns {{ text: string, gate: string, serves: string[], signers: string[], unknown: string[], count?: string, runs?: string, mode?: string, files?: string }}
+ * @returns {{ text: string, gate: string, serves: string[], signers: string[], unknown: string[], count?: string, runs?: string, mode?: string, files?: string, source?: string }}
*/
function splitFields(rest) {
const [text = '', ...parts] = rest.split(' | ');
@@ -58,7 +60,7 @@ function splitFields(rest) {
if (key.trim() === 'gate') {
fields.gate = joined;
inCheck = /^check(\s|$)/u.test(joined);
- } else if (CHECK_FIELDS.includes(key.trim())) fields[key.trim()] = joined;
+ } else if (CHECK_FIELDS.includes(key.trim()) || key.trim() === 'source') fields[key.trim()] = joined;
else if (key.trim() === 'serves') {
fields.serves = joined.split(',').map((id) => id.trim()).filter(Boolean);
} else if (key.trim() === 'signers') {
@@ -194,7 +196,8 @@ function rowFindings(row, maxWords) {
// are not counted: the limit keeps the requirement itself short (blueprint rows carry both).
const words = row.text.split(/ (?:Why|Choices): /u)[0].split(/\s+/).filter(Boolean).length;
if (words > maxWords) add('warning', `${words} words; rows stay under ${maxWords}, the why goes elsewhere`);
- for (const part of row.unknown) add('error', `unknown field "${part}"; fields are gate, serves, signers, count, runs, mode and files`);
+ for (const part of row.unknown) add('error', `unknown field "${part}"; fields are gate, serves, signers, count, runs, mode, files and source`);
+ if (row.source !== undefined && !row.source.trim()) add('error', 'source names where the row came from; leave it out when the row has none');
findings.push(...checkFieldFindings(row).map((message) => ({ level: 'error', line: row.line, id: row.id, message })));
return findings;
}
diff --git a/test/blueprint.test.js b/test/blueprint.test.js
index d8a50622..7120a506 100644
--- a/test/blueprint.test.js
+++ b/test/blueprint.test.js
@@ -314,6 +314,149 @@ test('a starter item without a check is refused [S1,I1]', () => {
assert.deepEqual(readdirSync(empty.repo).filter((entry) => entry !== '.git'), [], 'init writes nothing');
});
+/** An architecture blueprint whose rules name the reference each paraphrases; a fixture, never fetched. */
+const SOURCED = {
+ blueprint: 1, name: 'edge-api', title: 'Edge API', version: 1, kind: 'architecture', by: 'Fixture', prefix: 'EA',
+ rules: [
+ { key: 'EA1', text: 'Every function has an error alarm.', why: 'a quiet failure is found by users first.',
+ source: { name: 'Example Framework', id: 'OPS 8', url: 'https://example.com/framework/ops-8' } },
+ { key: 'EA2', text: 'No function runs past its time limit.', why: 'the platform stops it there.', source: { name: 'Example Lens' } },
+ ],
+ questions: [{ key: 'Q1', ask: 'It runs on', choices: ['AWS', 'Cloudflare'], default: 'AWS' }],
+ items: [{ key: '1', title: 'Every function has an alarm', cites: ['EA1'], criterion: 'A test fails on a function without an alarm.', check: 'true' }],
+};
+
+test('a drafted row records its rule source [S1,I1]', () => {
+ // blueprint add copies each rule's source onto its drafted row as a source field; the row's text
+ // stays the rule and its reason, so the person approves the rule and reads where it came from.
+ const box = freshBoard({ gate: 'true' });
+ writeFileSync(join(box.repo, 'edge-api.json'), `${JSON.stringify(SOURCED)}\n`);
+ const added = json(box, 'blueprint', 'add', 'edge-api.json');
+ const drafted = added.rows.filter((row) => row.status === 'draft');
+ assert.deepEqual(drafted.map((row) => [row.key, row.source]), [['EA1', 'Example Framework OPS 8 https://example.com/framework/ops-8'], ['EA2', 'Example Lens']]);
+ assert.equal(added.rows.find((row) => row.key === 'Q1').source, undefined, 'a question names no source');
+ const source = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');
+ const ea1 = drafted[0].id;
+ assert.ok(source.split('\n').includes(`- ${ea1} [draft, must] Every function has an error alarm. Why: a quiet failure is found by users first. | gate: review | source: Example Framework OPS 8 https://example.com/framework/ops-8`), source);
+ const spec = parseSpec(source);
+ assert.deepEqual(spec.problems, []);
+ const row = spec.rows.find((entry) => entry.id === ea1);
+ assert.equal(row.text, 'Every function has an error alarm. Why: a quiet failure is found by users first.', 'the source is a field, not part of the text');
+ assert.equal(row.source, 'Example Framework OPS 8 https://example.com/framework/ops-8');
+
+ // pullboard spec shows where the row came from: spec check passes, its JSON rows carry the
+ // source, and spec show prints it.
+ const check = box.run('spec', 'check');
+ assert.equal(check.status, 0, check.stdout + check.stderr);
+ const rows = json(box, 'spec', '--json').rows;
+ assert.equal(rows.find((entry) => entry.id === ea1).source, 'Example Framework OPS 8 https://example.com/framework/ops-8');
+ const shown = box.run('spec', 'show', ea1);
+ assert.equal(shown.status, 0, shown.stdout + shown.stderr);
+ assert.match(shown.stdout, /^source: Example Framework OPS 8 https:\/\/example\.com\/framework\/ops-8$/mu);
+ assert.equal(json(box, 'spec', 'show', ea1).row.source, 'Example Framework OPS 8 https://example.com/framework/ops-8');
+
+ // A row with no source parses exactly as before: no source key, and spec show prints none. An
+ // empty source field is an error spec check names.
+ const plain = rows.find((entry) => entry.status === 'pending');
+ assert.equal(Object.hasOwn(plain, 'source'), false, 'a row without a source carries no source key');
+ assert.deepEqual(Object.keys(parseSpec('# S\n\n## G · Goals\n\n- G1 [draft, must] A row. | gate: review\n').rows[0]),
+ ['id', 'status', 'tier', 'text', 'gate', 'serves', 'signers', 'unknown', 'section', 'line'], 'an older row parses unchanged');
+ assert.doesNotMatch(box.run('spec', 'show', plain.id).stdout, /^source:/mu);
+ writeFileSync(join(box.repo, 'SPEC.md'), source.replace(' | source: Example Lens', ' | source: '));
+ const empty = box.run('spec', 'check');
+ assert.equal(empty.status, 1, empty.stdout + empty.stderr);
+ assert.match(empty.stdout, /source names where the row came from/u);
+ writeFileSync(join(box.repo, 'SPEC.md'), source);
+
+ // A bundled architecture blueprint drafts its rows with the source it names.
+ const serverless = json(box, 'blueprint', 'add', 'serverless');
+ for (const rule of readBlueprint('serverless', process.cwd()).rules) {
+ const drafted = serverless.rows.find((entry) => entry.key === rule.key);
+ assert.equal(drafted.source, `${rule.source.name} ${rule.source.id} ${rule.source.url}`, `serverless ${rule.key} keeps its source`);
+ }
+
+ // init --blueprint drafts the same rows with the same sources.
+ const fresh = emptyRepo();
+ writeFileSync(join(box.dir, 'edge-api.json'), `${JSON.stringify(SOURCED)}\n`);
+ const started = fresh.run('init', '--blueprint', join(box.dir, 'edge-api.json'));
+ assert.equal(started.status, 0, started.stdout + started.stderr);
+ const initRows = parseSpec(readFileSync(join(fresh.repo, 'SPEC.md'), 'utf8')).rows.filter((entry) => entry.status === 'draft');
+ assert.deepEqual(initRows.map((entry) => entry.source), ['Example Framework OPS 8 https://example.com/framework/ops-8', 'Example Lens']);
+});
+
+test('an architecture rule without a source is refused [S1,I1]', () => {
+ // Loaded from a file or checked before a save writes one: an architecture blueprint with a rule
+ // that names no source is refused by name, the blueprint's and the rule's.
+ const unsourced = { ...SOURCED, rules: [SOURCED.rules[0], { key: 'EA2', text: 'No function runs past its time limit.', why: 'the platform stops it there.' }] };
+ for (const kind of ['architecture', 'infrastructure']) {
+ assert.throws(() => validateBlueprint({ ...unsourced, kind }, 'edge-api.json'), (error) => {
+ assert.equal(error.code, 'BLUEPRINT_NO_SOURCE');
+ assert.match(error.message, /architecture blueprint edge-api rule EA2 \("No function runs past its time limit\."\) names no source/u);
+ return true;
+ }, `a ${kind} rule without a source is refused`);
+ }
+ // A product, practice or beyond-code rule may still leave its source out.
+ for (const kind of ['product', 'practice', 'beyond-code', undefined]) {
+ assert.equal(validateBlueprint({ ...unsourced, kind }, 'edge-api.json').rules.length, 2, `a ${kind} blueprint needs no source`);
+ }
+ // A source that is not { name, id?, url? } with a web address is refused as a bad blueprint.
+ for (const source of ['Example Framework', { id: 'OPS 8' }, { name: 'Example', url: 'ftp://example.com/x' }, { name: 'Example | Lens' }]) {
+ const value = { ...SOURCED, rules: [{ ...SOURCED.rules[0], source }] };
+ assert.throws(() => validateBlueprint(value, 'edge-api.json'), (error) => error.code === 'BAD_BLUEPRINT' && /rules\[0\]\.source/u.test(error.message), JSON.stringify(source));
+ }
+
+ // blueprint add refuses it with its next step and writes nothing.
+ const box = freshBoard({ gate: 'true' });
+ const spec = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');
+ writeFileSync(join(box.repo, 'unsourced.json'), `${JSON.stringify(unsourced)}\n`);
+ const refused = box.run('blueprint', 'add', 'unsourced.json', '--json');
+ assert.equal(refused.status, 1, refused.stdout + refused.stderr);
+ const error = JSON.parse(refused.stdout).error;
+ assert.equal(error.code, 'BLUEPRINT_NO_SOURCE');
+ assert.match(error.message, /architecture blueprint edge-api rule EA2/u);
+ assert.match(error.next, /source \{ name, id, url \}/u);
+ assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), spec, 'a refused blueprint writes nothing');
+ assert.equal(json(box, 'list', '--all').items.length, 0, 'and files no item');
+
+ // init --blueprint refuses it before writing anything.
+ const empty = emptyRepo();
+ writeFileSync(join(box.dir, 'unsourced.json'), `${JSON.stringify(unsourced)}\n`);
+ const init = empty.run('init', '--blueprint', join(box.dir, 'unsourced.json'), '--json');
+ assert.notEqual(init.status, 0);
+ assert.equal(JSON.parse(init.stdout).error.code, 'BLUEPRINT_NO_SOURCE');
+ assert.deepEqual(readdirSync(empty.repo).filter((entry) => entry !== '.git'), [], 'init writes nothing');
+
+ // Every bundled architecture blueprint names a source for every rule.
+ for (const name of bundledBlueprints()) {
+ const blueprint = readBlueprint(name, process.cwd());
+ if (blueprint.kind !== 'architecture') continue;
+ for (const rule of blueprint.rules) assert.ok(rule.source?.name && rule.source.url, `${name} ${rule.key} names its source`);
+ }
+});
+
+test('infrastructure loads as architecture [S1]', async () => {
+ const { BLUEPRINT_KINDS } = await import('../src/blueprints.js');
+ // The kind is architecture now; the old name is no kind a blueprint is filed under.
+ assert.ok(BLUEPRINT_KINDS.includes('architecture'));
+ assert.equal(BLUEPRINT_KINDS.includes('infrastructure'), false);
+ assert.equal(validateBlueprint({ ...SOURCED, kind: 'infrastructure' }, 'edge-api.json').kind, 'architecture');
+ assert.equal(validateBlueprint({ ...SOURCED, kind: 'architecture' }, 'edge-api.json').kind, 'architecture');
+ assert.throws(() => validateBlueprint({ ...SOURCED, kind: 'cloud' }, 'edge-api.json'), (error) => error.code === 'BAD_BLUEPRINT' && /kind must be one of product, architecture, practice, beyond-code/u.test(error.message));
+
+ // A file that says infrastructure reads, and adds, as architecture.
+ const box = freshBoard({ gate: 'true' });
+ writeFileSync(join(box.repo, 'old.json'), `${JSON.stringify({ ...SOURCED, name: 'old-edge', kind: 'infrastructure' })}\n`);
+ assert.equal(readBlueprint('old.json', box.repo).kind, 'architecture');
+ assert.equal(json(box, 'blueprint', 'add', 'old.json').rows.length, 3);
+
+ // The bundled files that said infrastructure now say architecture, and none says the old name.
+ for (const name of bundledBlueprints()) {
+ const raw = JSON.parse(readFileSync(resolve(import.meta.dirname, `../src/blueprints/${name}.json`), 'utf8'));
+ assert.notEqual(raw.kind, 'infrastructure', `${name} uses the new name`);
+ }
+ assert.deepEqual(['serverless', 'data-pipeline'].map((name) => readBlueprint(name, process.cwd()).kind), ['architecture', 'architecture']);
+});
+
test('blueprint add files a blueprint as drafts with light and mid starters add accepts [S1,I1]', () => {
// A light or mid starter carrying its brief, criterion and check is filed on that route, with
// all three passed to the item unchanged; a strong starter needs no brief.