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(gate): set project checks with one command [I1,A1,B26]

Corey Olson10f7f67e1500
diff --git a/docs/api.md b/docs/api.md
index 628f39d1..29c648ff 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -139,6 +139,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec
| `forget` | `version:number`, `root:string` |
| `prompt` | `version:number`, `role:string`, `text:string` |
| `gate` | `version:number`, `green:boolean`, `report:string` |
+| `gate set` | `version:number`, `gate:string`, `file:string` |
| `export` | `version:number`, `tables:object` |
| `digest` | `version:number`, `markdown:string`, `bytes:number`, `sequence:number`, `sections:array` |
| `import` | `version:number`, `tables:array` |
diff --git a/docs/lifecycle.md b/docs/lifecycle.md
index be55b950..f3bd64a6 100644
--- a/docs/lifecycle.md
+++ b/docs/lifecycle.md
@@ -112,7 +112,7 @@ Each move checks its guards in this order and refuses with the first one that do
| DIRTY | the worktree has no uncommitted changes | commit your changes, then submit |
| UNTRACKED | the worktree has no untracked files | commit or ignore them, then submit |
| NO_COMMIT | there is a commit to submit | commit your work, then submit |
-| NO_GATE | the repo names a gate command | set "gate" in pullboard.json to "pullboard spec check", then commit it |
+| NO_GATE | the repo names a gate command | in the main checkout, run pullboard gate set "<project test command>", then commit pullboard.json |
| OUTSIDE_LANE | the full claimed diff respects committed coordinator ownership | restore foreign paths or shout their owner |
| NO_POLICY | the full claimed diff respects committed coordinator ownership | restore the claim base or ask the coordinator to refreeze |
| BAD_CONFIG | the full claimed diff respects committed coordinator ownership | restore the committed coordinator configuration |
diff --git a/src/cli.js b/src/cli.js
index 1596cc27..18a7e83e 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -104,6 +104,7 @@ import {
} from './gate.js';
import { draftRow } from './spec-draft.js';
import { gateWaitReporter } from './gate-wait.js';
+import * as gateConfig from './gate-config.js';
import {
checkNeedsBrowser,
explicitCheckFiles,
@@ -1630,8 +1631,6 @@ function boardSetup(ctx, card, identity) {
const quote = value => "'" + String(value).replaceAll("'", "'\\''") + "'";
/** Quote one shell word only when it needs it, so a plain lane command reads as typed. */
const word = value => /^[A-Za-z0-9._/-]+$/u.test(String(value)) ? String(value) : quote(value);
- /** Preserve all existing configuration when recording one setup answer. */
- const configure = patch => `node -e ${quote(`const fs=require('node:fs');const p='pullboard.json';const c=JSON.parse(fs.readFileSync(p,'utf8'));${patch};fs.writeFileSync(p,JSON.stringify(c,null,2)+${JSON.stringify('\n')})`)}`;
const steps = [
requirementStep({ rows, drafted, toApply, completed: completed && !open.some(row => row.staleDecision), hasItems: card.all.length > 0 }),
{ number: 2, done: lanes.length > 0, question: `Ask the person: how should we divide the work? Suggested folders: ${folders.join(', ') || 'app/ (create it for the app)'}.`,
@@ -1640,7 +1639,7 @@ function boardSetup(ctx, card, identity) {
question: detectedGate
? `Ask the person: which command proves the build works? Suggested: ${detectedGate}.`
: 'Ask the person: if this board has no build, use `pullboard spec check` to check its spec and practice files; a second agent review checks the actual work. Or choose a custom gate command.',
- command: configure(`c.gate=${JSON.stringify(detectedGate || 'pullboard spec check')}`) },
+ command: gateConfig.settingCommand(ctx.info.root, detectedGate || 'pullboard spec check') },
{ number: 4, done: card.all.length > 0, question: 'Ask the person: what is the first small piece we should build?',
command: `pullboard add ${quote(lane)} 'First small piece' --specs ${quote(approved[0]?.id ?? 'G1')} --criterion 'Describe what the person will be able to do'` },
{ number: 5, done: card.viewOpened,
@@ -4470,6 +4469,7 @@ async function runCommand(argv, io) {
}
if (command === 'blueprint' && first === 'starters') return startersCommand(io, { second, rest, context, withBoard });
if (command === 'gate') {
+ if (first === 'set') return gateConfig.setHere(io, second, rest, values);
if (first !== undefined || second !== undefined || rest.length > 0) {
const words = [first, second, ...rest].filter((word) => word !== undefined);
const next = 'use pullboard resources for status, or pullboard gate with no extra words to run the gate';
diff --git a/src/gate-config.js b/src/gate-config.js
new file mode 100644
index 00000000..5758a445
--- /dev/null
+++ b/src/gate-config.js
@@ -0,0 +1,68 @@
+/** Project gate detection and configuration, without executing the chosen command [I1,I2,A1]. */
+import {
+ existsSync,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import { join } from 'node:path';
+import {
+ CONFIG_FILE,
+ loadConfig,
+} from './config.js';
+import { repoInfo } from './git.js';
+import { Refused } from './refused.js';
+
+const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';
+
+/** Detect an existing ecosystem's test command without executing it during setup. */
+export function detectGate(root) {
+ const file = join(root, 'package.json');
+ if (existsSync(file)) {
+ try {
+ const test = JSON.parse(readFileSync(file, 'utf8'))?.scripts?.test;
+ if (typeof test === 'string' && test.trim() && test.trim() !== NPM_DEFAULT_TEST) return 'npm test';
+ } catch { /* An unreadable package does not hide another ecosystem. */ }
+ }
+ if (existsSync(join(root, 'go.mod'))) return 'go test ./...';
+ if (existsSync(join(root, 'Cargo.toml'))) return 'cargo test';
+ if (['pytest.ini', '.pytest.ini', 'pytest.toml', '.pytest.toml', 'pyproject.toml', 'setup.py', 'requirements.txt'].some((name) => existsSync(join(root, name)))) return 'pytest';
+ for (const [name, section] of [['tox.ini', 'pytest'], ['setup.cfg', 'tool:pytest']]) {
+ if (existsSync(join(root, name)) && readFileSync(join(root, name), 'utf8').includes(`[${section}]`)) return 'pytest';
+ }
+ for (const name of ['GNUmakefile', 'makefile', 'Makefile']) {
+ if (!existsSync(join(root, name))) continue;
+ return /^test[ \t]*:(?!=)/mu.test(readFileSync(join(root, name), 'utf8')) ? 'make test' : '';
+ }
+ return '';
+}
+
+/** Quote the whole gate command as one shell argument, including embedded quotes. */
+export function settingCommand(root, command = detectGate(root) || 'pullboard spec check') {
+ return `pullboard gate set '${command.replaceAll("'", "'\\''")}'`;
+}
+
+/** Refuse an empty gate with a project-specific next step rather than a substitute check. */
+export function missingGate(root) {
+ const next = `in the main checkout, run ${settingCommand(root)}, then commit ${CONFIG_FILE}`;
+ return new Refused('NO_GATE', `no gate configured; ${next}`, next);
+}
+
+/** Set only the coordinator's gate field; running and trusting it remain separate commands. */
+export function setHere(io, command, rest, values) {
+ if (typeof command !== 'string' || !command.trim() || rest.length || values.landing) {
+ throw new Refused('USAGE', 'set the gate with one quoted argument: pullboard gate set "<command>"', 'pullboard gate set "<command>"');
+ }
+ const info = repoInfo(io.cwd);
+ if (!info.isMain) {
+ throw new Refused('NOT_MAIN', 'the project gate belongs to the coordinator', 'ask the coordinator to run pullboard gate set "<command>" in the main checkout');
+ }
+ loadConfig(info.root);
+ const file = join(info.root, CONFIG_FILE);
+ const raw = JSON.parse(readFileSync(file, 'utf8'));
+ raw.gate = command;
+ writeFileSync(file, JSON.stringify(raw, null, 2) + '\n');
+ io.result?.({ gate: command, file: CONFIG_FILE });
+ io.say(`set the project gate to ${command}`);
+ io.say(`Next: commit ${CONFIG_FILE}, then run pullboard gate.`);
+ return 0;
+}
diff --git a/src/gate.js b/src/gate.js
index e293f442..7437f99b 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -42,6 +42,7 @@ import {
} from './git.js';
import { secretsIn } from './hooks.js';
import { Refused } from './refused.js';
+import { missingGate } from './gate-config.js';
import {
GATE_SLOT_HELD_ENV,
gateSlotEnvironment,
@@ -528,7 +529,7 @@ export async function withGateSlot(root, action, { landing = false, itemCheck =
*/
export async function runGate(root, config, { trustStamp = true, onWait, landing = false, agent, item = '', stages = false, waivers = [] } = {}) {
if (!config.gate.trim()) {
- throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json to "pullboard spec check"', 'set "gate" in pullboard.json to "pullboard spec check", then commit it');
+ throw missingGate(root);
}
if (trustStamp && isStampedGreen(root)) return { isGreen: true, isCached: true, output: '', seconds: 0, log: '' };
return await withGateSlot(root, (lease) => fullGateRun(root, config, trustStamp, { waitMs: lease.waitMs, gateLease: lease, landing, stages, waivers }), {
@@ -576,7 +577,7 @@ export async function runStaticChecks(root, config, { agent, item = '', onWait,
* @returns {Promise<any>}
*/
export async function runSubmitGate(root, config, { base, trunk, changed, check, agent, item = '', kind = 'submit', onWait, onBrowserFallback }) {
- if (!config.gate.trim()) throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json to "pullboard spec check"', 'set "gate" in pullboard.json to "pullboard spec check", then commit it');
+ if (!config.gate.trim()) throw missingGate(root);
await runStaticChecks(root, config, { agent, item, onWait, onBrowserFallback });
const selection = config.affectedTests
? selectAffectedTests(root, { base, trunk, changed })
diff --git a/src/help.js b/src/help.js
index d5107864..e127d77f 100644
--- a/src/help.js
+++ b/src/help.js
@@ -225,6 +225,7 @@ Role guides
Gate and hooks
pullboard gate [--landing] run the configured gate; prioritize a trunk landing in the machine queue
+ pullboard gate set "<command>" record the project gate in the main checkout; commit it before running the gate
pullboard hook pre-commit|pre-merge-commit|commit-msg|pre-push git runs these
${lifecycleHelp()}
@@ -302,6 +303,7 @@ const HELP_ALIASES = {
'spec signers add': { usage: 'pullboard spec signers add [--key <path>] [--by <principal>]', source: 'spec signers add' },
doctrine: { usage: 'pullboard doctrine check', source: 'doctrine check' },
hook: { usage: 'pullboard hook pre-commit|pre-merge-commit|commit-msg|pre-push', source: 'hook' },
+ 'gate set': { usage: 'pullboard gate set "<command>"', source: 'gate set' },
'hook pre-commit': { usage: 'pullboard hook pre-commit', source: 'hook' },
'hook pre-merge-commit': { usage: 'pullboard hook pre-merge-commit', source: 'hook' },
'hook commit-msg': { usage: 'pullboard hook commit-msg <file>', source: 'hook' },
diff --git a/src/init.js b/src/init.js
index 1f409923..4ab9606d 100644
--- a/src/init.js
+++ b/src/init.js
@@ -37,6 +37,11 @@ import {
} from './config.js';
import { loadDoctrine } from './doctrine.js';
import { installHooks } from './hooks.js';
+import {
+ detectGate,
+ settingCommand,
+} from './gate-config.js';
+export { detectGate } from './gate-config.js';
import { machineHome } from './machine-home.js';
import { Refused } from './refused.js';
import { reviewerStartup } from './next-steps.js';
@@ -57,8 +62,6 @@ import {
specTemplate,
} from './templates.js';
-const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';
-
/** Resolve a directory through symlinks, retaining a missing suffix for a not-yet-created private home. */
function canonicalDirectoryPath(candidate) {
let cursor = resolve(candidate);
@@ -92,29 +95,6 @@ export function machineHomeWriteScopeIsNarrow(machinePath, userHome = userInfo()
return !targetContainsHome;
}
-/**
- * Detect an existing ecosystem's test command without running it during setup (I1, I2).
- *
- * @param {string} root
- * @returns {string}
- */
-export function detectGate(root) {
- const file = join(root, 'package.json');
- if (existsSync(file)) {
- try {
- const test = JSON.parse(readFileSync(file, 'utf8'))?.scripts?.test;
- if (typeof test === 'string' && test.trim() && test.trim() !== NPM_DEFAULT_TEST) return 'npm test';
- } catch { /* An unreadable package does not hide another ecosystem. */ }
- }
- if (existsSync(join(root, 'go.mod'))) return 'go test ./...';
- if (existsSync(join(root, 'Cargo.toml'))) return 'cargo test';
- if (['pytest.ini', '.pytest.ini', 'pytest.toml', '.pytest.toml', 'pyproject.toml', 'setup.py', 'requirements.txt'].some((name) => existsSync(join(root, name)))) return 'pytest';
- for (const [name, section] of [['tox.ini', 'pytest'], ['setup.cfg', 'tool:pytest']]) {
- if (existsSync(join(root, name)) && readFileSync(join(root, name), 'utf8').includes(`[${section}]`)) return 'pytest';
- }
- return '';
-}
-
/** Folders a lane proposal never hands out: dependencies and build output. */
const NOT_LANE_FOLDERS = new Set(['node_modules', 'dist', 'build', 'out', 'target', 'vendor', 'coverage']);
@@ -618,8 +598,8 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model, per
notes.push(...laneProposalNotes(proposeLanes(root)));
if (!configuredGate(root)) {
notes.push(gate
- ? 'no gate yet: set "gate" in pullboard.json to the command that proves the build'
- : 'no test command detected; ask the person which command tests this project, then set "gate" in pullboard.json to that command; if this board has no build, use `pullboard spec check` to check its spec and practice files; a second agent review checks the actual work');
+ ? `no gate yet: record the command that proves the build with ${settingCommand(root, gate)}`
+ : `no test command detected; ask the person which command tests this project, then record it with pullboard gate set "<command>"; if this board has no build, use ${settingCommand(root)} to check its spec and practice files; a second agent review checks the actual work`);
}
if (written.length) notes.push(`git add -f -- ${written.map((path) => `'${path.replaceAll("'", "'\\''")}'`).join(' ')}`);
return notes;
diff --git a/src/json.js b/src/json.js
index 7e1cb049..252043b7 100644
--- a/src/json.js
+++ b/src/json.js
@@ -83,6 +83,7 @@ export const JSON_SHAPES = {
forget: shape({ root: 'string' }),
prompt: shape({ role: 'string', text: 'string' }),
gate: shape({ green: 'boolean', report: 'string' }),
+ 'gate set': shape({ gate: 'string', file: 'string' }),
export: shape({ tables: 'object' }),
digest: shape({ markdown: 'string', bytes: 'number', sequence: 'number', sections: 'array' }),
import: shape({ tables: 'array' }),
diff --git a/src/machine.js b/src/machine.js
index 9595adde..5abad8b7 100644
--- a/src/machine.js
+++ b/src/machine.js
@@ -149,7 +149,7 @@ export const GUARDS = [
{ id: 'treeClean', refuse: 'DIRTY', rule: 'the worktree has no uncommitted changes', next: 'commit your changes, then submit', source: 'cli' },
{ id: 'nothingUntracked', refuse: 'UNTRACKED', rule: 'the worktree has no untracked files', next: 'commit or ignore them, then submit', source: 'cli' },
{ id: 'hasCommit', refuse: 'NO_COMMIT', rule: 'there is a commit to submit', next: 'commit your work, then submit', source: 'cli' },
- { id: 'gateConfigured', refuse: 'NO_GATE', rule: 'the repo names a gate command', next: 'set "gate" in pullboard.json to "pullboard spec check", then commit it', source: 'cli' },
+ { id: 'gateConfigured', refuse: 'NO_GATE', rule: 'the repo names a gate command', next: 'in the main checkout, run pullboard gate set "<project test command>", then commit pullboard.json', source: 'cli' },
{ 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' },
diff --git a/src/next-steps.js b/src/next-steps.js
index 569d1408..1d3fdaf5 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -366,7 +366,7 @@ export const NEXT_STEPS = Object.freeze({
NO_FILE: 'check the path and pass a file that exists',
NO_FILES_LANE: 'run pullboard lanes, then file the build in a lane that owns files, or pass --after <id> if it reviews that item',
NO_FIRST_COMMIT: 'commit the repo, then pullboard spec signers add',
- NO_GATE: 'set "gate" in pullboard.json to "pullboard spec check", then commit it',
+ NO_GATE: 'in the main checkout, run pullboard gate set "<project test command>", then commit pullboard.json',
NO_ITEM: 'find the item id: pullboard list --all',
NO_LANE: 'pick a lane from pullboard lanes',
NO_LINES: 'name a line range inside the file',
diff --git a/src/run.js b/src/run.js
index e42abe66..1255c874 100644
--- a/src/run.js
+++ b/src/run.js
@@ -54,6 +54,7 @@ import {
outOfLane,
} from './lanes.js';
import { Refused } from './refused.js';
+import { missingGate } from './gate-config.js';
/** Report changing machine queue state while an unattended item waits for a gate slot. */
function gateWaitReporter(io) {
@@ -444,7 +445,7 @@ export async function runItems(io, values, deps) {
const minutes = boundedInt(values.minutes ?? '15', 1, 240, '--minutes');
const limit = values.items === undefined ? Infinity : boundedInt(values.items, 1, 1000, '--items');
const waitMinutes = values.wait === undefined ? 0 : boundedInt(values.wait, 0, 240, '--wait');
- if (!ctx.config.gate.trim()) throw new Refused('NO_GATE', 'the runner submits through the gate; set "gate" in pullboard.json first');
+ if (!ctx.config.gate.trim()) throw missingGate(ctx.info.root);
if (!isClean(ctx.info.root) || untracked(ctx.info.root).length) {
throw new Refused('DIRTY', 'the runner starts from a clean worktree; commit or remove your changes first');
}
diff --git a/test/api.test.js b/test/api.test.js
index 8a7d34ff..2fa7ef62 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -1056,6 +1056,8 @@ test('[A1] every catalog command and subcommand has a real CLI exercise', () =>
assert.deepEqual(json(source, source.repo, 'lanes').lanes.catalog, { owns: ['catalog/'] });
const runner = json(source, source.repo, 'runner', ['add', 'fixture-runner', '--slots', '2', '--browser', '1']);
assert.deepEqual(runner.runner, { host: 'fixture-runner', slots: 2, browser: 1 });
+ const projectGate = JSON.parse(readFileSync(join(source.repo, 'pullboard.json'), 'utf8')).gate;
+ assert.equal(json(source, source.repo, 'gate', ['set', projectGate], 'set').gate, projectGate);
const missing = Object.keys(JSON_SHAPES.commands).filter((key) => !covered.has(key));
assert.deepEqual(missing, [], `add real-repo invocations for undocumented coverage gaps: ${missing.join(', ')}`);
assert.deepEqual([...coveredRoots].sort(), resultCommands(), 'every actual root/factory command has an invocation');
diff --git a/test/init-gate.test.js b/test/init-gate.test.js
index 9b27725a..6e72d88d 100644
--- a/test/init-gate.test.js
+++ b/test/init-gate.test.js
@@ -4,6 +4,7 @@ import { accessSync, chmodSync, constants as fsConstants, existsSync, mkdirSync,
import { delimiter, join } from 'node:path';
import { after, test } from 'node:test';
import { createE2eHelpers } from './e2e-helpers.js';
+import { runFixtureChild } from './fixture-child.js';
const e2e = createE2eHelpers();
after(e2e.cleanup);
@@ -202,3 +203,122 @@ test('a repo without package.json is told a gate that fits it [C7,B26]', () => {
assert.equal(completed.code, 0, completed.err || completed.out);
assert.equal(readFileSync(marker, 'utf8'), 'tested\n', 'submit runs the chosen project test');
});
+
+test('the gate is set with one pullboard command [I1,A1,B26]', () => {
+ const box = e2e.sandbox();
+ const root = join(box.dir, 'one-gate-command');
+ mkdirSync(root);
+ box.git(root, 'init', '-q', '-b', 'main');
+ const initialized = box.run(root, 'init');
+ assert.equal(initialized.code, 0, initialized.err || initialized.out);
+
+ const configFile = join(root, 'pullboard.json');
+ const initial = JSON.parse(readFileSync(configFile, 'utf8'));
+ initial.gate = '';
+ initial.lanes.checks = { owns: ['checks/'] };
+ initial.fixtureSetting = { kept: ['spaces and "quotes"', { nested: true }] };
+ writeFileSync(configFile, JSON.stringify(initial, null, 2) + '\n');
+ writeFileSync(join(root, 'SPEC.md'), "# Gate project\n\n## G \u00b7 Goals\n- G1 [approved, must] The project gate checks the work. | gate: test\n");
+ mkdirSync(join(root, 'checks'));
+ const marker = join(box.dir, 'chosen gate ran.json');
+ const checker = join(root, 'checks', 'project check.mjs');
+ writeFileSync(checker, `import { writeFileSync } from 'node:fs';\nwriteFileSync(${JSON.stringify(marker)}, JSON.stringify(process.argv.slice(2)));\n`);
+ box.git(root, 'add', '-A');
+ box.git(root, 'commit', '-q', '-m', 'chore: prepare a board without a gate');
+
+ const resumed = box.run(root, 'resume', '--json');
+ assert.equal(resumed.code, 0, resumed.err || resumed.out);
+ assert.equal(JSON.parse(resumed.out).setup.step, 3);
+ const step = JSON.parse(resumed.out).setup.steps.find(entry => entry.number === 3);
+ assert.equal(step.done, false);
+ assert.match(step.command, /^pullboard gate set /u);
+ assert.doesNotMatch(step.command, /node -e|writeFileSync/u);
+ const resumedText = box.run(root, 'resume');
+ assert.equal(resumedText.code, 0, resumedText.err || resumedText.out);
+ assert.ok(resumedText.out.includes(step.command));
+ assert.doesNotMatch(resumedText.out, /node -e.*pullboard\.json/u);
+ const missing = box.run(root, 'gate', '--json');
+ assert.equal(missing.code, 1, missing.err || missing.out);
+ const refusal = JSON.parse(missing.out).error;
+ assert.equal(refusal.code, 'NO_GATE');
+ assert.match(refusal.next, /pullboard gate set/u);
+ assert.doesNotMatch(refusal.next, /node -e/u);
+
+ /** Quote each shell word while retaining the entire configured command as one CLI argument. */
+ const quote = value => `'${value.replaceAll("'", "'\\''")}'`;
+ const argument = `proof with spaces, "double quotes" and 'single quotes'`;
+ const command = [process.execPath, checker, argument].map(quote).join(' ');
+ const before = JSON.parse(readFileSync(configFile, 'utf8'));
+ const configured = box.run(root, 'gate', 'set', command, '--json');
+ assert.equal(configured.code, 0, configured.err || configured.out);
+ assert.equal(JSON.parse(configured.out).gate, command);
+ assert.deepEqual(JSON.parse(readFileSync(configFile, 'utf8')), { ...before, gate: command });
+ assert.equal(existsSync(marker), false, 'setting the command neither executes it nor stamps it green');
+ const answered = box.run(root, 'resume', '--json');
+ assert.equal(answered.code, 0, answered.err || answered.out);
+ assert.equal(JSON.parse(answered.out).setup.steps.find(entry => entry.number === 3).done, true);
+
+ // The normal gate trusts committed coordinator policy, so commit the chosen answer first.
+ box.git(root, 'add', 'pullboard.json');
+ box.git(root, 'commit', '-q', '-m', 'chore: choose the project gate');
+ const gated = box.run(root, 'gate', '--json');
+ assert.equal(gated.code, 0, gated.err || gated.out);
+ assert.equal(JSON.parse(gated.out).green, true);
+ assert.deepEqual(JSON.parse(readFileSync(marker, 'utf8')), [argument]);
+});
+
+test('NO_GATE names the project test before a spec-only fallback [I1,C3,B26]', () => {
+ const box = e2e.sandbox();
+ const root = join(box.dir, 'red-make-project');
+ mkdirSync(root);
+ box.git(root, 'init', '-q', '-b', 'main');
+ const initialized = box.run(root, 'init');
+ assert.equal(initialized.code, 0, initialized.err || initialized.out);
+ const marker = join(box.dir, 'make-test-ran');
+ const quotedMarker = `'${marker.replaceAll("'", "'\\''")}'`;
+ writeFileSync(join(root, 'Makefile'), `test:\n\t@printf tested > ${quotedMarker}\n\t@exit 1\n`);
+ box.git(root, 'add', '-A');
+ box.git(root, 'commit', '-q', '-m', 'chore: prepare a project with a failing test');
+
+ const missing = box.run(root, 'gate', '--json');
+ assert.equal(missing.code, 1, missing.err || missing.out);
+ const refusal = JSON.parse(missing.out).error;
+ assert.equal(refusal.code, 'NO_GATE');
+ const suggested = /pullboard gate set '[^']*'/u.exec(refusal.next)?.[0];
+ assert.equal(suggested, "pullboard gate set 'make test'", 'the next step keeps the actual project test');
+ assert.doesNotMatch(refusal.next, /pullboard spec check/u, 'a known test command is not replaced with a spec check');
+ assert.equal(existsSync(marker), false, 'finding a test command never executes it');
+ const configured = runFixtureChild('sh', ['-c', suggested], { cwd: root, env: box.env, encoding: 'utf8' });
+ assert.equal(configured.status, 0, configured.failure || configured.stderr || configured.stdout);
+ assert.equal(JSON.parse(readFileSync(join(root, 'pullboard.json'), 'utf8')).gate, 'make test');
+ assert.equal(existsSync(marker), false, 'the printed setter does not execute the test');
+ box.git(root, 'add', 'pullboard.json');
+ box.git(root, 'commit', '-q', '-m', 'chore: record the printed project gate');
+ const gated = box.run(root, 'gate', '--json');
+ assert.equal(gated.code, 1, gated.err || gated.out);
+ assert.equal(JSON.parse(gated.out).green, false, 'following the advice cannot certify red project tests');
+ assert.equal(readFileSync(marker, 'utf8'), 'tested', 'the real Makefile target ran');
+});
+
+test('gate set keeps configuration in the coordinator checkout [I1,L3,B26]', () => {
+ const box = e2e.project();
+ const mainFile = join(box.repo, 'pullboard.json');
+ const laneFile = join(box.web, 'pullboard.json');
+ const mainBefore = readFileSync(mainFile, 'utf8');
+ const laneBefore = readFileSync(laneFile, 'utf8');
+ const forbidden = box.run(box.web, 'gate', 'set', 'echo changed', '--json');
+ assert.equal(forbidden.code, 1, forbidden.err || forbidden.out);
+ const refusal = JSON.parse(forbidden.out).error;
+ assert.equal(refusal.code, 'NOT_MAIN');
+ assert.match(refusal.next, /ask the coordinator.*pullboard gate set/u);
+ assert.equal(readFileSync(mainFile, 'utf8'), mainBefore);
+ assert.equal(readFileSync(laneFile, 'utf8'), laneBefore);
+
+ for (const args of [[], [''], [' '], ['echo', 'split'], ['echo ok', '--landing']]) {
+ const invalid = box.run(box.repo, 'gate', 'set', ...args, '--json');
+ assert.equal(invalid.code, 1, invalid.err || invalid.out);
+ assert.equal(JSON.parse(invalid.out).error.code, 'USAGE');
+ assert.match(JSON.parse(invalid.out).error.next, /pullboard gate set/u);
+ assert.equal(readFileSync(mainFile, 'utf8'), mainBefore, 'a malformed setter leaves all configuration alone');
+ }
+});
diff --git a/test/newcomer.test.js b/test/newcomer.test.js
index 6c7eeda4..7ac2cfba 100644
--- a/test/newcomer.test.js
+++ b/test/newcomer.test.js
@@ -115,7 +115,7 @@ test('init detects language gates and gives an example in the same ecosystem [I1
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
const rerun = emptyConfigured.run('init');
assert.equal(rerun.status, 0, rerun.stderr);
- assert.match(rerun.stdout, /no gate yet: set "gate" in pullboard\.json to the command that proves the build/u);
+ assert.match(rerun.stdout, /no gate yet: record the command that proves the build with pullboard gate set 'npm test'/u);
assert.doesNotMatch(rerun.stdout, /if this board has no build/u);
});