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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(spec): spec check at an older commit skips later items' ids [S10]
Corey Olson26a25b01d2b9
diff --git a/src/cli.js b/src/cli.jsindex 7d305f6b..fb17a70f 100644--- a/src/cli.js+++ b/src/cli.js@@ -987,20 +987,26 @@ function workCommands(io, args) {/*** Every spec id something cites (S8): commit headers since the spec's first commit, and every item- * on the board, open or closed. Each must still be in the spec.+ * on the board, open or closed. Each must still be in the spec. The board is shared by every+ * checkout, so at an older commit an item may cite a row a later commit added: that id is not lost+ * here, only not written yet, and it counts once any ref has committed it (S10).** @param {any} ctx- * @param {string | null} since+ * @param {{ ids: Map<string, string>, since: string | null }} history - this checkout's.* @returns {Map<string, string>} Each id, with who cites it.*/-function citations(ctx, since) {+function citations(ctx, { ids, since }) {const cited = since ? commitCitations(ctx.info.root, since) : new Map();if (!existsSync(ctx.file)) return cited;+ const byItems = new Map();for (const item of withBoard(ctx, (board) => store.listItems(board, { all: true }))) {for (const id of item.item_spec_ids ? item.item_spec_ids.split(',') : []) {- if (!cited.has(id)) cited.set(id, `item #${item.item_id}`);+ if (!cited.has(id) && !byItems.has(id)) byItems.set(id, `item #${item.item_id}`);}}+ const unseen = [...byItems.keys()].some((id) => !ids.has(id));+ const elsewhere = unseen ? committedIds(ctx.info.root, ctx.config.spec, ['--all']).ids : new Map();+ for (const [id, where] of byItems) if (ids.has(id) || !elsewhere.has(id)) cited.set(id, where);return cited;}@@ -1023,7 +1029,7 @@ function specCommand(io, { first, second, rest, values }) {const findings = lintSpec(parsed);findings.forEach((finding) => io.say(`${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.since) : new Map();+ const cited = name === ctx.config.spec ? citations(ctx, history) : new Map();const lost = permanenceProblems(parsed, { committed: history.ids, cited });lost.forEach((problem) => io.say(`${name}: ${problem.id} error: ${problem.message}`));const fileErrors = findings.filter((finding) => finding.level === 'error').length + lost.length;diff --git a/src/history.js b/src/history.jsindex f08f3d64..408023b1 100644--- a/src/history.js+++ b/src/history.js@@ -23,17 +23,19 @@ function gitOut(root, args) {}/**- * Every committed version of a file reachable from HEAD, newest first: the commit, and the file's- * whole text after it. Renames are followed. One git process, however long the history.+ * Every committed version of a file reachable from `revs` (HEAD by default), newest first: the+ * commit, and the file's whole text after it. Renames are followed. One git process, however long+ * the history.** @param {string} root* @param {string} path+ * @param {string[]} [revs]* @returns {{ commit: string, text: string }[]}*/-export function fileVersions(root, path) {+export function fileVersions(root, path, revs = ['HEAD']) {const out = gitOut(root, ['log', '--follow', '--format=%x00%H', '-p', '--unified=1000000',- '--no-color', '--no-ext-diff', '--no-textconv', 'HEAD', '--', path,+ '--no-color', '--no-ext-diff', '--no-textconv', ...revs, '--', path,]);if (!out) return [];return out.split('\0').filter((chunk) => chunk.trim()).map((chunk) => {@@ -49,10 +51,11 @@ export function fileVersions(root, path) {** @param {string} root* @param {string} path+ * @param {string[]} [revs] - the history to walk; HEAD's by default.* @returns {{ ids: Map<string, string>, since: string | null }} `since` is the file's first commit.*/-export function committedIds(root, path) {- const versions = fileVersions(root, path);+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);diff --git a/test/e2e.test.js b/test/e2e.test.jsindex 9d6641e0..ff3ea687 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -732,3 +732,18 @@ test('submit refuses a bar that moved since the claim, before any verifier runs;box.run(box.web, 'claim', '1');assert.match(box.run(box.web, 'submit', '1').out, /submitted #1/);});++test('spec check at an older commit skips ids that items cite from a later commit; a never-committed id still fails [S10]', () => {+ const box = project();+ writeFileSync(join(box.repo, 'SPEC.md'), `${SPEC}- G3 [draft, must] The page has a footer.\n`);+ box.git(box.repo, 'commit', '-qam', 'docs(spec): a footer row');+ box.run(box.repo, 'add', 'web', 'Footer', '--specs', 'G3');+ const older = box.run(box.web, 'spec', 'check');+ assert.equal(older.code, 0, older.out);+ writeFileSync(join(box.repo, 'SPEC.md'), `${SPEC}- G3 [draft, must] The page has a footer.\n- G4 [draft, must] Not committed.\n`);+ box.run(box.repo, 'add', 'web', 'Ghost', '--specs', 'G4');+ const ghost = box.run(box.web, 'spec', 'check');+ assert.equal(ghost.code, 1);+ assert.match(ghost.out, /SPEC.md: G4 error: item #2 cites it, but it was never committed/);+ assert.doesNotMatch(ghost.out, /G3 error/);+});