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.

feat(rigor): run the person's code and test quality rules [D1,D3]

Corey Olson0c44878d9e24
diff --git a/src/cli.js b/src/cli.js
index a3cf7436..f5cbf1f5 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -357,6 +357,11 @@ import {
conflictReport,
} from './rigor-conflicts.js';
import { draftConflictSplits } from './rigor-splits.js';
+import {
+ QUALITY_OPTIONS,
+ draftQualityRows,
+ rigorQualityCommand,
+} from './rigor-quality-draft.js';
import { nextReview } from './next-review.js';
import { serveApi } from './api.js';
import { watchCommand } from './watch.js';
@@ -636,6 +641,7 @@ const OPTIONS = {
as: { type: 'string' },
check: { type: 'string' },
...SENTINEL_OPTIONS,
+ ...QUALITY_OPTIONS,
yes: { type: 'boolean' },
landing: { type: 'boolean' },
adopt: { type: 'boolean' },
@@ -2663,15 +2669,18 @@ function readCommands(io, { first, second, rest, values }) {
return 0;
},
rigor: async () => {
- if (values['draft-splits'] && first) throw new Refused('USAGE', 'use pullboard rigor --draft-splits without a proof-bound draft subcommand');
+ if ((values['draft-splits'] || values['draft-quality']) && first) throw new Refused('USAGE', 'use pullboard rigor --draft-splits or --draft-quality without a subcommand');
+ if (first === 'quality') { if (second || rest.length) throw new Refused('USAGE', 'pullboard rigor quality [--base <commit>] [--rule <key>] [--budget <lines>]'); const ctx = context(io); return rigorQualityCommand(io, { values }, { root: ctx.info.root, config: ctx.config }); }
if (first === 'draft') { const ctx = context(io); return rigorDraftCommand(io, { second, rest, values }, { root: ctx.info.root, config: ctx.config, read: () => withBoard(ctx, (board) => ({ events: store.events(board), actor: whoAmI(ctx, board).id })), reserve: (row) => reserveRow(ctx, row, true), propose: (row, evidence) => withBoard(ctx, async (board) => ordered(ctx, board, 'proposeSentinel', [{ agentId: whoAmI(ctx, board).id, row, evidence }])) }); }
if (first || second || rest.length) throw new Refused('USAGE', 'pullboard rigor takes no arguments; to draft a rule: pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit>');
const ctx = context(io);
const report = withBoard(ctx, (board) => { const history = store.events(board); return { ...rigorReport(history, { person: store.PERSON }), ...conflictReport(history) }; });
if (values['draft-splits']) report.splitDrafts = await draftConflictSplits(ctx, report, { read: () => withBoard(ctx, (board) => ({ coordinator: whoAmI(ctx, board).id === COORDINATOR, rows: store.rowDrafts(board), decisions: store.rowDecisions(board) })), reserve: row => reserveRow(ctx, row, true) });
+ if (values['draft-quality']) report.qualityDrafts = await draftQualityRows(ctx, { read: () => withBoard(ctx, (board) => ({ coordinator: whoAmI(ctx, board).id === COORDINATOR, rows: store.rowDrafts(board), decisions: store.rowDecisions(board) })), reserve: row => reserveRow(ctx, row, true) });
io.result?.(report);
for (const line of [...rigorLines(report), ...conflictLines(report)]) io.say(line);
for (const draft of report.splitDrafts ?? []) io.say(`${draft.id}: draft split proposal; person approval required`);
+ for (const draft of report.qualityDrafts ?? []) io.say(`${draft.id}: draft quality rule, switched off until the person approves it`);
return 0;
},
log: () => {
diff --git a/src/help.js b/src/help.js
index 33979cc4..38e40b36 100644
--- a/src/help.js
+++ b/src/help.js
@@ -194,6 +194,10 @@ Receipts
pullboard rigor failure causes that repeated: on 2 items, or 1 item at 2 commits;
each with its items and whether it reads as work, product or both
pullboard rigor --draft-splits coordinator on main: draft review-gated split proposals for files colliding on 2 items in 14 days; only the person approves
+ pullboard rigor quality [--base <commit>] [--head <commit>] [--rule <key>] [--budget <lines>]
+ the person's quality rules broken by this change since main, as path:line: rule: what broke
+ rules: fix-test, fails-closed, silent-catch, guard-mutation, size-budget, root-cause-control
+ pullboard rigor --draft-quality coordinator on main: draft each quality rule as a Doctrine row with its check; only the person approves
pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit> [--section <letter>]
--red is a noticed failure commit; prove its check red, then green at --green
draft Doctrine (work), spec (product) or both; only the person approves
@@ -271,7 +275,7 @@ const HELP_EXAMPLES = {
status: 'pullboard status', view: 'pullboard view', digest: 'pullboard digest --out briefing.md', mcp: 'pullboard mcp', stats: 'pullboard stats --since 2026-10-08', log: 'pullboard log 12', ledger: 'pullboard ledger',
relay: 'pullboard relay on --all', 'relay recover': 'pullboard relay recover --skip 12',
'lane add': 'pullboard lane add web --owns apps/web/', lane: 'pullboard lane add web --owns apps/web/',
- queue: 'pullboard queue', roadmap: 'pullboard roadmap', rigor: 'pullboard rigor', 'rigor draft': 'pullboard rigor draft "refusal:MERGE_LOST" "Merges keep every hunk" --check "node bin/checks/merges.js" --red 0123456 --green 89abcde', milestone: 'pullboard milestone add "0.7.0" --items 12,13',
+ queue: 'pullboard queue', roadmap: 'pullboard roadmap', rigor: 'pullboard rigor', 'rigor quality': 'pullboard rigor quality --rule silent-catch', 'rigor draft': 'pullboard rigor draft "refusal:MERGE_LOST" "Merges keep every hunk" --check "node bin/checks/merges.js" --red 0123456 --green 89abcde', milestone: 'pullboard milestone add "0.7.0" --items 12,13',
'milestone order': 'pullboard milestone order "0.7.0" 13,12',
runner: 'pullboard runner add studio --slots 2 --browser 1', 'runner add': 'pullboard runner add studio --slots 2 --browser 1',
edit: 'pullboard edit 12 --brief "Add the upload page"', release: 'pullboard release 12',
diff --git a/src/next-steps.js b/src/next-steps.js
index 71bad03b..ee244b63 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -364,6 +364,8 @@ export const NEXT_STEPS = Object.freeze({
NOT_VERIFIED: 'merge only verified items; see pullboard list --all',
NOT_YOURS: 'shout its holder or the coordinator: pullboard shout coordinator "<what you need>"',
NOT_YOUR_CHECKOUT: 'make an independent checkout with git worktree add -b <lane>/<n> ../<repo>-<lane>-<n>, then run pullboard join <lane> --model "<model name>" there; the same agent in a new session should run pullboard takeover from its own shell',
+ RIGOR_RANGE: 'pass --base the commit or branch this change grew from: pullboard rigor quality --base main',
+ RIGOR_RULE: 'name a rule pullboard help rigor lists: pullboard rigor quality --rule silent-catch',
RIGOR_UNNOTICED: 'run pullboard rigor and draft a cause it lists, or wait until the cause repeats',
RIGOR_UNPROVEN: 'name a check that fails at --red and passes at --green: pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit>',
RIGOR_PERSON_ONLY: 'ask the person to mark it from the main checkout: pullboard fact <id> root-cause "<why>" --cause <key> --never-again --as person',
diff --git a/src/rigor-quality-draft.js b/src/rigor-quality-draft.js
new file mode 100644
index 00000000..24cf59e0
--- /dev/null
+++ b/src/rigor-quality-draft.js
@@ -0,0 +1,120 @@
+/**
+ * `pullboard rigor quality` and `pullboard rigor --draft-quality` [D1,D3]. The first reports the
+ * person's quality rules broken by one change, each with its file, line and rule. The second
+ * drafts each rule as a Doctrine row through the ordinary draft writer: a draft with a check and
+ * a count of 0, never approved here, so nothing is switched on until the person approves it.
+ */
+import { existsSync } from 'node:fs';
+import { join } from 'node:path';
+import { loadDoctrine } from './doctrine.js';
+import { Refused } from './refused.js';
+import {
+ GROWTH_BUDGET,
+ QUALITY_RULES,
+ breachLine,
+ changeRange,
+ qualityBreaches,
+} from './rigor-quality.js';
+import { draftRow } from './spec-draft.js';
+
+/** The flags these commands add to the CLI's option table. */
+export const QUALITY_OPTIONS = {
+ base: { type: 'string' },
+ head: { type: 'string' },
+ rule: { type: 'string' },
+ budget: { type: 'string' },
+ 'draft-quality': { type: 'boolean' },
+};
+
+/** The source a drafted quality row carries, so a rerun finds it whatever the person decided. */
+export function qualitySource(key) {
+ return `rigor-quality:${key}`;
+}
+
+/**
+ * The doctrine row id for each quality rule the repo's doctrine carries, by rule key.
+ *
+ * @param {string} root
+ * @param {any} config
+ * @returns {Map<string, string>}
+ */
+export function qualityRows(root, config) {
+ const rows = new Map();
+ for (const row of loadDoctrine(root, config).repo.rows) {
+ const key = /^rigor-quality:([a-z-]+)$/u.exec(row.source ?? '')?.[1];
+ if (key && !rows.has(key)) rows.set(key, row.id);
+ }
+ return rows;
+}
+
+/**
+ * The command a drafted row's check runs. Why two forms: this repo's hooks run the source in the
+ * checkout, while any other repo runs the installed pullboard.
+ *
+ * @param {string} root
+ * @param {string} key
+ * @returns {string}
+ */
+export function qualityCommand(root, key) {
+ const bin = existsSync(join(root, 'bin/pullboard.js')) && existsSync(join(root, 'src/rigor-quality.js')) ? 'node bin/pullboard.js' : 'pullboard';
+ return `${bin} rigor quality --rule ${key}`;
+}
+
+/**
+ * pullboard rigor quality: print each breach as `path:line: [row] rule: what broke` and exit 1
+ * with any, 0 with none, so a doctrine row's check counts it.
+ *
+ * @param {any} io
+ * @param {{ values: any }} args
+ * @param {{ root: string, config: any }} ctx
+ * @returns {number}
+ */
+export function rigorQualityCommand(io, { values }, { root, config }) {
+ const rules = values.rule ? String(values.rule).split(',').map((key) => key.trim()).filter(Boolean) : undefined;
+ const budget = values.budget === undefined ? GROWTH_BUDGET : Number(values.budget);
+ if (!Number.isSafeInteger(budget) || budget < 0) throw new Refused('USAGE', `--budget takes a whole number of lines, such as ${GROWTH_BUDGET}`);
+ const range = changeRange(root, { base: values.base, head: values.head });
+ const breaches = qualityBreaches(root, range, { rules, budget });
+ const rows = qualityRows(root, config);
+ io.result?.({ base: range.base, head: range.head, breaches: breaches.map((breach) => ({ ...breach, row: rows.get(breach.rule) ?? null })) });
+ for (const breach of breaches) io.say(breachLine(breach, rows));
+ return breaches.length ? 1 : 0;
+}
+
+/**
+ * Draft each quality rule the doctrine does not carry yet as a pending Doctrine row. Each id is
+ * reserved on the board first (#878); a reservation whose row never reached the file is finished
+ * at its id, unless the person already decided it. Coordinator only, from the main checkout,
+ * because the doctrine file is the coordinator's to write.
+ *
+ * @param {{ info: { root: string, isMain: boolean }, config: any }} ctx
+ * @param {{ read: () => { coordinator: boolean, rows: any[], decisions?: any[] }, reserve: (row: any) => Promise<{ id: string }> }} deps
+ * @returns {Promise<{ id: string, file: string, line: string, row: any }[]>}
+ */
+export async function draftQualityRows(ctx, { read, reserve }) {
+ const state = read();
+ if (!ctx.info.isMain || !state.coordinator) throw new Refused('COORDINATOR_ONLY', 'only the coordinator drafts the quality rules; ask your coordinator to run pullboard rigor --draft-quality from the main checkout');
+ const { root } = ctx.info;
+ const drafts = [];
+ for (const rule of QUALITY_RULES) {
+ const doctrine = loadDoctrine(root, ctx.config);
+ if (doctrine.repo.rows.some((row) => row.source === qualitySource(rule.key))) continue;
+ const sections = doctrine.repo.sections.map((section) => /^([A-Z][A-Z0-9]*)\s*[·.:-]/u.exec(section.name)?.[1]).filter(Boolean);
+ const request = { target: 'doctrine', text: `${rule.text} ${rule.how}`, gate: `check ${qualityCommand(root, rule.key)}`,
+ fields: ['count: 0', `source: ${qualitySource(rule.key)}`], section: sections.includes(rule.section) ? rule.section : undefined };
+ const pending = state.rows.find((row) => row.written && row.target === 'doctrine' && row.text === request.text
+ && !doctrine.repo.rows.some((existing) => existing.id === row.id));
+ if (pending && (state.decisions ?? []).some((decision) => decision.kind === 'doctrine' && decision.id === pending.id)) {
+ throw new Refused('STALE_ROW_DECISION', `${pending.id} has a person decision but its doctrine row is missing; a quality draft cannot recreate it`, 'ask the coordinator to restore the decided doctrine row and run pullboard spec apply before retrying');
+ }
+ if (pending) {
+ drafts.push(draftRow(root, ctx.config, { ...request, id: pending.id }));
+ continue;
+ }
+ const planned = draftRow(root, ctx.config, { ...request, taken: state.rows.map((row) => row.id), write: false });
+ const entry = await reserve({ ...planned.row, target: 'doctrine' });
+ drafts.push(draftRow(root, ctx.config, { ...request, id: entry.id }));
+ state.rows.push({ ...planned.row, id: entry.id, target: 'doctrine', written: true });
+ }
+ return drafts;
+}
diff --git a/src/rigor-quality.js b/src/rigor-quality.js
new file mode 100644
index 00000000..b7ad5b6b
--- /dev/null
+++ b/src/rigor-quality.js
@@ -0,0 +1,393 @@
+/**
+ * The person's code and test quality rules as checks Rigor runs by itself [D1,D3]. Each rule reads
+ * one change, from the merge base with main to HEAD, and names every breach as
+ * `path:line: <rule> <what broke>`, the same shape bin/checks prints, so a doctrine row's
+ * `gate: check` can count it. Why a change and not the whole tree: these rules judge how a change
+ * was made (a fix and its test, a new guard and the test that catches its loss), which only a
+ * diff can show, and an old file never breaks a rule its author never saw.
+ *
+ * Nothing here drafts or approves a row; rigor-quality-draft.js drafts them for the person.
+ */
+import { spawnSync } from 'node:child_process';
+import {
+ mkdirSync,
+ mkdtempSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import {
+ dirname,
+ join,
+} from 'node:path';
+import {
+ lex,
+ lineAt,
+} from '../bin/checks/scan.js';
+import {
+ cleanGitEnvironment,
+ mainCheckout,
+} from './git.js';
+import { Refused } from './refused.js';
+
+/** The line cap a changed file is held to, as Doctrine C9 holds it. */
+export const LINE_CAP = 1500;
+
+/** How many lines of non-test code one change may add, net, before Rigor names it. */
+export const GROWTH_BUDGET = 400;
+
+/** How long one test run inside a mutation or control may take. */
+const TEST_TIMEOUT_MS = 5 * 60 * 1000;
+
+/**
+ * The rules, in the order Rigor reports and drafts them. `text` is the rule; `how` says plainly
+ * what the check reads and what it leaves to review, so the person approves exactly what runs.
+ * Neither may hold a field separator, since each becomes one doctrine row.
+ */
+export const QUALITY_RULES = Object.freeze([
+ { key: 'fix-test', section: 'T', text: 'A fix ships with a test that reproduces the original failure.',
+ how: 'Rigor names each fix commit that changes no test file, at the first line it changes; whether the test reproduces the failure is the root-cause-control rule.' },
+ { key: 'fails-closed', section: 'T', text: 'A new gate or check has a test that fails closed when it has no data.',
+ how: 'Rigor names a new file under checks/ or gates/, or named *-check or *-gate, that no test changed in the same change names; whether that test feeds it no data and expects a refusal is review, since no command can read what a test asserts.' },
+ { key: 'silent-catch', section: 'C', text: 'No silent catch or fallback: each one logs a specific line that names its subject.',
+ how: 'Rigor names each catch clause and .catch handler a change adds to a source file that neither throws nor writes a line; a fallback written with a default operator is review.' },
+ { key: 'guard-mutation', section: 'T', text: 'A guard test fails when the guard is deleted.',
+ how: 'Rigor turns each throw a change adds to a source file into a no-op, one at a time, and runs the test files the change touches; a guard they still pass without is named.' },
+ { key: 'size-budget', section: 'C', text: `A file over the ${LINE_CAP}-line cap, or a change that grows code past its ${GROWTH_BUDGET}-line budget, is named.`,
+ how: `Rigor names each changed source file that ends over ${LINE_CAP} lines and grew, and a change whose non-test code grows by more than ${GROWTH_BUDGET} lines net, at the file that grew most.` },
+ { key: 'root-cause-control', section: 'T', text: 'A root cause is proven by a control that would have come out differently before the fix lands.',
+ how: 'Rigor runs each fix commit\'s changed test files on the fix\'s parent, where they must fail, and at the fix, where they must pass; a cause argued only in prose is review.' },
+]);
+
+/** A test file in any common layout: a test folder, or a name that says test or spec. */
+const TEST_FILE = /(?:^|\/)(?:test|tests|__tests__)\/|\.(?:test|spec)\.[cm]?[jt]sx?$|(?:^|\/)test_[^/]+\.py$|_test\.(?:go|py)$/u;
+
+/** A JavaScript source file, the only kind the catch and guard rules can lex. */
+const SCRIPT = /\.[cm]?js$/u;
+
+/** A file the size rule counts, as bin/checks/file-size.js does. */
+const SIZED = /\.(?:[cm]?js|css)$/u;
+
+/** A new gate or check, by folder or by name. */
+const CHECK_FILE = /(?:^|\/)(?:checks|gates)\/[^/]+\.[cm]?js$|[-_.](?:check|gate)s?\.[cm]?js$/u;
+
+/** A fix commit, by its conventional header type. */
+const FIX = /^fix(?:\([^)]*\))?!?:/u;
+
+/** A call that writes a line somewhere a person or a log reads it. */
+const LOGS = /\b(?:console\s*\.\s*(?:log|warn|error|info|debug)|std(?:err|out)\s*\.\s*write|(?:io|logger|log)\s*\.\s*\w+|say|warn\w*|log\w*|report\w*|reject)\s*\(/u;
+
+/** Run git without the caller's repository selectors; null when git refuses. */
+function gitOut(cwd, args) {
+ const result = spawnSync('git', ['--no-replace-objects', '-c', 'core.quotepath=false', ...args],
+ { cwd, env: cleanGitEnvironment(), encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
+ return result.status === 0 ? result.stdout : null;
+}
+
+/** One commit id for a revision, or null when it names none. */
+function commitOf(root, revision) {
+ return gitOut(root, ['rev-parse', '--verify', '--quiet', `${revision}^{commit}`])?.trim() || null;
+}
+
+/**
+ * The change Rigor reads: from the merge base of `base` and `head` to `head`. Without `base`, the
+ * first of the main checkout's branch, main, origin/main and master that `head` has grown past;
+ * with none of them, the range is empty, so a repository with no main has nothing to judge
+ * rather than everything.
+ *
+ * @param {string} root
+ * @param {{ base?: string, head?: string }} [range]
+ * @returns {{ base: string, head: string }}
+ */
+export function changeRange(root, { base, head = 'HEAD' } = {}) {
+ const tip = commitOf(root, head);
+ if (!tip) throw new Refused('RIGOR_RANGE', `${head} names no commit; pass --head a commit or branch, or commit first`);
+ if (base !== undefined) {
+ const given = commitOf(root, base);
+ const merged = given && gitOut(root, ['merge-base', given, tip])?.trim();
+ if (!merged) throw new Refused('RIGOR_RANGE', `${base} shares no history with ${head}; pass --base a commit or branch that ${head} grew from`);
+ return { base: merged, head: tip };
+ }
+ const branch = mainCheckout(root)?.branch;
+ for (const candidate of [branch, 'main', 'origin/main', 'master'].filter(Boolean)) {
+ const found = commitOf(root, candidate);
+ const merged = found && gitOut(root, ['merge-base', found, tip])?.trim();
+ // A candidate that already holds HEAD (the branch HEAD is on, in a one-checkout repo) says nothing.
+ if (merged && merged !== tip) return { base: merged, head: tip };
+ }
+ return { base: tip, head: tip };
+}
+
+/**
+ * Parse a zero-context diff into each file's status and added lines, numbered at the new side.
+ * Why not `+++` alone: with -U0 a removed line `-- x` prints as `--- x`, so headers are read
+ * only between `diff --git` and the first hunk.
+ *
+ * @param {string} text
+ * @returns {Map<string, { status: 'A' | 'M' | 'D', added: { line: number, text: string }[] }>}
+ */
+export function parseDiff(text) {
+ const files = new Map();
+ let current = null;
+ let header = false;
+ let status = 'M';
+ let next = 0;
+ for (const line of text.split('\n')) {
+ if (line.startsWith('diff --git ')) { header = true; current = null; status = 'M'; continue; }
+ if (header) {
+ if (line.startsWith('new file mode')) status = 'A';
+ else if (line.startsWith('deleted file mode')) status = 'D';
+ else if (line.startsWith('+++ ')) {
+ const name = line.slice(4);
+ current = name === '/dev/null' ? null : name.replace(/^b\//u, '');
+ if (current) files.set(current, { status, added: [] });
+ } else if (line.startsWith('--- ') && status === 'D') {
+ const name = line.slice(4).replace(/^a\//u, '');
+ files.set(name, { status, added: [] });
+ }
+ if (!line.startsWith('@@')) continue;
+ header = false;
+ }
+ const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/u.exec(line);
+ if (hunk) { next = Number(hunk[1]); continue; }
+ if (current && line.startsWith('+')) {
+ files.get(current).added.push({ line: next, text: line.slice(1) });
+ next += 1;
+ }
+ }
+ return files;
+}
+
+/** The diff from one commit to another, or of one commit against its parent. */
+function diffOf(root, from, to) {
+ const args = from ? ['diff', '-U0', '--no-renames', '--no-color', '--no-ext-diff', from, to, '--']
+ : ['diff-tree', '-p', '-r', '-U0', '--root', '--no-renames', '--no-color', '--no-ext-diff', to, '--'];
+ return parseDiff(gitOut(root, args) ?? '');
+}
+
+/** A file's text at a commit, or null when the commit lacks it. */
+function textAt(root, commit, path) {
+ return gitOut(root, ['show', `${commit}:${path}`]);
+}
+
+/** Lines as an editor numbers them. */
+function lineCount(text) {
+ if (!text) return 0;
+ const newlines = text.split('\n').length - 1;
+ return text.endsWith('\n') ? newlines : newlines + 1;
+}
+
+/** The fix commits in a range, oldest first, with their subjects. */
+function fixCommits(root, { base, head }) {
+ if (base === head) return [];
+ return (gitOut(root, ['log', '--no-merges', '--reverse', '--format=%H%x00%s', `${base}..${head}`]) ?? '')
+ .split('\n').filter(Boolean).map((line) => line.split('\0')).filter(([, subject]) => FIX.test(subject))
+ .map(([commit, subject]) => ({ commit, subject, parent: commitOf(root, `${commit}^`) }));
+}
+
+/** The test files a diff adds lines to and keeps. */
+function changedTests(diff) {
+ return [...diff].filter(([path, file]) => TEST_FILE.test(path) && file.status !== 'D' && file.added.length).map(([path]) => path);
+}
+
+/** Where a change starts: its first non-test file's first added line, else its first file. */
+function firstChange(diff) {
+ const entries = [...diff];
+ const [path, file] = entries.find(([name, entry]) => !TEST_FILE.test(name) && entry.added.length) ?? entries[0] ?? ['(no file)', { added: [] }];
+ return { path, line: file.added[0]?.line ?? 1 };
+}
+
+/** The catch clauses and .catch handlers in a source, each with its offset and body. */
+function catches(source) {
+ const { code } = lex(source);
+ const found = [];
+ for (const match of code.matchAll(/(?<![\w$.])catch\s*(?:\([^()]*\)\s*)?\{/gu)) {
+ const open = match.index + match[0].length - 1;
+ found.push({ at: match.index, kind: 'clause', body: code.slice(open + 1, closing(code, open, '{', '}')) });
+ }
+ for (const match of code.matchAll(/\.\s*catch\s*\(/gu)) {
+ const open = match.index + match[0].length - 1;
+ found.push({ at: match.index + match[0].indexOf('catch'), kind: 'handler', body: code.slice(open + 1, closing(code, open, '(', ')')) });
+ }
+ return found;
+}
+
+/** The offset of the bracket that closes the one at `open`, or the end of the code. */
+function closing(code, open, left, right) {
+ let depth = 0;
+ for (let at = open; at < code.length; at += 1) {
+ if (code[at] === left) depth += 1;
+ else if (code[at] === right && --depth === 0) return at;
+ }
+ return code.length;
+}
+
+/** Every rule's breaches for one change; each check is below, one function per rule. */
+const CHECKS = {
+ /** A fix commit that changes no test file. */
+ 'fix-test': (root, range) => fixCommits(root, range).flatMap((fix) => {
+ const diff = diffOf(root, fix.parent, fix.commit);
+ if (changedTests(diff).length) return [];
+ return [{ ...firstChange(diff), text: `fix ${fix.commit.slice(0, 12)} "${fix.subject}" changes no test that reproduces its failure` }];
+ }),
+ /** A new gate or check no test in the change names. */
+ 'fails-closed': (root, range, { diff }) => {
+ const tests = changedTests(diff).map((path) => textAt(root, range.head, path) ?? '');
+ return [...diff].filter(([path, file]) => file.status === 'A' && CHECK_FILE.test(path) && !TEST_FILE.test(path))
+ .filter(([path]) => !tests.some((text) => text.includes(path.split('/').pop().replace(/\.[cm]?js$/u, ''))))
+ .map(([path]) => ({ path, line: 1, text: 'is a new gate or check, and no test in this change runs it with no data to show it fails closed' }));
+ },
+ /** A catch the change adds that neither throws nor writes a line. */
+ 'silent-catch': (root, range, { diff }) => [...diff].filter(([path, file]) => SCRIPT.test(path) && !TEST_FILE.test(path) && file.added.length)
+ .flatMap(([path, file]) => {
+ const source = textAt(root, range.head, path) ?? '';
+ const added = new Set(file.added.map((entry) => entry.line));
+ return catches(source).map((found) => ({ ...found, line: lineAt(source, found.at) }))
+ .filter((found) => added.has(found.line) && !/\bthrow\b/u.test(found.body) && !LOGS.test(found.body))
+ .map((found) => ({ path, line: found.line, text: `${found.kind === 'clause' ? 'catch' : '.catch handler'} is silent: it neither throws nor logs a line that names its subject` }));
+ }),
+ /** A throw the change adds that its tests still pass without. */
+ 'guard-mutation': (root, range, { diff, runTests }) => guardBreaches(root, range, diff, runTests),
+ /** A grown file over the cap, and a change past its budget. */
+ 'size-budget': (root, range, { diff, budget }) => {
+ const breaches = [];
+ const growth = [];
+ for (const [path, file] of diff) {
+ if (!SIZED.test(path) || file.status === 'D') continue;
+ const after = lineCount(textAt(root, range.head, path));
+ const grew = after - lineCount(textAt(root, range.base, path));
+ if (after > LINE_CAP && grew > 0) breaches.push({ path, line: LINE_CAP + 1, text: `is ${after} lines, over the ${LINE_CAP}-line cap, and this change grows it by ${grew}; split it into a new module` });
+ if (!TEST_FILE.test(path)) growth.push({ path, grew, line: file.added[0]?.line ?? 1 });
+ }
+ const total = growth.reduce((sum, entry) => sum + entry.grew, 0);
+ if (total > budget) {
+ const most = growth.reduce((top, entry) => (entry.grew > top.grew ? entry : top));
+ breaches.push({ path: most.path, line: most.line, text: `this change grows code by ${total} lines, past its ${budget}-line budget; split the change` });
+ }
+ return breaches;
+ },
+ /** A fix whose tests pass on its parent too, or fail at the fix. */
+ 'root-cause-control': (root, range, { runTests }) => fixCommits(root, range).flatMap((fix) => controlBreaches(root, fix, runTests)),
+};
+
+/**
+ * Run the given test files in a checkout and say whether they passed. The child loses the parent
+ * test runner's context, or a `node --test` inside a test would report into its parent.
+ *
+ * @param {string} cwd
+ * @param {string[]} files
+ * @returns {boolean}
+ */
+export function nodeTests(cwd, files) {
+ const env = cleanGitEnvironment();
+ delete env.NODE_TEST_CONTEXT;
+ const result = spawnSync(process.execPath, ['--test', ...files], { cwd, env, encoding: 'utf8', timeout: TEST_TIMEOUT_MS, killSignal: 'SIGKILL', maxBuffer: 64 * 1024 * 1024 });
+ return result.status === 0;
+}
+
+/** A private shared clone, checked out at `commit` with hooks off; `move` checks out another. */
+function scratchClone(root, commit) {
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-rigor-quality-'));
+ const checkout = join(directory, 'checkout');
+ const env = cleanGitEnvironment();
+ /** Check out a commit exactly, dropping anything a run wrote. */
+ const move = (target) => {
+ spawnSync('git', ['clean', '-fdxq'], { cwd: checkout, env });
+ const moved = spawnSync('git', ['-c', 'core.hooksPath=/dev/null', 'checkout', '--quiet', '--force', '--detach', target], { cwd: checkout, env });
+ if (moved.status !== 0) throw new Refused('RIGOR_RANGE', `could not check out ${target} to run its tests; fetch it, or pass --base a commit this checkout has`);
+ };
+ const cloned = spawnSync('git', ['clone', '--quiet', '--shared', '--no-checkout', '--', root, checkout], { env, stdio: 'ignore' });
+ if (cloned.status !== 0) {
+ rmSync(directory, { recursive: true, force: true });
+ throw new Refused('RIGOR_RANGE', 'could not clone this repository to run its tests; check that git can read it, then run pullboard rigor quality again');
+ }
+ move(commit);
+ return { checkout, move, remove: () => rmSync(directory, { recursive: true, force: true }) };
+}
+
+/**
+ * The guard rule: each throw a change adds to a source file becomes `void`, one at a time, and the
+ * change's tests run against that copy. Why `void`: it keeps the statement valid, so a test fails
+ * only because the guard is gone, never because the file no longer parses.
+ */
+function guardBreaches(root, range, diff, runTests) {
+ const guards = [];
+ for (const [path, file] of diff) {
+ if (!SCRIPT.test(path) || TEST_FILE.test(path) || !file.added.length) continue;
+ const source = textAt(root, range.head, path) ?? '';
+ const added = new Set(file.added.map((entry) => entry.line));
+ for (const match of lex(source).code.matchAll(/\bthrow\b/gu)) {
+ if (added.has(lineAt(source, match.index))) guards.push({ path, at: match.index, line: lineAt(source, match.index), source });
+ }
+ }
+ if (!guards.length) return [];
+ const tests = changedTests(diff);
+ /** Name one guard with what is wrong with it. */
+ const breach = (guard, text) => ({ path: guard.path, line: guard.line, text });
+ if (!tests.length) return guards.map((guard) => breach(guard, 'adds a guard, and this change touches no test that could fail without it'));
+ const clone = scratchClone(root, range.head);
+ try {
+ if (!runTests(clone.checkout, tests)) return guards.map((guard) => breach(guard, `adds a guard whose tests fail at ${range.head.slice(0, 12)} even with it, so its loss proves nothing`));
+ return guards.filter((guard) => {
+ writeFileSync(join(clone.checkout, guard.path), `${guard.source.slice(0, guard.at)}void ${guard.source.slice(guard.at + 'throw'.length)}`);
+ const survived = runTests(clone.checkout, tests);
+ writeFileSync(join(clone.checkout, guard.path), guard.source);
+ return survived;
+ }).map((guard) => breach(guard, `adds a guard the change's tests still pass without: ${tests.join(', ')}`));
+ } finally { clone.remove(); }
+}
+
+/**
+ * The control rule for one fix: its test files, as the fix wrote them, must fail on its parent's
+ * code and pass at the fix. A test that passes on both shows nothing about the cause.
+ */
+function controlBreaches(root, fix, runTests) {
+ const diff = diffOf(root, fix.parent, fix.commit);
+ const tests = changedTests(diff);
+ if (!tests.length) return [{ ...firstChange(diff), text: `fix ${fix.commit.slice(0, 12)} has no control: it changes no test to run before and after it` }];
+ const at = { path: tests[0], line: diff.get(tests[0]).added[0].line };
+ if (!fix.parent) return [{ ...at, text: `fix ${fix.commit.slice(0, 12)} has no parent to run its control on` }];
+ const clone = scratchClone(root, fix.parent);
+ try {
+ for (const path of tests) {
+ mkdirSync(dirname(join(clone.checkout, path)), { recursive: true });
+ writeFileSync(join(clone.checkout, path), textAt(root, fix.commit, path) ?? '');
+ }
+ const before = runTests(clone.checkout, tests);
+ clone.move(fix.commit);
+ const after = runTests(clone.checkout, tests);
+ if (before) return [{ ...at, text: `fix ${fix.commit.slice(0, 12)}'s tests pass on its parent too, so they prove no root cause` }];
+ if (!after) return [{ ...at, text: `fix ${fix.commit.slice(0, 12)}'s tests fail at the fix itself` }];
+ return [];
+ } finally { clone.remove(); }
+}
+
+/**
+ * Every breach of the chosen rules in one change, sorted by path, line and rule.
+ *
+ * @param {string} root
+ * @param {{ base: string, head: string }} range - from changeRange
+ * @param {{ rules?: string[], budget?: number, runTests?: (cwd: string, files: string[]) => boolean }} [options]
+ * @returns {{ rule: string, path: string, line: number, text: string }[]}
+ */
+export function qualityBreaches(root, range, { rules = QUALITY_RULES.map((rule) => rule.key), budget = GROWTH_BUDGET, runTests = nodeTests } = {}) {
+ const unknown = rules.filter((key) => !CHECKS[key]);
+ if (unknown.length) throw new Refused('RIGOR_RULE', `no quality rule named ${unknown.join(', ')}; use one of ${QUALITY_RULES.map((rule) => rule.key).join(', ')}`);
+ const diff = range.base === range.head ? new Map() : diffOf(root, range.base, range.head);
+ const order = (rule) => QUALITY_RULES.findIndex((entry) => entry.key === rule);
+ return rules.flatMap((rule) => CHECKS[rule](root, range, { diff, budget, runTests }).map((breach) => ({ rule, ...breach })))
+ .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0) || a.line - b.line || order(a.rule) - order(b.rule));
+}
+
+/**
+ * One breach as a problem line: its file and line, then the doctrine row that carries its rule
+ * when the person has one, then the rule's key and what broke.
+ *
+ * @param {{ rule: string, path: string, line: number, text: string }} breach
+ * @param {Map<string, string>} [rows] - rule key to doctrine row id
+ * @returns {string}
+ */
+export function breachLine(breach, rows = new Map()) {
+ const row = rows.get(breach.rule);
+ return `${breach.path}:${breach.line}: ${row ? `${row} ` : ''}${breach.rule}: ${breach.text}`;
+}
diff --git a/test/rigor-checks.test.js b/test/rigor-checks.test.js
index e91cf67e..ab0804bf 100644
--- a/test/rigor-checks.test.js
+++ b/test/rigor-checks.test.js
@@ -27,6 +27,11 @@ import { draftConflictSplits } from '../src/rigor-splits.js';
import { proposeDoctrine } from '../src/doctrine-rulings.js';
import { conflictNote } from '../src/trunk-conflict.js';
import { conflictNoteFiles, conflictReport } from '../src/rigor-conflicts.js';
+import {
+ breachLine,
+ changeRange,
+ qualityBreaches,
+} from '../src/rigor-quality.js';
const conflictE2e = createE2eHelpers();
after(conflictE2e.cleanup);
@@ -482,3 +487,74 @@ test('concurrent split proposals keep one reserved row [D1]', async () => {
assert.equal(readFileSync(doctrine.repo.file, 'utf8'), before, 'a fixed-id retry cannot overwrite a different judgment');
} finally { store.closeBoard(board); }
});
+
+
+/**
+ * A real git repo on main with `files` committed, then a work branch, for the quality rules [D1,D3].
+ * commit(subject, files) writes and commits on the branch and returns the commit id.
+ */
+function qualityRepo(name, files) {
+ const root = fixture(name);
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_')));
+ /** Git in the fixture, with a fixed identity and no hooks. */
+ const run = (...args) => {
+ const result = spawnSync('git', ['-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'core.hooksPath=/dev/null', ...args], { cwd: root, env, encoding: 'utf8' });
+ assert.equal(result.status, 0, `git ${args.join(' ')}: ${result.stderr}`);
+ return result.stdout.trim();
+ };
+ /** Write files and commit them with this subject. */
+ const commit = (subject, changes) => {
+ for (const [path, text] of Object.entries(changes)) put(root, path, text);
+ run('add', '-A');
+ run('commit', '-q', '-m', subject);
+ return run('rev-parse', 'HEAD');
+ };
+ run('init', '-q', '-b', 'main');
+ commit('feat: start', files);
+ run('checkout', '-q', '-b', 'work');
+ return { root, commit };
+}
+
+test('rigor reports a fix with no reproducing test [D1,D3]', () => {
+ const start = { 'src/parse.js': 'export function parse(text) {\n return text.split(\',\');\n}\n',
+ 'test/parse.test.js': 'import { test } from \'node:test\';\ntest(\'parses [G1]\', () => {});\n' };
+ const bare = qualityRepo('quality-fix-bare', start);
+ bare.commit('feat(parse): count fields', { 'src/count.js': 'export const count = (text) => text.length;\n' });
+ const fix = bare.commit('fix(parse): ignore empty input', { 'src/parse.js': 'export function parse(text) {\n if (!text) return [];\n return text.split(\',\');\n}\n' });
+ const breaches = qualityBreaches(bare.root, changeRange(bare.root), { rules: ['fix-test'] });
+ assert.deepEqual(breaches.map((breach) => breachLine(breach)),
+ [`src/parse.js:2: fix-test: fix ${fix.slice(0, 12)} "fix(parse): ignore empty input" changes no test that reproduces its failure`],
+ 'the fix is named at its file and first changed line with the rule it breaks; a feature commit with no test is not a fix');
+ assert.deepEqual(breachLine(breaches[0], new Map([['fix-test', 'T7']])).split(': ').slice(1, 2), ['T7 fix-test'], 'a drafted row names its id beside the rule');
+ const tested = qualityRepo('quality-fix-tested', start);
+ tested.commit('fix(parse): ignore empty input', { 'src/parse.js': 'export function parse(text) {\n if (!text) return [];\n return text.split(\',\');\n}\n',
+ 'test/parse.test.js': 'import { test } from \'node:test\';\ntest(\'parses [G1]\', () => {});\ntest(\'empty input [G1]\', () => {});\n' });
+ assert.deepEqual(qualityBreaches(tested.root, changeRange(tested.root), { rules: ['fix-test'] }), [], 'a fix that ships a test passes');
+ assert.deepEqual(qualityBreaches(bare.root, changeRange(bare.root, { base: 'HEAD' }), { rules: ['fix-test'] }), [], 'an empty change has nothing to judge');
+});
+
+test('rigor reports a silent catch [D1,D3]', () => {
+ const old = 'export function old() {\n try { return 1; } catch { return 0; }\n}\n';
+ const repo = qualityRepo('quality-catch', { 'src/load.js': old });
+ repo.commit('feat(load): read settings', { 'src/load.js': [
+ old.trimEnd(),
+ 'export function settings(read) {',
+ ' try { return read(); } catch { return null; }',
+ '}',
+ 'export function loud(read) {',
+ ' try { return read(); } catch (error) { console.warn(`settings unreadable: ${error.message}`); return null; }',
+ '}',
+ 'export function strict(read) {',
+ ' try { return read(); } catch (error) { throw new Error(`settings: ${error.message}`); }',
+ '}',
+ 'export const later = (load) => load().catch(() => null);',
+ 'export const told = (load) => load().catch((error) => log(`load failed: ${error.message}`));',
+ 'export const words = \'a catch { } in a string is not code\';',
+ '',
+ ].join('\n'), 'test/load.test.js': 'try { JSON.parse(\'{\'); } catch { }\n' });
+ const breaches = qualityBreaches(repo.root, changeRange(repo.root), { rules: ['silent-catch'] });
+ assert.deepEqual(breaches.map((breach) => breachLine(breach)), [
+ 'src/load.js:5: silent-catch: catch is silent: it neither throws nor logs a line that names its subject',
+ 'src/load.js:13: silent-catch: .catch handler is silent: it neither throws nor logs a line that names its subject',
+ ], 'only the added silent catches are named: the old one, the logged one, the rethrow, a string and a test file are not');
+});
diff --git a/test/rigor-quality.test.js b/test/rigor-quality.test.js
new file mode 100644
index 00000000..dbd86c08
--- /dev/null
+++ b/test/rigor-quality.test.js
@@ -0,0 +1,166 @@
+/**
+ * The person's quality rules that run tests or read the doctrine (D1, D3): a guard its tests pass
+ * without, a fix with no control, a new check with no test, a change past its size budget, and the
+ * rules drafted as Doctrine rows that stay switched off until the person approves them. Every
+ * repo is real git and every test run is a real `node --test`.
+ */
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import {
+ mkdirSync,
+ mkdtempSync,
+ realpathSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import {
+ dirname,
+ join,
+} from 'node:path';
+import {
+ after,
+ test,
+} from 'node:test';
+import { loadDoctrine } from '../src/doctrine.js';
+import { doctrineReport } from '../src/doctrine-checks.js';
+import { loadConfig } from '../src/config.js';
+import {
+ QUALITY_RULES,
+ breachLine,
+ changeRange,
+ qualityBreaches,
+} from '../src/rigor-quality.js';
+import { createE2eHelpers } from './e2e-helpers.js';
+
+const e2e = createE2eHelpers();
+after(e2e.cleanup);
+const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-rigor-quality-test-')));
+after(() => rmSync(dir, { recursive: true, force: true }));
+
+/** Git in a fixture, with a fixed identity, no hooks and none of the suite's GIT_* settings. */
+function gitIn(root, ...args) {
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_')));
+ const result = spawnSync('git', ['-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'core.hooksPath=/dev/null', ...args], { cwd: root, env, encoding: 'utf8' });
+ assert.equal(result.status, 0, `git ${args.join(' ')}: ${result.stderr}`);
+ return result.stdout.trim();
+}
+
+/** Write files under a root and commit them with this subject; returns the commit id. */
+function commitIn(root, subject, changes) {
+ for (const [path, text] of Object.entries(changes)) {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), text);
+ }
+ gitIn(root, 'add', '-A');
+ gitIn(root, 'commit', '-q', '-m', subject);
+ return gitIn(root, 'rev-parse', 'HEAD');
+}
+
+/** A repo on main with `files`, then a work branch; returns its root. */
+function repo(name, files) {
+ const root = join(dir, name);
+ mkdirSync(root, { recursive: true });
+ gitIn(root, 'init', '-q', '-b', 'main');
+ commitIn(root, 'feat: start', files);
+ gitIn(root, 'checkout', '-q', '-b', 'work');
+ return root;
+}
+
+const SIZE = 'export function size(value) {\n return value.length;\n}\n';
+const SIZE_TEST = "import assert from 'node:assert/strict';\nimport { test } from 'node:test';\nimport { size } from '../src/size.mjs';\ntest('size [G1]', () => assert.equal(size('abc'), 3));\n";
+
+test('rigor names a guard its tests pass without [D1,D3]', () => {
+ const root = repo('guard', { 'src/size.mjs': SIZE, 'test/size.test.mjs': SIZE_TEST });
+ commitIn(root, 'feat(size): refuse what it cannot count', {
+ 'src/size.mjs': [
+ 'export function size(value) {',
+ " if (typeof value !== 'string') throw new TypeError('size counts text');",
+ " if (value.length > 10) throw new RangeError('size counts ten characters at most');",
+ ' return value.length;',
+ '}',
+ '',
+ ].join('\n'),
+ 'test/size.test.mjs': `${SIZE_TEST}test('size refuses a number [G1]', () => assert.throws(() => size(1), TypeError));\n`,
+ });
+ const breaches = qualityBreaches(root, changeRange(root), { rules: ['guard-mutation'] });
+ assert.deepEqual(breaches.map((breach) => breachLine(breach)),
+ ['src/size.mjs:3: guard-mutation: adds a guard the change\'s tests still pass without: test/size.test.mjs'],
+ 'the tested guard fails its test when removed; the untested one is named at its line');
+ const untested = repo('guard-untested', { 'src/size.mjs': SIZE, 'test/size.test.mjs': SIZE_TEST });
+ commitIn(untested, 'feat(size): refuse a number', { 'src/size.mjs': "export function size(value) {\n if (typeof value !== 'string') throw new TypeError('size counts text');\n return value.length;\n}\n" });
+ assert.deepEqual(qualityBreaches(untested, changeRange(untested), { rules: ['guard-mutation'] }).map((breach) => breachLine(breach)),
+ ['src/size.mjs:2: guard-mutation: adds a guard, and this change touches no test that could fail without it']);
+});
+
+test('rigor proves a fix by a control that fails before it and passes after [D1,D3]', () => {
+ const broken = 'export function size(value) {\n return value.length;\n}\n';
+ const fixed = 'export function size(value) {\n return value === null ? 0 : value.length;\n}\n';
+ const proven = repo('control-proven', { 'src/size.mjs': broken, 'test/size.test.mjs': SIZE_TEST });
+ commitIn(proven, 'fix(size): count null as empty', { 'src/size.mjs': fixed,
+ 'test/size.test.mjs': `${SIZE_TEST}test('size of null is 0 [G1]', () => assert.equal(size(null), 0));\n` });
+ assert.deepEqual(qualityBreaches(proven, changeRange(proven), { rules: ['root-cause-control', 'fix-test'] }), [],
+ 'the new test fails on the parent and passes at the fix');
+ const idle = repo('control-idle', { 'src/size.mjs': broken, 'test/size.test.mjs': SIZE_TEST });
+ const fix = commitIn(idle, 'fix(size): count null as empty', { 'src/size.mjs': fixed,
+ 'test/size.test.mjs': `${SIZE_TEST}test('size of text [G1]', () => assert.equal(size('ab'), 2));\n` });
+ assert.deepEqual(qualityBreaches(idle, changeRange(idle), { rules: ['root-cause-control'] }).map((breach) => breachLine(breach)),
+ [`test/size.test.mjs:5: root-cause-control: fix ${fix.slice(0, 12)}'s tests pass on its parent too, so they prove no root cause`],
+ 'a test that passes before the fix proves nothing about its cause');
+});
+
+test('rigor names a new check with no test and a change past its size budget [D1,D3]', () => {
+ const long = `${Array.from({ length: 1495 }, (_, index) => `export const line${index} = ${index};`).join('\n')}\n`;
+ const root = repo('size', { 'src/long.js': long, 'test/long.test.js': '// [G1]\n' });
+ commitIn(root, 'feat(checks): count todo markers', {
+ 'src/long.js': `${long}${Array.from({ length: 10 }, (_, index) => `export const more${index} = ${index};`).join('\n')}\n`,
+ 'bin/checks/todo.js': 'export const todo = 1;\n',
+ 'bin/checks/named.js': 'export const named = 1;\n',
+ 'test/named.test.js': "import '../bin/checks/named.js';\n",
+ });
+ const breaches = qualityBreaches(root, changeRange(root), { rules: ['fails-closed', 'size-budget'], budget: 5 });
+ assert.deepEqual(breaches.map((breach) => breachLine(breach)), [
+ 'bin/checks/todo.js:1: fails-closed: is a new gate or check, and no test in this change runs it with no data to show it fails closed',
+ 'src/long.js:1496: size-budget: this change grows code by 12 lines, past its 5-line budget; split the change',
+ 'src/long.js:1501: size-budget: is 1505 lines, over the 1500-line cap, and this change grows it by 10; split it into a new module',
+ ], 'the untested check, the budget at the file that grew most, and the grown over-cap file');
+ assert.deepEqual(qualityBreaches(root, changeRange(root), { rules: ['size-budget'] }).map((breach) => breach.line), [1501], 'within the default budget only the cap is named');
+ assert.throws(() => qualityBreaches(root, changeRange(root), { rules: ['tabs'] }), (error) => error.code === 'RIGOR_RULE');
+});
+
+test('quality rules are drafted for the person and stay off until approved [D1,D3]', () => {
+ const box = e2e.project('true');
+ const run = box.run(box.repo, 'rigor', '--draft-quality', '--json');
+ assert.equal(run.code, 0, run.out + run.err);
+ const drafts = JSON.parse(run.out).qualityDrafts;
+ assert.equal(drafts.length, QUALITY_RULES.length, 'one draft per rule');
+ const doctrine = loadDoctrine(box.repo);
+ for (const rule of QUALITY_RULES) {
+ const row = doctrine.repo.rows.find((entry) => entry.source === `rigor-quality:${rule.key}`);
+ assert.ok(row, `${rule.key} is drafted`);
+ assert.equal(row.status, 'draft', 'only the person approves a rule');
+ assert.equal(row.gate, `check pullboard rigor quality --rule ${rule.key}`);
+ assert.equal(row.count, '0');
+ assert.ok(row.text.startsWith(rule.text) && row.text.includes(rule.how), 'the row says what the check reads and what is left to review');
+ }
+ assert.deepEqual(doctrineReport(box.repo, loadConfig(box.repo)).filter((rule) => drafts.some((draft) => draft.id === rule.id)), [],
+ 'no drafted rule runs before the person approves it');
+ const again = box.run(box.repo, 'rigor', '--draft-quality', '--json');
+ assert.equal(again.code, 0, again.out + again.err);
+ assert.deepEqual(JSON.parse(again.out).qualityDrafts, [], 'a rerun drafts nothing twice');
+ const lane = box.run(box.web, 'rigor', '--draft-quality');
+ assert.equal(lane.code, 1, lane.out + lane.err);
+ assert.match(lane.out + lane.err, /COORDINATOR_ONLY/u);
+ gitIn(box.repo, 'add', '-A');
+ gitIn(box.repo, 'commit', '-q', '-m', 'docs(doctrine): draft the quality rules');
+ gitIn(box.web, 'merge', '-q', '--ff-only', 'main');
+ const fix = commitIn(box.web, 'fix(web): close the page', { 'web/page.js': 'export const page = 1;\n' });
+ const report = box.run(box.web, 'rigor', 'quality', '--rule', 'fix-test');
+ assert.equal(report.code, 1, report.out + report.err);
+ const row = drafts.find((draft) => draft.row.text.startsWith(QUALITY_RULES[0].text)).id;
+ assert.equal(report.out.trim(), `web/page.js:1: ${row} fix-test: fix ${fix.slice(0, 12)} "fix(web): close the page" changes no test that reproduces its failure`,
+ 'the breach names its file, line, doctrine row and rule');
+ const clean = box.run(box.repo, 'rigor', 'quality');
+ assert.equal(clean.code, 0, clean.out + clean.err);
+ assert.equal(clean.out.trim(), '', 'main against itself has no change to judge');
+});