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(view): pin row ages to one captured commit [N26]
Corey Olson9ad151838bd7
diff --git a/src/serve.js b/src/serve.jsindex d88c0481..769e3f97 100644--- a/src/serve.js+++ b/src/serve.js@@ -173,16 +173,16 @@ function withProject(root, read, providedBoard = null) {** @param {string} root* @param {string} file- * @param {(root: string, file: string) => { ids: Map<string, string> }} [history]+ * @param {string | null} head The one commit captured for this project's state.+ * @param {(root: string, file: string, revs: string[]) => { ids: Map<string, string> }} [history]* @returns {Map<string, number>}*/-function rowAges(root, file, history = committedIds) {- const head = resolveCommit(root, 'HEAD');+function rowAges(root, file, head, history = committedIds) {const key = root + '\0' + file, kept = agesKept.get(key);if (kept && kept.head === head) return kept.ages;- const log = head ? spawnSync('git', ['log', '--follow', '--format=%H', 'HEAD', '--', file], { cwd: root, encoding: 'utf8' }) : null;+ const log = head ? spawnSync('git', ['log', '--follow', '--format=%H', head, '--', file], { cwd: root, encoding: 'utf8' }) : null;const place = new Map((log?.status === 0 ? log.stdout : '').split('\n').filter(Boolean).map((commit, n) => [commit, n + 1]));- const ages = new Map([...history(root, file).ids].map(([id, commit]) => [id, place.get(commit) ?? place.size + 1]));+ const ages = new Map([...(head ? history(root, file, [head]).ids : new Map())].map(([id, commit]) => [id, place.get(commit) ?? place.size + 1]));agesKept.set(key, { head, ages });return ages;}@@ -201,13 +201,15 @@ export function projectState(root, { seen = null, board: providedBoard = null }return withProject(root, (board, info, config) => {const all = store.listItems(board, { all: true });const status = new Map(all.map((item) => [item.item_id, item.item_status]));+ // Both row lists and their cached ages name this commit even if HEAD moves between Git reads.+ const head = resolveCommit(info.root, 'HEAD');const rows = (file) => {- const ages = rowAges(info.root, file);+ const ages = rowAges(info.root, file, head);return loadSpec(info.root, { ...config, spec: file }).rows.map(({ id, status: state, tier, text, gate, serves, section }) => ({ id, status: state, tier, text, gate, serves, section, added: ages.get(id) ?? 0 }));};const doctrine = loadDoctrine(info.root, config);// A standard rule was never added to this repo, so it has no age here; the repo's own rows have.- const doctrineAges = rowAges(info.root, doctrine.name, doctrineHistory);+ const doctrineAges = rowAges(info.root, doctrine.name, head, doctrineHistory);// A decline's text is its reason. Keep the inherited rule available so the page strikes the// rule itself, while showing the repo's reason beside it.const inherited = new Map(standardDoctrine().rows.map((row) => [row.id, row.text]));@@ -217,6 +219,7 @@ export function projectState(root, { seen = null, board: providedBoard = null }const lastMove = new Map(log.map((event) => [event.event_by, event.event_at]));return {root: info.root,+ rowAgesAt: { [config.spec]: head, [doctrine.name]: head },lanes: [COORDINATOR, ...Object.keys(config.lanes)],// The lanes that own folders, where builders work; review lanes own none.owning: Object.keys(config.lanes).filter((lane) => (config.lanes[lane].owns ?? []).length > 0),diff --git a/test/cockpit/search.test.js b/test/cockpit/search.test.jsindex 7d0515d4..606bcae2 100644--- a/test/cockpit/search.test.js+++ b/test/cockpit/search.test.js@@ -1,11 +1,92 @@/** Cockpit search checks, using the shared real-board fixtures [N26]. */import assert from 'node:assert/strict';-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { execFileSync, spawnSync } from 'node:child_process';+import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { test } from 'node:test';import { SPEC, machine, project, startView, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, searchFor, press } from './fixture.js';+/** Commit between actual Git reads, preserving each real command's output and exit status. */+function interleavedAges(file, when) {+ const box = machine();+ const g3 = '- G3 [approved, must] The greeting names the visitor. | gate: web test\n';+ const g4 = '- G4 [approved, must] The greeting waves back. | gate: web test\n';+ const g5 = '- G5 [approved, must] The greeting fits a phone. | gate: web test\n';+ const r1 = '# Local rules\n\n## Team\n- R1 [approved, must] Every greeting is read by a person. | gate: review\n';+ const r2 = '- R2 [approved, must] A greeting never shouts. | gate: review\n';+ const alpha = project(box, 'pinned-ages', SPEC + g3, { practice: 'ways.md' });+ writeFileSync(join(alpha.repo, 'ways.md'), r1);+ writeFileSync(join(alpha.repo, 'SPEC.md'), SPEC + g3 + g4);+ box.git(alpha.repo, 'add', 'ways.md', 'SPEC.md');+ box.git(alpha.repo, 'commit', '-q', '-m', 'docs(spec): add the second greeting [G1]');+ const specTarget = file === 'SPEC.md';+ writeFileSync(join(alpha.repo, specTarget ? 'ways.md' : 'SPEC.md'), specTarget ? r1 + r2 : SPEC + g5 + g3 + g4);+ box.git(alpha.repo, 'commit', '-q', '-am', 'docs(spec): add the next greeting [G1]');+ const captured = box.git(alpha.repo, 'rev-parse', 'HEAD');+ const future = join(box.dir, 'next-row.txt'), receipt = join(box.dir, 'interleave.json');+ writeFileSync(future, specTarget ? SPEC + g5 + g3 + g4 : r1 + r2);+ const realGit = execFileSync('which', ['git'], { encoding: 'utf8' }).trim();+ const wrapper = join(box.dir, 'bin', 'git');+ writeFileSync(wrapper, `#!${process.execPath}+import { spawnSync } from 'node:child_process';+import { existsSync, readFileSync, writeFileSync } from 'node:fs';+const args = process.argv.slice(2), file = ${JSON.stringify(file)}, receipt = ${JSON.stringify(receipt)};+const realGit = ${JSON.stringify(realGit)};+/** Run the real Git command with unchanged arguments and environment. */+const run = (words) => spawnSync(realGit, words, { encoding: 'utf8', env: process.env });+const interleave = args[0] === 'log' && args.includes('--format=%H') && args.at(-1) === file && !existsSync(receipt);+let before, after, result;+/** Add the prepared real row in a real commit, without changing any command response. */+function advance() {+ writeFileSync(file, readFileSync(${JSON.stringify(future)}));+ for (const words of [['add', file], ['commit', '-q', '-m', 'docs(spec): interleave a greeting [G1]']]) {+ const step = run(words);+ if (step.status !== 0) throw new Error(step.stderr);+ }+ after = run(['rev-parse', 'HEAD']).stdout.trim();+}+if (interleave) {+ before = run(['rev-parse', 'HEAD']).stdout.trim();+ writeFileSync(receipt, '{}');+ if (${JSON.stringify(when)} === 'before') advance();+ result = run(args);+ if (${JSON.stringify(when)} === 'after') advance();+ writeFileSync(receipt, JSON.stringify({ args, before, after, status: result.status, stdout: result.stdout }));+} else result = run(args);+process.stdout.write(result.stdout ?? ''); process.stderr.write(result.stderr ?? ''); process.exitCode = result.status ?? 1;+`);+ chmodSync(wrapper, 0o755);+ // Both tabs may read the on-disk row before its commit lands between their history reads.+ writeFileSync(join(alpha.repo, file), readFileSync(future));+ const worker = spawnSync(process.execPath, ['--input-type=module', '-e', `import { projectState } from ${JSON.stringify(new URL('../../src/serve.js', import.meta.url).href)}; console.log(JSON.stringify(projectState(${JSON.stringify(alpha.repo)})));`], { cwd: alpha.repo, env: box.env, encoding: 'utf8' });+ assert.equal(worker.status, 0, `real projectState child: ${worker.stderr}`);+ const state = JSON.parse(worker.stdout), observed = box.git(alpha.repo, 'rev-parse', 'HEAD');+ const proof = JSON.parse(readFileSync(receipt, 'utf8'));+ const ordinals = { spec: state.spec.map(({ id, added }) => ({ id, added })), doctrine: state.practice.map(({ id, added }) => ({ id, added })) };+ return { state, captured, observed, proof, ordinals };+}++/** Pin every age read despite a real commit before or after either file's ordinal log. */+test('row ages read from one captured commit [N26]', () => {+ for (const file of ['SPEC.md', 'ways.md']) for (const when of ['after', 'before']) {+ const { state, captured, observed, proof, ordinals } = interleavedAges(file, when);+ const diagnostic = JSON.stringify({ file, when, ordinals, captured, observed, computedAt: state.rowAgesAt ?? null, proof });+ assert.notEqual(observed, captured, diagnostic);+ assert.equal(proof.before, captured, diagnostic);+ assert.equal(proof.after, observed, diagnostic);+ assert.equal(proof.status, 0, diagnostic);+ /** Keep only the deliberate fixture rows, in the same age order as search results. */+ const ordered = (rows, ids) => rows.filter((row) => ids.includes(row.id)).sort((a, b) => a.added - b.added).map(({ id, added }) => [id, added]);+ const spec = ordered(state.spec, ['G3', 'G4', 'G5']), doctrine = ordered(state.practice, ['R1', 'R2']);+ assert.deepEqual(spec.map(([id]) => id), ['G5', 'G4', 'G3'], diagnostic);+ assert.deepEqual(doctrine.map(([id]) => id), ['R2', 'R1'], diagnostic);+ assert.deepEqual(spec, file === 'SPEC.md' ? [['G5', 0], ['G4', 1], ['G3', 2]] : [['G5', 1], ['G4', 2], ['G3', 3]], diagnostic);+ assert.deepEqual(doctrine, file === 'SPEC.md' ? [['R2', 1], ['R1', 2]] : [['R2', 0], ['R1', 1]], diagnostic);+ assert.deepEqual(state.rowAgesAt, { 'SPEC.md': captured, 'ways.md': captured }, diagnostic);+ }+});+test('search in the top bar finds anything on the board [N26]', { timeout: 150_000 }, async (t) => {const executable = chromeExecutable();@@ -139,7 +220,8 @@ test('search in the top bar finds anything on the board [N26]', { timeout: 150_0await chrome.waitFor("data.project.spec.some((row) => row.id === 'G5') && data.project.practice.some((row) => row.id === 'R2')", 15_000);await search('greeting');const added = (await read()).hits.filter((hit) => /^(spec|doctrine):/.test(hit.go)).map((hit) => hit.id);- assert.deepEqual(added, ['G5', 'G4', 'G3', 'R2', 'R1'], `Spec and Doctrine newest first by when each row was added: ${JSON.stringify(added)}`);+ const ageProof = JSON.parse(await chrome.stable('JSON.stringify({ captured: data.project.rowAgesAt ?? null, spec: data.project.spec.map(({ id, added }) => ({ id, added })), doctrine: data.project.practice.map(({ id, added }) => ({ id, added })) })'));+ assert.deepEqual(added, ['G5', 'G4', 'G3', 'R2', 'R1'], `Spec and Doctrine newest first by when each row was added: ${JSON.stringify({ added, ...ageProof, observed: box.git(alpha.repo, 'rev-parse', 'HEAD') })}`);await key('Escape', 'Escape', 27);// A click opens a Spec row, a Doctrine rule or a shout where it lives.