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.

fix(spec): handle versioned grammar refusals [A5,M1]

Corey Olson3fa1b1515f08
diff --git a/src/board.js b/src/board.js
index a5eb56f8..b973cc16 100644
--- a/src/board.js
+++ b/src/board.js
@@ -553,15 +553,17 @@ export function editItem(board, id, { agentId, brief, route, criterion, check })
}
/**
- * The refusal code src/machine.js declares for a guard of a move: the guard's own, or for the
- * state check, the move's.
+ * The refusal codes src/machine.js declares for a guard of a move: the guard's own and any
+ * additional typed refusals, or for the state check, the move's.
*
* @param {any} move
* @param {string} id
- * @returns {string}
+ * @returns {string[]}
*/
-function declaredCode(move, id) {
- return id === IN_STATE ? move.refuse : GUARDS.find((guard) => guard.id === id).refuse;
+function declaredCodes(move, id) {
+ if (id === IN_STATE) return [move.refuse];
+ const guard = GUARDS.find((entry) => entry.id === id);
+ return [guard.refuse, ...(guard.alsoRefuses ?? []).map((entry) => entry.code)];
}
/**
@@ -598,8 +600,9 @@ function moveItem(board, id, verb, { checks, set = () => ({}), before = () => {}
if (guard === IN_STATE && move.from.includes(item.item_status)) continue;
const refusal = check(item);
if (refusal === null) continue;
- if (refusal.code !== declaredCode(move, guard)) {
- throw new Error(`move ${verb}: guard ${guard} refused with ${refusal.code}; the declaration says ${declaredCode(move, guard)}`);
+ const codes = declaredCodes(move, guard);
+ if (!codes.includes(refusal.code)) {
+ throw new Error(`move ${verb}: guard ${guard} refused with ${refusal.code}; the declaration says ${codes.join(' or ')}`);
}
throw refusal;
}
diff --git a/src/cli.js b/src/cli.js
index 1b7fc430..17f25394 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1019,7 +1019,7 @@ function submitHere(ctx, id) {
try {
digest = freezer(ctx)(item).digest;
} catch (error) {
- if (!(error instanceof Refused)) throw error;
+ if (!(error instanceof Refused) || error.code === 'A5_GRAMMAR_VERSION') throw error;
unusable = error.message.replace(/^\[\w+\] /, '').split(';')[0];
}
if (digest !== item.item_frozen_digest) {
@@ -1086,7 +1086,7 @@ function verifyHere(ctx, id, { second, values }) {
try {
digest = freezer(ctx)(item).digest;
} catch (error) {
- if (!(error instanceof Refused)) throw error;
+ if (!(error instanceof Refused) || error.code === 'A5_GRAMMAR_VERSION') throw error;
}
return store.verify(board, id, {
agentId: me.id,
diff --git a/src/history.js b/src/history.js
index 408023b1..72e0762b 100644
--- a/src/history.js
+++ b/src/history.js
@@ -58,7 +58,7 @@ export function committedIds(root, path, revs = ['HEAD']) {
const versions = fileVersions(root, path, revs);
const ids = new Map();
for (const { commit, text } of versions) {
- for (const row of parseSpec(text).rows) ids.set(row.id, commit);
+ for (const row of parseSpec(text, { strictGrammarVersion: false }).rows) ids.set(row.id, commit);
}
return { ids, since: versions.at(-1)?.commit ?? null };
}
diff --git a/src/json.js b/src/json.js
index 64c295b6..06a7785c 100644
--- a/src/json.js
+++ b/src/json.js
@@ -69,7 +69,7 @@ export const JSON_SHAPES = {
/** Extract a concrete repair from existing refusals, retaining their original guidance. */
function nextStep(message) {
- const match = /(?:; |\. |: )((?:run|install|fix|restore|commit|check out|set|give|use|ask your coordinator|answer from the main checkout|the coordinator|to keep looking|never work around)\b[\s\S]*)/i.exec(message);
+ const match = /(?:; |\. |: )((?:run|install|upgrade|fix|restore|commit|check out|set|give|use|ask your coordinator|answer from the main checkout|the coordinator|to keep looking|never work around)\b[\s\S]*)/i.exec(message);
return match?.[1] ?? 'Run pullboard help, correct the reported problem, and retry the command.';
}
@@ -94,8 +94,8 @@ export function commandOutput(argv, streams) {
let document;
if (refusal || (code && result === undefined)) {
const text = refusal?.message ?? [...diagnostics, ...messages].join('\n');
- const match = /\[([A-Z_]+)\]\s*([\s\S]*)/.exec(text);
- const message = refusal ? text.replace(/^\[[A-Z_]+\] /, '') : match?.[2] ?? text;
+ const match = /\[([A-Z][A-Z0-9_]*)\]\s*([\s\S]*)/.exec(text);
+ const message = refusal ? text.replace(/^\[[A-Z][A-Z0-9_]*\] /, '') : match?.[2] ?? text;
document = { version: JSON_SHAPES.version, error: { code: refusal?.code ?? match?.[1] ?? (code === 2 ? 'USAGE' : 'COMMAND_FAILED'), message, next: nextStep(message) } };
} else if (result !== undefined) {
document = { version: JSON_SHAPES.version, ...result };
diff --git a/src/machine.js b/src/machine.js
index 85d0116d..364ad863 100644
--- a/src/machine.js
+++ b/src/machine.js
@@ -15,6 +15,7 @@
* @typedef {object} Guard
* @property {string} id - How moves name it.
* @property {string} refuse - The refusal code it raises when it does not hold.
+ * @property {{ code: string, next: string }[]} [alsoRefuses] - Additional typed refusals and their repair steps.
* @property {string} rule - What must hold, in words.
* @property {string} next - The step that gets past it.
* @property {'board' | 'cli'} source - Where its fact comes from: the board file, or the CLI's look at git and the worktree.
@@ -104,7 +105,7 @@ export const GUARDS = [
{ id: 'notHeldByAnother', refuse: 'HELD', rule: 'no other agent holds it under a live lease', next: 'pullboard next', source: 'board' },
{ id: 'laneOpen', refuse: 'LANE_HELD', rule: 'nobody holds its lane', next: 'pullboard next --wait 9 (minutes)', source: 'board', when: 'unless the caller is renewing its own live claim' },
{ id: 'oneLiveClaim', refuse: 'ONE_CLAIM', rule: 'the caller holds no other live top-level claim, reworks of its own rejected items aside', next: 'submit or release the other item first; child items are free', source: 'board' },
- { id: 'rowsInForce', refuse: 'UNKNOWN_SPEC', rule: 'every row the item cites exists and is in force', next: 'fix the spec, or the coordinator withdraws the item', source: 'board', when: 'only where the criterion freezes: claiming an item with no frozen criterion, and refreeze' },
+ { id: 'rowsInForce', refuse: 'UNKNOWN_SPEC', alsoRefuses: [{ code: 'A5_GRAMMAR_VERSION', next: 'upgrade Pullboard or use a file written for grammar 1' }], rule: 'every row the item cites exists and is in force', next: 'fix the spec, or the coordinator withdraws the item', source: 'board', when: 'only where the criterion freezes: claiming an item with no frozen criterion, and refreeze' },
{ id: 'criterionUnchanged', refuse: 'CRITERIA_CHANGED', rule: 'the criterion and the rows it cites read as they did at claim', next: 'the coordinator runs pullboard refreeze <id>', source: 'cli' },
{ id: 'treeClean', refuse: 'DIRTY', rule: 'the worktree has no uncommitted changes', next: 'commit your changes, then submit', source: 'cli' },
{ id: 'nothingUntracked', refuse: 'UNTRACKED', rule: 'the worktree has no untracked files', next: 'commit or ignore them, then submit', source: 'cli' },
@@ -304,9 +305,13 @@ function unnamedRefusals(machine) {
const used = new Set([...machine.moves.flatMap((move) => move.guards), ...Object.values(machine.exitGuards).flat()]);
const problems = [];
for (const guard of machine.guards) {
- if (guard.id !== IN_STATE && !/^[A-Z][A-Z_]*$/.test(guard.refuse)) problems.push(`guard ${guard.id} names no refusal code`);
+ const codes = [guard.refuse, ...(guard.alsoRefuses ?? []).map((entry) => entry.code)];
+ if (guard.id !== IN_STATE && codes.some((code) => !/^[A-Z][A-Z0-9_]*$/.test(code))) problems.push(`guard ${guard.id} names no refusal code`);
if (!guard.rule.trim()) problems.push(`guard ${guard.id} states no rule`);
if (!guard.next.trim()) problems.push(`guard ${guard.id} refuses without a next step`);
+ for (const refusal of guard.alsoRefuses ?? []) {
+ if (!refusal.next?.trim()) problems.push(`guard ${guard.id} refusal ${refusal.code} has no next step`);
+ }
if (!used.has(guard.id)) problems.push(`guard ${guard.id} is declared but no move uses it`);
}
for (const move of machine.moves.filter((entry) => !entry.by.includes('clock'))) {
@@ -456,8 +461,10 @@ export function storeTriggers(machine = MACHINE) {
* @returns {string}
*/
function guardLabel(machine, move, id) {
- const code = id === IN_STATE ? move.refuse : machine.guards.find((guard) => guard.id === id)?.refuse;
- return code ? `${id} (${code})` : id;
+ const guard = machine.guards.find((entry) => entry.id === id);
+ const codes = id === IN_STATE ? [move.refuse] : [guard?.refuse, ...(guard?.alsoRefuses ?? []).map((entry) => entry.code)];
+ const declared = codes.filter(Boolean).join(' or ');
+ return declared ? `${id} (${declared})` : id;
}
/**
@@ -479,7 +486,10 @@ export function lifecycleMarkdown(machine = MACHINE) {
return `| ${move.verb} | ${move.from.join(', ')} | ${move.to} | ${cell(who)} | ${cell(guards)} |`;
});
const wrongState = machine.moves.filter((move) => move.refuse).map((move) => `| ${move.refuse} | ${move.verb}: the item is in ${move.from.join(', ')} | pullboard show <id> |`);
- const refusals = machine.guards.filter((guard) => guard.id !== IN_STATE).map((guard) => `| ${guard.refuse} | ${cell(guard.when ? `${guard.rule}, ${guard.when}` : guard.rule)} | ${cell(guard.next)} |`);
+ const refusals = machine.guards.filter((guard) => guard.id !== IN_STATE).flatMap((guard) => [
+ { code: guard.refuse, next: guard.next },
+ ...(guard.alsoRefuses ?? []),
+ ].map(({ code, next }) => `| ${code} | ${cell(guard.when ? `${guard.rule}, ${guard.when}` : guard.rule)} | ${cell(next)} |`));
const unknown = `| ${machine.unknownMove.refuse} | ${cell(machine.unknownMove.rule)} | ${cell(machine.unknownMove.next)} |`;
return [
'# The item lifecycle',
diff --git a/src/spec.js b/src/spec.js
index 9bbca550..3c788aa9 100644
--- a/src/spec.js
+++ b/src/spec.js
@@ -15,6 +15,8 @@ import { Refused } from './refused.js';
export const STATUSES = ['approved', 'draft', 'pending', 'fact', 'wont', 'retired'];
export const TIERS = ['must', 'aim'];
export const SIGNOFFS_FILE = '.pullboard/signoffs.jsonl';
+/** Shared SPEC.md/PRACTICE.md row grammar; bump for incompatible persisted format changes. */
+export const SPEC_GRAMMAR_VERSION = 1;
const ID = '[A-Za-z]+\\d+(?:\\.\\d+)*';
export const ID_RE = new RegExp(`^${ID}$`);
@@ -48,16 +50,30 @@ function splitFields(rest) {
* parse are kept as problems, never dropped silently.
*
* @param {string} source
- * @returns {{ title: string, intro: string[], sections: any[], rows: any[], problems: any[] }}
+ * @param {{ strictGrammarVersion?: boolean }} [options] - Historical text is parsed for ids without enforcing its marker.
+ * @returns {{ grammarVersion: number, title: string, intro: string[], sections: any[], rows: any[], problems: any[] }}
*/
-export function parseSpec(source) {
- const spec = { title: '', intro: [], sections: [], rows: [], problems: [] };
+export function parseSpec(source, { strictGrammarVersion = true } = {}) {
+ const spec = { grammarVersion: SPEC_GRAMMAR_VERSION, title: '', intro: [], sections: [], rows: [], problems: [] };
let section = null;
let isFenced = false;
source.split(/\r?\n/).forEach((line, index) => {
const lineNo = index + 1;
if (line.startsWith('```')) isFenced = !isFenced;
if (isFenced || line.startsWith('```')) return;
+ const grammar = /^\uFEFF?\s*<!--\s*pullboard-grammar(?:\s+(.*?))?\s*-->\s*$/.exec(line);
+ if (grammar) {
+ const declared = grammar[1]?.trim() ?? '';
+ const valid = /^\d+$/u.test(declared);
+ if (strictGrammarVersion && (!valid || BigInt(declared) !== BigInt(SPEC_GRAMMAR_VERSION))) {
+ const found = valid ? declared : 'invalid';
+ throw new Refused(
+ 'A5_GRAMMAR_VERSION',
+ `grammar ${found} is not supported; this Pullboard reads grammar ${SPEC_GRAMMAR_VERSION}; upgrade Pullboard or use a file written for grammar ${SPEC_GRAMMAR_VERSION}`,
+ );
+ }
+ return;
+ }
if (line.startsWith('# ') && !spec.title) {
spec.title = line.slice(2).trim();
return;
@@ -354,6 +370,6 @@ export function permanenceProblems(spec, { committed, cited }) {
* @returns {string[]} The deleted ids.
*/
export function deletedIds(before, after) {
- const kept = new Set(parseSpec(after).rows.map((row) => row.id));
- return parseSpec(before).rows.map((row) => row.id).filter((id) => !kept.has(id));
+ const kept = new Set(parseSpec(after, { strictGrammarVersion: false }).rows.map((row) => row.id));
+ return parseSpec(before, { strictGrammarVersion: false }).rows.map((row) => row.id).filter((id) => !kept.has(id));
}
diff --git a/test/e2e.test.js b/test/e2e.test.js
index f38b3ce4..9bb54651 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -544,6 +544,56 @@ test('verify runs at the submitted commit, against the criterion frozen at claim
assert.match(ledger, /\| 1 \| web \| Page \| G1 \| web-1 \| coordinator \|/);
});
+test('unsupported spec grammar keeps claim, refreeze, submit and verify refusals typed [A5,A1,M1]', () => {
+ const marker = '<!-- pullboard-grammar 2 -->\n';
+ const setup = () => {
+ const box = project();
+ assert.equal(box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1', '--criterion', 'renders').code, 0);
+ return box;
+ };
+ const claimBox = setup();
+ writeFileSync(join(claimBox.web, 'SPEC.md'), marker + SPEC);
+ for (const args of [['claim', '1'], ['next']]) {
+ const refused = claimBox.run(claimBox.web, ...args);
+ assert.equal(refused.code, 1);
+ assert.match(refused.err, /A5_GRAMMAR_VERSION.*grammar 2.*grammar 1/);
+ }
+ const claimJson = claimBox.run(claimBox.web, 'claim', '1', '--json');
+ assert.equal(claimJson.code, 1);
+ assert.equal(JSON.parse(claimJson.out).error.code, 'A5_GRAMMAR_VERSION');
+ writeFileSync(join(claimBox.repo, 'SPEC.md'), marker + SPEC);
+ const refreeze = claimBox.run(claimBox.repo, 'refreeze', '1');
+ assert.equal(refreeze.code, 1);
+ assert.match(refreeze.err, /A5_GRAMMAR_VERSION/);
+ const refreezeJson = claimBox.run(claimBox.repo, 'refreeze', '1', '--json');
+ assert.equal(refreezeJson.code, 1);
+ assert.equal(JSON.parse(refreezeJson.out).error.code, 'A5_GRAMMAR_VERSION');
+
+ const submitBox = setup();
+ assert.equal(submitBox.run(submitBox.web, 'claim', '1').code, 0);
+ commitFile(submitBox, submitBox.web, 'web/page.html', '<h1>Page</h1>', 'feat(web): add page [G1]');
+ writeFileSync(join(submitBox.web, 'SPEC.md'), marker + SPEC);
+ const submit = submitBox.run(submitBox.web, 'submit', '1');
+ assert.equal(submit.code, 1);
+ assert.match(submit.err, /A5_GRAMMAR_VERSION/);
+ const submitJson = submitBox.run(submitBox.web, 'submit', '1', '--json');
+ assert.equal(submitJson.code, 1);
+ assert.equal(JSON.parse(submitJson.out).error.code, 'A5_GRAMMAR_VERSION');
+
+ const verifyBox = setup();
+ assert.equal(verifyBox.run(verifyBox.web, 'claim', '1').code, 0);
+ commitFile(verifyBox, verifyBox.web, 'web/page.html', '<h1>Page</h1>', 'feat(web): add page [G1]');
+ assert.equal(verifyBox.run(verifyBox.web, 'submit', '1').code, 0);
+ verifyBox.git(verifyBox.repo, 'switch', '--detach', 'web/one');
+ writeFileSync(join(verifyBox.repo, 'SPEC.md'), marker + SPEC);
+ const verify = verifyBox.run(verifyBox.repo, 'verify', '1', 'accept', '--as', 'coordinator', '--note', 'checked');
+ assert.equal(verify.code, 1);
+ assert.match(verify.err, /A5_GRAMMAR_VERSION/);
+ const verifyJson = verifyBox.run(verifyBox.repo, 'verify', '1', 'accept', '--as', 'coordinator', '--note', 'checked', '--json');
+ assert.equal(verifyJson.code, 1);
+ assert.equal(JSON.parse(verifyJson.out).error.code, 'A5_GRAMMAR_VERSION');
+});
+
test('pre-push runs the gate once per tree and pushes only the checked-out commit [C3]', () => {
const box = project();
const remote = join(box.dir, 'remote.git');
diff --git a/test/machine.test.js b/test/machine.test.js
index 00429a82..4a7ca04e 100644
--- a/test/machine.test.js
+++ b/test/machine.test.js
@@ -1,6 +1,6 @@
/**
* The item lifecycle's declaration (M1, M2, M4): sound on its own terms, each property shown
- * failing on a broken copy, and in step with the refusals board.js and cli.js raise today.
+ * failing on a broken copy, and in step with the refusals the board, CLI and spec parser raise today.
*/
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
@@ -115,7 +115,7 @@ function codeWalk(read) {
const [file, name] = key.split('#');
const { bodies, named, spaces } = load(file);
const body = bodies.get(name) ?? '';
- const codes = new Set([...body.matchAll(/new Refused\(\s*(['"])([A-Z_]+)\1/g)].map((match) => match[2]));
+ const codes = new Set([...body.matchAll(/new Refused\(\s*(['"])([A-Z][A-Z0-9_]*)\1/g)].map((match) => match[2]));
const callees = [
...[...body.matchAll(/(?<!\w)(?<!(?<!\.\.)\.)(\w+)\(/g)].map(([, callee]) => (bodies.has(callee) ? `${file}#${callee}` : named.get(callee) ?? CALLBACKS[file]?.[callee])),
...[...body.matchAll(/\b(\w+)\.(\w+)\(/g)].map(([, space, callee]) => (spaces.has(space) ? `${spaces.get(space)}#${callee}` : undefined)),
@@ -146,7 +146,7 @@ function declaredCodes(machine, verbs) {
const moves = verbs ? machine.moves.filter((move) => verbs.includes(move.verb)) : machine.moves;
const used = new Set(moves.flatMap((move) => effectiveGuards(move, machine)));
return new Set([
- ...machine.guards.filter((guard) => !verbs || used.has(guard.id)).map((guard) => guard.refuse),
+ ...machine.guards.filter((guard) => !verbs || used.has(guard.id)).flatMap((guard) => [guard.refuse, ...(guard.alsoRefuses ?? []).map((entry) => entry.code)]),
...moves.map((move) => move.refuse),
machine.unknownMove.refuse,
].filter(Boolean));
@@ -154,7 +154,7 @@ function declaredCodes(machine, verbs) {
/**
* Where a declaration and the code disagree: a refusal a move raises today that the move does not
- * declare, or a code the declaration names that board.js and cli.js never raise.
+ * declare, or a code the declaration names that the board, CLI and spec parser never raise.
*
* @param {any} machine
* @param {(file: string) => string} [read]
@@ -171,8 +171,8 @@ function codeProblems(machine, read = fromDisk) {
}
}
}
- const raised = new Set(['board.js', 'cli.js'].flatMap((file) => walk.functions(file).flatMap((name) => [...walk.refusalsOf(`${file}#${name}`)])));
- for (const code of declaredCodes(machine)) if (!raised.has(code)) problems.add(`${code} is declared but board.js and cli.js never raise it`);
+ const raised = new Set(['board.js', 'cli.js', 'spec.js'].flatMap((file) => walk.functions(file).flatMap((name) => [...walk.refusalsOf(`${file}#${name}`)])));
+ for (const code of declaredCodes(machine)) if (!raised.has(code)) problems.add(`${code} is declared but the board, CLI and spec parser never raise it`);
return [...problems];
}
@@ -304,6 +304,13 @@ const BROKEN = [
},
says: /guard laneOpen refuses without a next step/,
},
+ {
+ property: 'every additional refusal says its next step',
+ breaks: (machine) => {
+ machine.guards.find((guard) => guard.id === 'rowsInForce').alsoRefuses[0].next = '';
+ },
+ says: /guard rowsInForce refusal A5_GRAMMAR_VERSION has no next step/,
+ },
{
property: 'every guard is used by some move',
breaks: (machine) => machine.guards.push({ id: 'unused', refuse: 'UNUSED', rule: 'nothing', next: 'nothing', source: 'board' }),
@@ -387,8 +394,11 @@ test('every refusal a move raises today is declared on that move, and every decl
const walk = codeWalk(fromDisk);
assert.ok(walk.refusalsOf('board.js#claim').has('UNKNOWN_SPEC'), 'the walk follows claim into the freezer the CLI hands it');
assert.ok(walk.refusalsOf('board.js#refreeze').has('UNKNOWN_SPEC'), 'and refreeze too');
+ assert.ok(walk.refusalsOf('board.js#claim').has('A5_GRAMMAR_VERSION'), 'grammar declarations can stop a claim with their own code');
+ assert.ok(walk.refusalsOf('board.js#refreeze').has('A5_GRAMMAR_VERSION'), 'and stop a refreeze too');
assert.ok(walk.refusalsOf('cli.js#submitHere').has('UNKNOWN_SPEC'), 'submit calls the freezer too');
assert.ok(!walk.refusalsOf('cli.js#submitHere', new Set(CAUGHT['cli.js#submitHere'])).has('UNKNOWN_SPEC'), 'and catches what it raises');
+ assert.ok(walk.refusalsOf('cli.js#freezer').has('A5_GRAMMAR_VERSION'), 'the freezer propagates an unsupported grammar version');
for (const code of ['NOT_CLAIMABLE', 'LANE_HELD', 'GATE_RED', 'NO_GATE', 'NOT_AT_COMMIT', 'SELF_VERIFY', 'BAD_DECISION']) {
assert.ok(ENTRY_POINTS.some(({ at }) => at.some((entry) => walk.refusalsOf(entry).has(code))), `the walk finds ${code}`);
}
@@ -407,6 +417,8 @@ test('a broken copy of the declaration fails the check against the code, both wa
noRows.guards = noRows.guards.filter((guard) => guard.id !== 'rowsInForce');
for (const move of noRows.moves) move.guards = move.guards.filter((id) => id !== 'rowsInForce');
assert.deepEqual(codeProblems(noRows).sort(), [
+ 'A5_GRAMMAR_VERSION is raised by claim but not declared there',
+ 'A5_GRAMMAR_VERSION is raised by refreeze but not declared there',
'UNKNOWN_SPEC is raised by claim but not declared there',
'UNKNOWN_SPEC is raised by refreeze but not declared there',
]);
@@ -421,7 +433,7 @@ test('a broken copy of the declaration fails the check against the code, both wa
const invented = copy();
invented.guards.push({ id: 'moonPhase', refuse: 'WRONG_MOON', rule: 'the moon is full', next: 'wait', source: 'board' });
moveOf(invented, 'claim').guards.push('moonPhase');
- assert.deepEqual(codeProblems(invented), ['WRONG_MOON is declared but board.js and cli.js never raise it']);
+ assert.deepEqual(codeProblems(invented), ['WRONG_MOON is declared but the board, CLI and spec parser never raise it']);
});
test('a broken copy of the code fails the check: a refusal added wherever a move reaches [M1, M4]', () => {
@@ -715,7 +727,7 @@ test('docs/lifecycle.md is the page the declaration generates, so a stale copy f
for (const id of effectiveGuards(move)) assert.ok(page.includes(id), `${move.verb}'s guard ${id} is listed`);
}
for (const [state, guards] of Object.entries(MACHINE.exitGuards)) assert.ok(page.includes(`| ${state} | ${guards.join(', ')} |`), `${state}'s exit guards are listed`);
- const codes = new Set([...MACHINE.guards.map((guard) => guard.refuse), ...MACHINE.moves.map((move) => move.refuse), MACHINE.unknownMove.refuse].filter(Boolean));
+ const codes = new Set([...MACHINE.guards.flatMap((guard) => [guard.refuse, ...(guard.alsoRefuses ?? []).map((entry) => entry.code)]), ...MACHINE.moves.map((move) => move.refuse), MACHINE.unknownMove.refuse].filter(Boolean));
for (const code of codes) assert.match(page, new RegExp(`^\\| ${code} \\|`, 'm'), `${code} is in the refusal table`);
});
diff --git a/test/spec.test.js b/test/spec.test.js
index 91f60883..13c8b81b 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -17,6 +17,7 @@ import {
permanenceProblems,
readSignoffs,
SIGNOFFS_FILE,
+ SPEC_GRAMMAR_VERSION,
signOff,
standings,
unmetRows,
@@ -51,6 +52,86 @@ test('rows parse with id, status, tier, text, gate, serves, section and line [S1
assert.deepEqual(lintSpec(spec), []);
});
+test('SPEC and PRACTICE grammar defaults to version 1 and accepts its declaration [A5]', () => {
+ assert.equal(SPEC_GRAMMAR_VERSION, 1);
+ const legacy = parseSpec(SPEC);
+ const declared = parseSpec(`<!-- pullboard-grammar ${SPEC_GRAMMAR_VERSION} -->\n${SPEC}`);
+ assert.equal(legacy.grammarVersion, SPEC_GRAMMAR_VERSION);
+ assert.equal(declared.grammarVersion, SPEC_GRAMMAR_VERSION);
+ assert.deepEqual(declared.intro, legacy.intro);
+ assert.deepEqual(declared.rows.map(({ line, ...row }) => row), legacy.rows.map(({ line, ...row }) => row));
+ assert.deepEqual(lintSpec(declared), []);
+});
+
+test('a newer SPEC grammar is refused with its version and an upgrade step [A5]', () => {
+ for (const version of ['2', '9007199254740993', '0', '2.5', '']) {
+ assert.throws(() => parseSpec(`<!-- pullboard-grammar ${version} -->\n${SPEC}`), {
+ code: 'A5_GRAMMAR_VERSION',
+ message: new RegExp(`grammar .*not supported.*reads grammar ${SPEC_GRAMMAR_VERSION}.*upgrade Pullboard`),
+ });
+ }
+ const fence = String.fromCharCode(96).repeat(3);
+ assert.equal(parseSpec(`${fence}\n<!-- pullboard-grammar 2 -->\n${fence}\n${SPEC}`).grammarVersion, SPEC_GRAMMAR_VERSION);
+ assert.throws(() => parseSpec(`<!-- pullboard-grammar 1 -->\n<!-- pullboard-grammar 2 -->\n${SPEC}`), { code: 'A5_GRAMMAR_VERSION' });
+});
+
+test('real spec check refuses future grammar in either configured file [A5]', (t) => {
+ const practice = '# Practice\n\n## P\n- P1 [draft] A local rule.\n';
+ const box = specBox(t, { specName: 'requirements.md', practiceName: 'ways.md', practice });
+ for (const [name, source] of [[box.specName, SPEC], [box.practiceName, practice]]) {
+ writeFileSync(join(box.root, name), `<!-- pullboard-grammar ${SPEC_GRAMMAR_VERSION} -->\n${source}`);
+ }
+ assert.equal(box.run('check').status, 0);
+ for (const [name, source] of [[box.specName, SPEC], [box.practiceName, practice]]) {
+ writeFileSync(join(box.root, name), '<!-- pullboard-grammar 2 -->\n' + source);
+ const text = box.run('check');
+ assert.equal(text.status, 1);
+ assert.match(text.stderr, /A5_GRAMMAR_VERSION.*grammar 2.*grammar 1.*upgrade Pullboard/);
+ const json = box.run('check', '--json');
+ assert.equal(json.status, 1);
+ const error = JSON.parse(json.stdout).error;
+ assert.equal(error.code, 'A5_GRAMMAR_VERSION');
+ assert.ok(!error.message.includes('[A5_GRAMMAR_VERSION]'));
+ assert.match(error.message, /grammar 2.*grammar 1.*upgrade Pullboard/);
+ assert.match(error.next, /upgrade Pullboard/);
+ writeFileSync(join(box.root, name), source);
+ }
+ assert.equal(box.run('check').status, 0);
+});
+
+test('a grammar-1 repair can commit after grammar 2 was already recorded [A5,S8]', (t) => {
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-grammar-history-')));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const env = {
+ ...process.env,
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Test Agent',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Test Agent',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ PULLBOARD_HOME: join(root, '.home'),
+ };
+ const git = (...args) => execFileSync('git', args, { cwd: root, env, encoding: 'utf8', stdio: 'pipe' });
+ const command = (...args) => spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), ...args], { cwd: root, env, encoding: 'utf8' });
+ git('init', '-q', '-b', 'main');
+ git('config', 'user.name', 'Test Agent');
+ git('config', 'user.email', '[email protected]');
+ writeFileSync(join(root, 'SPEC.md'), `<!-- pullboard-grammar 2 -->\n${SPEC}`);
+ writeFileSync(join(root, 'PRACTICE.md'), '<!-- pullboard-grammar 2 -->\n# Practice\n');
+ git('add', '-A');
+ git('commit', '-q', '-m', 'docs: preserve pre-upgrade grammar');
+ const initialized = command('init');
+ assert.equal(initialized.status, 0, `${initialized.stdout}${initialized.stderr}`);
+ writeFileSync(join(root, 'SPEC.md'), `<!-- pullboard-grammar 1 -->\n${SPEC}`);
+ writeFileSync(join(root, 'PRACTICE.md'), '<!-- pullboard-grammar 1 -->\n# Practice\n');
+ git('add', '-A');
+ const repaired = spawnSync('git', ['commit', '-q', '-m', 'docs: restore supported grammar'], { cwd: root, env, encoding: 'utf8' });
+ assert.equal(repaired.status, 0, `${repaired.stdout}${repaired.stderr}`);
+ const checked = command('spec', 'check');
+ assert.equal(checked.status, 0, `${checked.stdout}${checked.stderr}`);
+});
+
test('a row-like line that does not parse is an error, never dropped [S1]', () => {
const spec = parseSpec('## G\n- G1 [approved, must]\n- just a bullet note\n');
const findings = lintSpec(spec);