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.

fix(core): block gate command args [C7,P4]

Corey Olsonc10b86668a24
diff --git a/src/cli.js b/src/cli.js
index 459f659d..ff60ccbd 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -3947,6 +3947,11 @@ async function runCommand(argv, io) {
return 0;
}
if (command === 'gate') {
+ 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';
+ throw new Refused('GATE_ARGUMENT', `pullboard gate does not accept extra words: ${words.join(' ')}. Use pullboard resources for status, or pullboard gate with no extra words to run the gate.`, next);
+ }
const ctx = context(io);
let config;
try { config = mainPolicy(ctx.info.root).config; }
diff --git a/src/next-steps.js b/src/next-steps.js
index 8dd0ed37..73d48970 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -131,6 +131,7 @@ export const NEXT_STEPS = Object.freeze({
FACT_JUDGEMENT: 'use a nonjudgement fact kind such as note, or ask the coordinator to record a judgement: pullboard fact <id> note "<what you observed>"',
FLAG_NOT_ALLOWED: 'drop the flag; pullboard help spec lists what each spec command takes',
GATE_RED: 'fix what the gate report names, commit, and submit again',
+ GATE_ARGUMENT: 'use pullboard resources for status, or pullboard gate with no extra words to run the gate',
GATE_SLOT_LEASE_LOST: 'let the parent process take the gate slot again, then restart the child',
GATE_SLOT_LEASE_REQUIRED: 'start the child test process with the live gate lease',
GATE_SLOT_MARKER_INVALID: 'restart the child with gateSlotEnvironment(lease)',
diff --git a/test/gate.test.js b/test/gate.test.js
index 082283b8..9afb4053 100644
--- a/test/gate.test.js
+++ b/test/gate.test.js
@@ -3,12 +3,14 @@
* no stamp stands in for it, and the tree must hold still while it runs.
*/
import assert from 'node:assert/strict';
-import { runFixtureExecFile as execFileSync, runFixtureChild as spawnSync, runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { runFixtureExecFile as execFileSync, runFixtureChild as spawnSync, runFixtureChild, runFixtureGit, startFixtureChild as spawn } from './fixture-child.js';
import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { after, test } from 'node:test';
+import { pathToFileURL } from 'node:url';
import { digestOf, testConcurrency } from '../src/gate.js';
+import { BROWSER_SLOT_HELD_ENV, GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV } from '../src/resources.js';
const PRIVATE_WORKER = resolve(import.meta.dirname, '../src/private-check-worker.js');
@@ -212,6 +214,101 @@ function repoWithGate(gate, check = '') {
return { dir, repo, env, git, run, runs };
}
+test('pullboard gate status refuses instead of running the gate [C7,P4]', async () => {
+ const box = repoWithGate('echo run >> ../runs.log');
+ for (const name of [BROWSER_SLOT_HELD_ENV, GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV]) delete box.env[name];
+ assert.equal(box.run('settings', 'gateSlots', '1').status, 0, 'the fixture uses the holder pool\'s single gate slot');
+ const resourceModule = pathToFileURL(resolve(import.meta.dirname, '../src/resources.js')).href;
+ const holderSource = `import { takeResource } from ${JSON.stringify(resourceModule)};
+const lease = await takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: process.cwd(), agent: 'gate-argument-holder' });
+try {
+ process.stdout.write('held\\n');
+ process.stdin.setEncoding('utf8');
+ for await (const line of process.stdin) if (line.trim() === 'release') break;
+} finally { lease.release(); }
+`;
+ let holderRun;
+ let holderClosed;
+ let commandRun;
+ let commandClosed;
+ let holderResult;
+ try {
+ holderRun = spawn(process.execPath, ['--input-type=module', '-e', holderSource], {
+ cwd: box.repo, env: box.env, stdio: ['pipe', 'pipe', 'pipe'],
+ });
+ let holderOutput = '';
+ holderRun.stdout.setEncoding('utf8');
+ holderClosed = new Promise((resolveClosed) => holderRun.once('close', (status, signal) =>
+ resolveClosed({ status, signal, stdout: holderOutput })));
+ const holderReady = new Promise((resolveReady) => {
+ holderRun.stdout.on('data', (part) => {
+ holderOutput += part;
+ if (holderOutput.includes('held\n')) resolveReady({ ready: true });
+ });
+ holderClosed.then((result) => resolveReady({ result }));
+ });
+ const ready = await holderReady;
+ assert.equal(ready.ready, true, `the private gate holder did not start: ${JSON.stringify(ready.result ?? holderOutput)}`);
+
+ for (const words of [['status'], ['run'], ['unexpected', 'word']]) {
+ commandRun = spawn(process.execPath, [BIN, 'gate', ...words], {
+ cwd: box.repo, env: box.env, stdio: ['ignore', 'pipe', 'pipe'],
+ });
+ let commandOutput = '';
+ let commandError = '';
+ commandRun.stdout.setEncoding('utf8');
+ commandRun.stderr.setEncoding('utf8');
+ commandRun.stdout.on('data', (part) => { commandOutput += part; });
+ commandRun.stderr.on('data', (part) => { commandError += part; });
+ commandClosed = new Promise((resolveClosed) => commandRun.once('close', (status, signal) =>
+ resolveClosed({ status, signal, stdout: commandOutput, stderr: commandError })));
+ const queued = new Promise((resolveQueued) => {
+ commandRun.stdout.on('data', () => {
+ if (commandOutput.includes('gate waiting:')) resolveQueued({ queued: true });
+ });
+ });
+ const outcome = await Promise.race([
+ queued,
+ commandClosed.then((result) => ({ result })),
+ ]);
+ if (outcome.queued) {
+ commandRun.kill('SIGTERM');
+ await commandClosed;
+ assert.fail(`the unexpected words ${words.join(' ')} entered the held gate queue: ${commandOutput}`);
+ }
+ assert.equal(outcome.result.status, 1, `${outcome.result.stderr}\n${outcome.result.stdout}`);
+ assert.match(outcome.result.stderr, /\[GATE_ARGUMENT\]/u);
+ assert.match(outcome.result.stderr, /pullboard resources for status/u);
+ assert.match(outcome.result.stderr, /pullboard gate with no extra words to run the gate/u);
+ assert.equal(box.runs(), 0, 'a refused extra word never starts the configured gate');
+ const gate = JSON.parse(box.run('resources', '--json').stdout).resources.find(({ name }) => name === 'gate');
+ assert.deepEqual(gate?.holders.map(({ agent }) => agent) ?? [], ['gate-argument-holder']);
+ assert.equal(gate?.line.length ?? 0, 0, 'the refused command never becomes a gate waiter');
+ }
+ for (const words of [['status'], ['run'], ['unexpected', 'word']]) {
+ const result = box.run('gate', ...words, '--json');
+ assert.equal(result.status, 1, `${result.stderr}\n${result.stdout}`);
+ const { error } = JSON.parse(result.stdout);
+ assert.equal(error.code, 'GATE_ARGUMENT');
+ assert.equal(error.next, 'use pullboard resources for status, or pullboard gate with no extra words to run the gate');
+ assert.equal(box.runs(), 0, 'JSON refusal never starts the configured gate');
+ const gate = JSON.parse(box.run('resources', '--json').stdout).resources.find(({ name }) => name === 'gate');
+ assert.deepEqual(gate?.holders.map(({ agent }) => agent) ?? [], ['gate-argument-holder']);
+ assert.equal(gate?.line.length ?? 0, 0, 'the refused JSON command never becomes a gate waiter');
+ }
+ } finally {
+ if (commandRun && commandRun.exitCode === null && commandRun.signalCode === null) {
+ commandRun.kill('SIGTERM');
+ }
+ if (commandClosed) await commandClosed;
+ if (holderRun) {
+ if (holderRun.exitCode === null && holderRun.signalCode === null) holderRun.stdin.end('release\n');
+ holderResult = await holderClosed;
+ }
+ }
+ assert.equal(holderResult?.status, 0, JSON.stringify(holderResult));
+});
+
test('gate before the first commit names the uncommitted config [I1,C7]', () => {
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-first-commit-')));
dirs.push(dir);