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): reject cross-file duplicate ids [A5]

Corey Olsonc30a46f3a007
diff --git a/src/cli.js b/src/cli.js
index ffb6ccae..49efe669 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1588,10 +1588,27 @@ function specCommand(io, { first, second, rest, values }) {
if (first === 'check' || first === undefined) {
const files = [[ctx.config.spec, spec], ...(practice.exists ? [[ctx.config.practice, practice]] : [])];
for (const [, parsed] of files) assertRequiredSigners(ctx.info.root, parsed.rows);
+ const repeatedAcrossFiles = new Map(files.map(([name]) => [name, []]));
+ const firstLocation = new Map();
+ for (const [name, parsed] of files) {
+ for (const row of parsed.rows) {
+ const first = firstLocation.get(row.id);
+ if (first && first.name !== name) {
+ repeatedAcrossFiles.get(first.name).push({
+ level: 'error', line: first.line, id: row.id,
+ message: `duplicate id; also appears at ${name}:${row.line}`,
+ });
+ repeatedAcrossFiles.get(name).push({
+ level: 'error', line: row.line, id: row.id,
+ message: `duplicate id; also appears at ${first.name}:${first.line}`,
+ });
+ } else if (!first) firstLocation.set(row.id, { name, line: row.line });
+ }
+ }
let errors = 0;
const messages = [];
for (const [name, parsed] of files) {
- const findings = lintSpec(parsed);
+ const findings = [...lintSpec(parsed), ...repeatedAcrossFiles.get(name)];
findings.forEach((finding) => messages.push(`${name}:${finding.line} ${finding.id ?? ''} ${finding.level}: ${finding.message}`.replace(' ', ' ')));
const history = committedIds(ctx.info.root, name);
const cited = name === ctx.config.spec ? citations(ctx, history) : new Map();
diff --git a/src/templates.js b/src/templates.js
index db4405a2..cb6cfa61 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -72,7 +72,7 @@ Inherits Pullboard standard doctrine version 1.
## T · Tests
-## G · Git and the gate
+## P · Git and the gate
## D · Dependencies
diff --git a/test/e2e.test.js b/test/e2e.test.js
index a6593677..81ab74e1 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -180,6 +180,22 @@ test('init writes config, spec, agent docs and hooks once, and never clobbers [I
assert.deepEqual(parseSpec(practice).rows, [], 'fresh init copies no standard rules [D4]');
assert.equal(parseSpec(practice).sections.length, 6);
assert.equal(practice.split('Inherits Pullboard standard doctrine version 1.').length, 2);
+ assert.equal(box.run(repo, 'spec', 'check').code, 0, 'fresh init has no repeated ids [A5]');
+ const specRows = parseSpec(readFileSync(join(repo, 'SPEC.md'), 'utf8'));
+ const practiceRows = parseSpec(practice);
+ const specPrefixes = specRows.sections.map(({ name }) => /^([A-Z])\s/u.exec(name)?.[1]).filter(Boolean);
+ const practicePrefixes = parseSpec(practice).sections.map(({ name }) => /^([A-Z])\s/u.exec(name)?.[1]).filter(Boolean);
+ assert.equal(specPrefixes.some((prefix) => practicePrefixes.includes(prefix)), false, 'init assigns distinct row prefixes to SPEC and PRACTICE');
+ for (const [file, parsed] of [['SPEC.md', specRows], ['PRACTICE.md', practiceRows]]) {
+ const source = readFileSync(join(repo, file), 'utf8');
+ const additions = parsed.sections.map(({ name }) => {
+ const prefix = /^([A-Z])\s/u.exec(name)?.[1];
+ return prefix ? `\n- ${prefix}1 [draft] A starter row.\n` : '';
+ }).join('');
+ writeFileSync(join(repo, file), `${source}${additions}`);
+ }
+ const representativeRows = box.run(repo, 'spec', 'check');
+ assert.equal(representativeRows.code, 0, representativeRows.err || representativeRows.out);
assert.match(agents, /PB1 \(standard 1\)/, 'fresh guidance shows inherited rules [D3]');
assert.ok(existsSync(join(repo, '.claude', 'skills', 'pullboard-decompose', 'SKILL.md')));
assert.match(second.out, /kept PRACTICE.md/);
diff --git a/test/spec.test.js b/test/spec.test.js
index ced7511a..d7a5cc31 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -109,6 +109,26 @@ test('real spec check refuses future grammar in either configured file [A5]', (t
assert.equal(box.run('check').status, 0);
});
+test('spec check names both locations when ids repeat within or across configured files [A5]', (t) => {
+ const practiceRow = '# Practice\n\n## P\n- G1 [draft] A local rule.\n';
+ const crossFile = specBox(t, { practice: practiceRow });
+ const cross = crossFile.run('check');
+ assert.equal(cross.status, 1);
+ assert.match(cross.stdout, /SPEC\.md:6 G1 error: duplicate id; also appears at PRACTICE\.md:4/u);
+ assert.match(cross.stdout, /PRACTICE\.md:4 G1 error: duplicate id; also appears at SPEC\.md:6/u);
+
+ for (const [file, source, line] of [
+ ['SPEC.md', SPEC.replace('- G1.2 [draft, aim]', '- G1 [draft, aim]'), 7],
+ ['PRACTICE.md', '# Practice\n\n## P\n- P1 [draft] First.\n- P1 [draft] Second.\n', 5],
+ ]) {
+ const box = specBox(t, { practice: file === 'PRACTICE.md' ? source : undefined });
+ if (file === 'SPEC.md') writeFileSync(join(box.root, file), source);
+ const result = box.run('check');
+ assert.equal(result.status, 1);
+ assert.match(result.stdout, new RegExp(`${file}:${line} .*duplicate id; first on line`));
+ }
+});
+
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 }));