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
feat(doctrine): files: narrows a check; uncountable ones refuse [D1,D3]
Corey Olson26af01f5b15a
diff --git a/docs/lifecycle.md b/docs/lifecycle.mdindex 3cc4f580..bbe0de08 100644--- a/docs/lifecycle.md+++ b/docs/lifecycle.md@@ -54,7 +54,7 @@ Each move checks its guards in this order and refuses with the first one that do| claim | open, claimed | claimed | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_CLAIMABLE), itemNotHeld (ITEM_HELD), inLane (WRONG_LANE), routeAllows (ROUTE), dependenciesVerified (BLOCKED), notHeldByAnother (HELD), correctionRefrozen (PENDING_REFREEZE), laneOpen (LANE_HELD), oneLiveClaim (ONE_CLAIM), rowsInForce (UNKNOWN_SPEC or A5_GRAMMAR_VERSION or NO_POLICY or BAD_CONFIG or SPEC_BEHIND_MAIN) || release | claimed | open | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), reviewReleaseExplained (NOTE_REQUIRED) || lapse | claimed | open | clock, when its lease runs out | none |-| submit | claimed | submitted | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), correctionRefrozen (PENDING_REFREEZE), criterionUnchanged (CRITERIA_CHANGED), treeClean (DIRTY), nothingUntracked (UNTRACKED), hasCommit (NO_COMMIT), withinLane (OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), doctrineHolds (RATCHET_ROSE), gateConfigured (NO_GATE), gateGreen (GATE_RED or PIPEFAIL_UNAVAILABLE), treeStillDuringGate (MOVED_DURING_GATE), childrenDone (CHILDREN_OPEN), headIsNew (HEAD_NOT_NEW) |+| submit | claimed | submitted | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), correctionRefrozen (PENDING_REFREEZE), criterionUnchanged (CRITERIA_CHANGED), treeClean (DIRTY), nothingUntracked (UNTRACKED), hasCommit (NO_COMMIT), withinLane (OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), doctrineHolds (RATCHET_ROSE or RATCHET_UNCOUNTED), gateConfigured (NO_GATE), gateGreen (GATE_RED or PIPEFAIL_UNAVAILABLE), treeStillDuringGate (MOVED_DURING_GATE), childrenDone (CHILDREN_OPEN), headIsNew (HEAD_NOT_NEW) || reserve | submitted | submitted | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), roadmapReadable (MILESTONES_CORRUPT), itemExists (NO_ITEM), inState (NOT_SUBMITTED), reviewCooldownElapsed (REVIEW_COOLDOWN), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD) || accept | submitted | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), itemCheckGreen (CHECK_RED or CHECK_UNVERIFIED), proofNoted (PROOF_REQUIRED) || reject | submitted | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED) |@@ -120,7 +120,8 @@ Each move checks its guards in this order and refuses with the first one that do| NO_POLICY | the candidate merges cleanly into the current primary branch without changing an index or worktree | restore the primary repository metadata || NO_TRUNK | the candidate merges cleanly into the current primary branch without changing an index or worktree | check out the trunk branch in the main checkout once and run pullboard inbox || STACKED_ON_UNVERIFIED | the candidate range contains no other item's unverified submitted commit | wait for that item to be accepted, or rebuild without its commits |-| RATCHET_ROSE | no touched doctrine check rises above its committed count and no changed file gains a problem; watch-mode rules only count, only when accepted main has an approved doctrine rule with gate: check | fix the new problems, commit, submit again; only the person's signature raises count: |+| RATCHET_ROSE | every touched doctrine check counts (exit 0 or 1), none rises above its committed count and no changed file gains a problem; watch-mode rules only count, only when accepted main has an approved doctrine rule with gate: check | fix the new problems, commit, submit again; only the person's signature raises count: |+| RATCHET_UNCOUNTED | every touched doctrine check counts (exit 0 or 1), none rises above its committed count and no changed file gains a problem; watch-mode rules only count, only when accepted main has an approved doctrine rule with gate: check | fix the check so it exits 0 or 1 within its timeout, then submit again || CHECK_RED | the frozen item check passes at the exact submitted commit | reject the failing behavior; the builder fixes and resubmits || CHECK_UNVERIFIED | the frozen item check passes at the exact submitted commit | restore the frozen install or check environment and retry || GATE_RED | the gate, which submit runs itself every time, is green at HEAD | fix what the digest names, commit, submit again |diff --git a/src/doctrine-checks.js b/src/doctrine-checks.jsindex 6badd64b..488b1eb3 100644--- a/src/doctrine-checks.js+++ b/src/doctrine-checks.js@@ -1,9 +1,10 @@/*** Doctrine checks with a count that only falls (D1, D3). A rule row may carry- * `| gate: check <command> | count: N`; the command prints one line per problem. Submit holds- * every touched rule's count at or below its committed count and refuses a changed file that- * gains a problem. Rules come only from committed doctrine: accepted main's at submit, HEAD's for- * `pullboard doctrine check`, never a working-tree edit.+ * `| gate: check <command> | count: N`, and `| files: <paths>` to narrow it; the command prints one+ * line per problem and exits 0 or 1. Submit holds every touched rule's count at or below its+ * committed count and refuses a changed file that gains a problem. Rules come only from committed+ * doctrine: accepted main's at submit, HEAD's for `pullboard doctrine check`, never a working-tree+ * edit.*/import { spawnSync } from 'node:child_process';import { mkdtempSync, rmSync } from 'node:fs';@@ -21,12 +22,17 @@ const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;* are lint errors in `pullboard spec check`; here they simply carry no rule.** @param {any} row- * @returns {{ id: string, text: string, status: string, command: string, count: number, runs: string, mode: string } | null}+ * @returns {{ id: string, text: string, status: string, command: string, count: number, runs: string, mode: string, files: string[] } | null}*/export function checkRule(row) {if (!/^check\s/u.test(row?.gate ?? '') || checkFieldFindings(row).length) return null;return { id: row.id, text: row.text, status: row.status, command: row.gate.slice('check'.length).trim(),- count: Number(row.count), runs: row.runs ?? 'submit', mode: row.mode ?? 'hold' };+ count: Number(row.count), runs: row.runs ?? 'submit', mode: row.mode ?? 'hold', files: ruleFiles(row.files) };+}++/** A row's `files:` paths, comma or space separated, without `./` or a trailing slash; none is the whole repo. */+export function ruleFiles(value) {+ return [...new Set(String(value ?? '').split(/[\s,]+/u).map((path) => path.replace(/^\.\//u, '').replace(/\/+$/u, '')).filter(Boolean))];}/**@@ -46,6 +52,8 @@ export function checkLoosening(before, after) {if (next.count > old.count) return `raises count: from ${old.count} to ${next.count}`;if (old.mode === 'hold' && next.mode === 'watch') return 'sets mode: watch';if (old.runs === 'submit' && next.runs === 'nightly') return 'moves its check to runs: nightly';+ // files: narrows a rule: adding it to a whole-repo rule, or dropping a path, covers less.+ if ((!old.files.length && next.files.length) || old.files.some((path) => !next.files.includes(path))) return 'narrows its files:';return '';}@@ -82,8 +90,9 @@ export function checkRulesAt(root, revision, name = DOCTRINE_FILE) {}/**- * Run one check where it stands and keep each non-empty output line as a problem. The exit status- * is not read: `grep` exits 1 when it finds nothing, which is zero problems.+ * Run one check where it stands and keep each non-empty output line as a problem. Exit 0 or 1 is+ * counted (`grep` exits 1 when it finds nothing); any other exit, a signal or a timeout cannot+ * count, so its error lines never pass for problems.** @param {string} cwd* @param {string} command@@ -102,35 +111,20 @@ export function runRuleCheck(cwd, command, timeoutMs = DEFAULT_TIMEOUT_MS) {const broken = result.error.code === 'ETIMEDOUT' ? `timed out after ${Math.round(timeoutMs / 1000)}s` : `could not run (${result.error.code ?? 'error'})`;return { problems: [], broken, seconds };}+ if (result.signal) return { problems: [], broken: `was killed by ${result.signal}`, seconds };+ if (result.status !== 0 && result.status !== 1) return { problems: [], broken: `exited ${result.status}`, seconds };const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;return { problems: output.split(/\r?\n/u).map((line) => line.trimEnd()).filter((line) => line.trim()), broken: '', seconds };}-/**- * The repo paths a check command names at a revision: the files it watches. A command that names- * no existing path watches the whole repo.- *- * @param {string} root- * @param {string} revision- * @param {string} command- * @returns {string[]}- */-export function ruleScope(root, revision, command) {- const words = command.split(/\s+/u)- .map((word) => word.replace(/^['"]|['"]$/gu, '').replace(/^\.\//u, '').replace(/\/+$/u, ''))- .filter((word) => word && !word.startsWith('-') && !/[*?[\]{}$`|;&<>()]/u.test(word) && !word.startsWith('/') && !word.split('/').includes('..'));- return [...new Set(words)].filter((word) => gitOut(root, ['rev-parse', '--verify', '--quiet', `${revision}:${word}`]) !== null);-}-/** True when a changed path is one of a rule's watched paths or lies under one. */function inScope(scope, path) {return !scope.length || scope.some((watched) => path === watched || path.startsWith(`${watched}/`));}-/** True when a problem line names a file, as `path:...`, `./path:...` or the bare path. */+/** True when a problem line starts with the file's repo path, as `path:...` or `./path:...`. */function namesFile(line, file) {- const text = line.trim();- return text === file || text.startsWith(`${file}:`) || text.startsWith(`./${file}:`) || text.includes(` ${file}:`) || text.includes(` ./${file}:`);+ return line.startsWith(`${file}:`) || line.startsWith(`./${file}:`);}/** A problem line without its line number, so a moved problem is not counted as new. */@@ -158,14 +152,14 @@ function newLines(before, after) {* @returns {string}*/export function ruleLine(result) {- const counts = result.broken ? `check ${result.broken}` : `${result.count}, was ${result.committed}`;+ const counts = result.broken ? `cannot count: its check ${result.broken}, was ${result.committed}` : `${result.count}, was ${result.committed}`;return `${result.id} ${result.text} · ${counts} · ${result.state}`;}-/** Name how a counted rule stands: watching never refuses; holding is at or below its count. */+/** Name how a rule stands: a check that cannot count never holds; watching never refuses a count. */function ruleState(rule, count, committed, broken) {+ if (broken) return 'uncounted';if (rule.mode === 'watch') return 'watching';- if (broken) return 'broken';return count <= committed ? 'holding' : 'rose';}@@ -226,9 +220,9 @@ export function holdDoctrine(root, { mainCommit, commit, practice = DOCTRINE_FILconst changed = (gitOut(root, ['diff', '-z', '--no-renames', '--name-only', base, commit, '--']) ?? '').split('\0').filter(Boolean);const results = [];const refusals = [];+ const uncounted = [];for (const rule of rules) {- const scope = ruleScope(root, commit, rule.command);- if (!changed.some((path) => inScope(scope, path))) continue;+ if (!changed.some((path) => inScope(rule.files, path))) continue;const committed = Math.min(rule.count, lowered.get(rule.id) ?? rule.count);const run = runRuleCheck(root, rule.command, timeoutMs);const count = run.problems.length;@@ -236,12 +230,13 @@ export function holdDoctrine(root, { mainCommit, commit, practice = DOCTRINE_FILconst result = { id: rule.id, text: rule.text, command: rule.command, count, committed,holds: state === 'holding' || state === 'watching', state, mode: rule.mode, runs: rule.runs, problems: run.problems, broken: run.broken };results.push(result);- if (rule.mode === 'watch') continue;const name = `${rule.id} ${rule.text}`;+ // A broken check never passes, whatever its mode.if (run.broken) {- refusals.push(`${name} cannot count: its check ${run.broken}`);+ uncounted.push(`${name} cannot count: its check ${run.broken}`);continue;}+ if (rule.mode === 'watch') continue;const touched = changed.filter((path) => run.problems.some((line) => namesFile(line, path)));const before = touched.length ? runAtCommit(root, base, rule.command, timeoutMs) : { problems: [], broken: '' };if (count > committed) {@@ -250,7 +245,7 @@ export function holdDoctrine(root, { mainCommit, commit, practice = DOCTRINE_FILcontinue;}if (before.broken) {- refusals.push(`${name} cannot compare changed files: its check ${before.broken} at the base`);+ uncounted.push(`${name} cannot count at the base ${base.slice(0, 12)}: its check ${before.broken}`);continue;}for (const path of touched) {@@ -262,6 +257,9 @@ export function holdDoctrine(root, { mainCommit, commit, practice = DOCTRINE_FILrefusals.push(`${name}: ${path} gains ${gained} problem${gained === 1 ? '' : 's'}, had ${then.length}:\n${(fresh.length ? fresh : now).map((line) => ` ${line}`).join('\n')}`);}}+ if (uncounted.length) {+ throw new Refused('RATCHET_UNCOUNTED', `${uncounted.join('\n')}\na check exits 0 or 1 within its timeout; fix the check, or ask the coordinator to, then submit again`);+ }if (refusals.length) {throw new Refused('RATCHET_ROSE', `${refusals.join('\n')}\nthe doctrine holds these counts; fix the new problems, commit, and submit again; only the person's signature raises count:`);}diff --git a/src/help.js b/src/help.jsindex caed775e..b556aa8a 100644--- a/src/help.js+++ b/src/help.js@@ -156,7 +156,8 @@ Specapprove <id> --text "new wording" approves an exact rewritepullboard spec apply coordinator applies recorded row decisions to the filespullboard doctrine check each doctrine rule's check: its count, its committed count, whether it holds- a rule row adds | gate: check <command> | count: N; the command prints one line per problem+ a rule row adds | gate: check <command> | count: N, and | files: <paths> to narrow it+ the command prints one line per problem and exits 0 or 1; anything else cannot countsubmit refuses a touched rule whose count rises; runs: nightly skips submit, mode: watch only countsRole guidesdiff --git a/src/machine.js b/src/machine.jsindex c7e51c1e..a00ff289 100644--- a/src/machine.js+++ b/src/machine.js@@ -120,7 +120,7 @@ export const GUARDS = [{ id: 'withinLane', refuse: 'OUTSIDE_LANE', alsoRefuses: [{ code: 'NO_POLICY', next: 'restore the claim base or ask the coordinator to refreeze' }, { code: 'BAD_CONFIG', next: 'restore the committed coordinator configuration' }, { code: 'GIT_GRAFTS', next: 'ask the coordinator to remove the Git graft file before retrying' }], rule: 'the full claimed diff respects committed coordinator ownership', next: 'restore foreign paths or shout their owner', source: 'cli' },{ id: 'trunkMergeClean', refuse: 'MERGE_CONFLICT', alsoRefuses: [{ code: 'MERGE_CHECK_FAILED', next: 'use Git 2.38 or newer, restore its objects and retry' }, { code: 'NO_POLICY', next: 'restore the primary repository metadata' }, { code: 'NO_TRUNK', next: 'check out the trunk branch in the main checkout once and run pullboard inbox' }], rule: 'the candidate merges cleanly into the current primary branch without changing an index or worktree', next: 'merge the trunk into your branch, resolve conflicts, commit and resubmit', source: 'cli' },{ id: 'noUnverifiedStack', refuse: 'STACKED_ON_UNVERIFIED', rule: "the candidate range contains no other item's unverified submitted commit", next: 'wait for that item to be accepted, or rebuild without its commits', source: 'cli' },- { id: 'doctrineHolds', refuse: 'RATCHET_ROSE', rule: "no touched doctrine check rises above its committed count and no changed file gains a problem; watch-mode rules only count", next: "fix the new problems, commit, submit again; only the person's signature raises count:", source: 'cli', when: 'only when accepted main has an approved doctrine rule with gate: check' },+ { id: 'doctrineHolds', refuse: 'RATCHET_ROSE', alsoRefuses: [{ code: 'RATCHET_UNCOUNTED', next: 'fix the check so it exits 0 or 1 within its timeout, then submit again' }], rule: "every touched doctrine check counts (exit 0 or 1), none rises above its committed count and no changed file gains a problem; watch-mode rules only count", next: "fix the new problems, commit, submit again; only the person's signature raises count:", source: 'cli', when: 'only when accepted main has an approved doctrine rule with gate: check' },{ id: 'itemCheckGreen', refuse: 'CHECK_RED', alsoRefuses: [{ code: 'CHECK_UNVERIFIED', next: 'restore the frozen install or check environment and retry' }], rule: 'the frozen item check passes at the exact submitted commit', next: 'reject the failing behavior; the builder fixes and resubmits', source: 'cli' },{ id: 'gateGreen', refuse: 'GATE_RED', alsoRefuses: [{ code: 'PIPEFAIL_UNAVAILABLE', next: 'rewrite the gate without a pipe' }], rule: 'the gate, which submit runs itself every time, is green at HEAD', next: 'fix what the digest names, commit, submit again', source: 'cli' },diff --git a/src/spec.js b/src/spec.jsindex 3fa4966a..3faf028d 100644--- a/src/spec.js+++ b/src/spec.js@@ -30,16 +30,18 @@ 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'];+const FIELD_NAMES = ['gate', 'serves', 'signers', 'count', 'runs', 'mode', 'files'];+const CHECK_FIELDS = ['count', 'runs', 'mode', 'files'];/*** One row's trailing fields, after the text: `| gate: ...`, `| serves: a, b` and `| signers: CO,AB`.- * A doctrine rule may add `| count: N`, `| runs: nightly` and `| mode: watch` to a `gate: check`;+ * 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.* 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 }}+ * @returns {{ text: string, gate: string, serves: string[], signers: string[], unknown: string[], count?: string, runs?: string, mode?: string, files?: string }}*/function splitFields(rest) {const [text = '', ...parts] = rest.split(' | ');@@ -56,7 +58,7 @@ function splitFields(rest) {if (key.trim() === 'gate') {fields.gate = joined;inCheck = /^check(\s|$)/u.test(joined);- } else if (['count', 'runs', 'mode'].includes(key.trim())) fields[key.trim()] = joined;+ } else if (CHECK_FIELDS.includes(key.trim())) fields[key.trim()] = joined;else if (key.trim() === 'serves') {fields.serves = joined.split(',').map((id) => id.trim()).filter(Boolean);} else if (key.trim() === 'signers') {@@ -190,14 +192,15 @@ function rowFindings(row, maxWords) {if (new Set(row.signers ?? []).size !== (row.signers ?? []).length) add('error', 'signers are unique on a row');const words = row.text.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 and mode`);+ for (const part of row.unknown) add('error', `unknown field "${part}"; fields are gate, serves, signers, count, runs, mode and files`);findings.push(...checkFieldFindings(row).map((message) => ({ level: 'error', line: row.line, id: row.id, message })));return findings;}/*** Problems with a row's check fields: a `gate: check` names its command and a whole-number count,- * `runs` is submit or nightly, `mode` is hold or watch, and none of them stands without a check.+ * `runs` is submit or nightly, `mode` is hold or watch, `files` names paths, and none of them+ * stands without a check.** @param {any} row* @returns {string[]}@@ -206,7 +209,7 @@ export function checkFieldFindings(row) {const isCheck = /^check(\s|$)/u.test(row.gate ?? '');const problems = [];if (!isCheck) {- if (['count', 'runs', 'mode'].some((key) => row[key] !== undefined)) problems.push('count, runs and mode belong to a row whose gate is check <command>');+ if (CHECK_FIELDS.some((key) => row[key] !== undefined)) problems.push('count, runs, mode and files belong to a row whose gate is check <command>');return problems;}if (!row.gate.slice('check'.length).trim()) problems.push('gate: check names the command that prints one line per problem');@@ -214,6 +217,7 @@ export function checkFieldFindings(row) {else if (!/^\d+$/u.test(row.count)) problems.push(`count "${row.count}" is a whole number`);if (row.runs !== undefined && !['submit', 'nightly'].includes(row.runs)) problems.push(`runs "${row.runs}" is submit or nightly`);if (row.mode !== undefined && !['hold', 'watch'].includes(row.mode)) problems.push(`mode "${row.mode}" is hold or watch`);+ if (row.files !== undefined && !row.files.trim()) problems.push('files names the repo paths the rule covers; leave it out to cover the whole repo');return problems;}diff --git a/test/doctrine-checks.test.js b/test/doctrine-checks.test.jsindex c6e38d07..6b41f445 100644--- a/test/doctrine-checks.test.js+++ b/test/doctrine-checks.test.js@@ -1,6 +1,6 @@/** A doctrine rule can carry a check whose count only falls, held at submit [D1,D3]. */import assert from 'node:assert/strict';-import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';+import { appendFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { join } from 'node:path';import { after, test } from 'node:test';import { createE2eHelpers } from './e2e-helpers.js';@@ -10,6 +10,8 @@ after(e2e.cleanup);const { project } = e2e;const RULE = '- Q1 [approved, must] Web pages carry no TODO markers. | gate: check grep -rn TODO web';+const NARROWED = '- Q3 [approved, must] Api work keeps the TODO count. | gate: check grep -rn TODO web | count: 2 | files: api';+const UNCOUNTABLE = '- Q4 [approved, must] The keep file stays. | gate: check test -f web/keep.txt || exit 3 | count: 0 | files: web/keep.txt';/*** A project whose doctrine has one check rule with the given trailing fields, two problems on@@ -20,6 +22,7 @@ function checkedProject(fields, extraRows = []) {appendFileSync(join(box.repo, 'DOCTRINE.md'), `\n## Q · Quality\n${[`${RULE} | ${fields}`, ...extraRows].join('\n')}\n`);mkdirSync(join(box.repo, 'web'));writeFileSync(join(box.repo, 'web', 'a.html'), 'TODO one\nTODO two\n');+ writeFileSync(join(box.repo, 'web', 'keep.txt'), 'keep\n');box.git(box.repo, 'add', '-A');box.git(box.repo, 'commit', '-q', '-m', 'chore: add the quality doctrine');box.git(box.web, 'merge', '-q', '--ff-only', 'main');@@ -47,11 +50,21 @@ function editRule(box, from, to) {}test("a doctrine rule's check holds its count [D1,D3]", () => {- const box = checkedProject('count: 2');+ const box = checkedProject('count: 2', [NARROWED, UNCOUNTABLE]);++ // A check that exits other than 0 or 1 cannot count, so it refuses by name.+ rmSync(join(box.web, 'web', 'keep.txt'));+ box.git(box.web, 'add', '-A');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): drop the keep file [G1]');+ const uncounted = box.run(box.web, 'submit', '1');+ assert.match(uncounted.err, /RATCHET_UNCOUNTED/);+ assert.match(uncounted.err, /Q4 The keep file stays\. cannot count: its check exited 3/);+ assert.equal(uncounted.code, 1, uncounted.out);// A rise above the committed count is refused, naming the rule, the counts and the new line.- commitWeb(box, { 'b.html': 'TODO three\n' }, 'feat(web): add a page [G1]');+ commitWeb(box, { 'b.html': 'TODO three\n', 'keep.txt': 'keep\n' }, 'feat(web): add a page [G1]');const rose = box.run(box.web, 'submit', '1');+ assert.doesNotMatch(rose.err, /Q3/, 'files: api keeps a web-only change from running the rule');assert.equal(rose.code, 1, rose.out);assert.match(rose.err, /RATCHET_ROSE/);assert.match(rose.err, /Q1 Web pages carry no TODO markers\. rose to 3, was 2/);@@ -73,10 +86,14 @@ test("a doctrine rule's check holds its count [D1,D3]", () => {assert.match(fell.out, /Q1 Web pages carry no TODO markers\. · 1, was 2 · holding/);const report = box.run(box.web, 'doctrine', 'check');assert.equal(report.code, 0, report.err);- assert.equal(report.out.trim(), 'Q1 Web pages carry no TODO markers. · 1, was 2 · holding');+ assert.equal(report.out.trim(), [+ 'Q1 Web pages carry no TODO markers. · 1, was 2 · holding',+ 'Q3 Api work keeps the TODO count. · 1, was 2 · holding',+ 'Q4 The keep file stays. · 0, was 0 · holding',+ ].join('\n'));const json = JSON.parse(box.run(box.web, 'doctrine', 'check', '--json').out);assert.deepEqual(json.rules.map(({ id, count, committed, holds }) => ({ id, count, committed, holds })),- [{ id: 'Q1', count: 1, committed: 2, holds: true }]);+ [{ id: 'Q1', count: 1, committed: 2, holds: true }, { id: 'Q3', count: 1, committed: 2, holds: true }, { id: 'Q4', count: 0, committed: 0, holds: true }]);assert.deepEqual(json.rules[0].problems, ['web/a.html:1:TODO two']);// Raising count: needs the person's signature; lowering it is a normal commit.