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(spec): bind signer setup to recorded roots [S18,S21]

Corey Olson670012460854
diff --git a/docs/api.md b/docs/api.md
index 351a477b..021ef9a4 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -93,6 +93,6 @@ The result and refusal tables are checked against `JSON_SHAPES` in `src/json.js`
## SSH spec sign-offs
-`pullboard spec signers add [--key <path>] [--by <principal>]` opts a repo into OpenSSH-signed spec sign-offs. The key defaults to Git `user.signingkey`, then `~/.ssh/id_ed25519.pub`. The principal defaults to the exact Git `user.email`; `--by` overrides it. `spec signoff` uses the same email default in a repo with SSH signers, and accepts `--by` when a listed principal differs. A row's `signers:` names those exact principals.
+`pullboard spec signers add [--key <path>] [--by <principal>]` opts a repo into OpenSSH-signed spec sign-offs. The key defaults to Git `user.signingkey`, then `~/.ssh/id_ed25519.pub`. The principal defaults to the exact Git `user.email`; `--by` overrides it. `spec signoff` uses the same email default in a repo with SSH signers, and accepts `--by` when a listed principal differs. A row's `signers:` names those exact principals. Spec checking refuses a required principal without a corresponding signer entry.
The initial command output names `.pullboard/signers`, `.pullboard/first-commit` and `.pullboard/signers.initial` for staging and committing. Later sign-offs and signed signer-list changes are recorded in `.pullboard/signoffs.jsonl`; commit that file with the corresponding signer-list change.
diff --git a/src/cli.js b/src/cli.js
index 3a48ba79..4cbeaf6a 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -48,7 +48,7 @@ import { citedTestFiles, rowEvidence, rowStage } from './evidence.js';
import { serveView } from './serve.js';
import { doctorProblems } from './doctor.js';
import { exportBoard, importBoard } from './exchange.js';
-import { addSigner, defaultPrincipal, hasSignerFile } from './signature.js';
+import { addSigner, assertRequiredSigners, defaultPrincipal, hasSignerFile } from './signature.js';
const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
export const VERSION = PACKAGE.version;
@@ -1469,6 +1469,7 @@ function specCommand(io, { first, second, rest, values }) {
const signoffs = readSignoffs(ctx.info.root);
if (first === 'check' || first === undefined) {
const files = [[ctx.config.spec, spec], ...(practice.exists ? [[ctx.config.practice, practice]] : [])];
+ for (const [, parsed] of files) assertRequiredSigners(ctx.info.root, parsed.rows);
let errors = 0;
const messages = [];
for (const [name, parsed] of files) {
diff --git a/src/signature.js b/src/signature.js
index b95930a1..6c3f818d 100644
--- a/src/signature.js
+++ b/src/signature.js
@@ -79,6 +79,19 @@ export function readSignerText(root) {
/** Treat the existence of the signer file as opt-in, including an incomplete empty file. */
export function hasSignerFile(root) { return existsSync(join(root, SIGNERS_FILE)); }
+/** Refuse required SSH principals that have no configured allowed-signers entry. */
+export function assertRequiredSigners(root, rows) {
+ const required = rows.filter((row) => row.signers?.length);
+ if (!required.length) return;
+ if (!hasSignerFile(root)) throw new Refused('NO_SIGNERS', 'rows naming signers need an SSH signer list; run pullboard spec signers add');
+ const allowed = readSignerText(root);
+ for (const row of required) {
+ for (const principal of row.signers) {
+ if (!listsPrincipal(allowed, principal)) throw new Refused('UNLISTED_SIGNER', `${row.id} names ${principal}, which is not listed; run pullboard spec signers add --by ${principal} --key <path>`);
+ }
+ }
+}
+
/** Find a valid principal in an OpenSSH allowed-signers file. */
export function listsPrincipal(text, principal) {
return text.split(/\r?\n/u).filter((line) => line.trim() && !line.trimStart().startsWith('#'))
@@ -200,10 +213,15 @@ export function verifySignedRecords(root, records) {
function firstCommitFromGit(root) {
const shallow = spawnSync('git', ['rev-parse', '--is-shallow-repository'], { cwd: root, encoding: 'utf8' });
if (shallow.status !== 0) throw new Refused('NOT_A_REPO', 'signers add needs a Git repository');
- if (shallow.stdout.trim() === 'true') throw new Refused('SHALLOW_BEFORE_OPT_IN', 'opt in from a full clone so Pullboard can record the repo first commit');
- const roots = runTool('git', ['rev-list', '--max-parents=0', 'HEAD'], { cwd: root }).split(/\r?\n/u).filter(Boolean);
- if (roots.length !== 1) throw new Refused('NO_SINGLE_ROOT', 'signers add needs one reachable first commit');
- return roots[0];
+ if (shallow.stdout.trim() === 'true') throw new Refused('SHALLOW_BEFORE_OPT_IN', 'run git fetch --unshallow, then pullboard spec signers add so the first commit can be recorded');
+ const roots = runTool('git', ['rev-list', '--max-parents=0', '--timestamp', 'HEAD'], { cwd: root })
+ .split(/\r?\n/u).filter(Boolean).map((line) => {
+ const [time, hash] = line.split(' ');
+ return { time: Number(time), hash };
+ });
+ roots.sort((a, b) => a.time - b.time || (a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0));
+ if (!roots.length) throw new Refused('NO_FIRST_COMMIT', 'commit the repo before running pullboard spec signers add');
+ return roots[0].hash;
}
/** Add a public key to a repo, signing later changes with a key already allowed. */
diff --git a/test/signoff.test.js b/test/signoff.test.js
index cabcc0de..12b7e30c 100644
--- a/test/signoff.test.js
+++ b/test/signoff.test.js
@@ -78,7 +78,9 @@ test('[S17,S18,S19,S20,S21] signed rows require every named principal and surviv
assert.equal(succeeds(box, 'signers', 'add', '--key', box.co.publicKey, '--by', 'CO').status, 0);
assert.equal(readFileSync(join(box.root, '.pullboard/first-commit'), 'utf8').trim(), first);
succeeds(box, 'signoff', 'G1', '--by', 'CO', '--note', 'checked the exact row');
- assert.match(succeeds(box, 'check').stdout, /0 errors/);
+ const missingPrincipal = box.run('spec', 'check');
+ assert.notEqual(missingPrincipal.status, 0);
+ assert.match(missingPrincipal.stderr, /UNLISTED_SIGNER/u);
const partial = JSON.parse(succeeds(box, 'unmet', '--json').stdout);
assert.ok(partial.rows.some((row) => row.id === 'G1'), 'the row waits until both named principals have signed');
const page = join(box.dir, 'spec.html');
@@ -203,10 +205,10 @@ test('[S21] signer setup defaults to the configured Git key and email principal
const home = join(box.dir, 'git-home');
const ssh = join(home, '.ssh');
mkdirSync(ssh, { recursive: true });
- const configured = makeKey(join(ssh, 'id_ed25519'));
+ const configured = makeKey(join(ssh, 'custom-signing-key'));
box.env.HOME = home;
const globalConfig = join(box.dir, 'global.gitconfig');
- writeFileSync(globalConfig, '[user]\n\temail = [email protected]\n\tsigningkey = ~/.ssh/id_ed25519\n');
+ writeFileSync(globalConfig, '[user]\n\temail = [email protected]\n\tsigningkey = ~/.ssh/custom-signing-key\n');
box.env.GIT_CONFIG_GLOBAL = globalConfig;
box.git('config', '--local', '--unset', 'user.email');
box.git('config', '--local', '--unset', 'user.signingkey');
@@ -246,6 +248,9 @@ test('[S5,S18] legacy receipts preserve their shape and cannot meet required SSH
assert.deepEqual(Object.keys(records[0]), ['id', 'by', 'on', 'text', 'note']);
assert.match(records[0].on, /^\d{4}-\d\d-\d\d$/u);
assert.equal(existsSync(join(box.root, '.pullboard/signers')), false);
+ const missingList = box.run('spec', 'check');
+ assert.notEqual(missingList.status, 0);
+ assert.match(missingList.stderr, /NO_SIGNERS/u);
assert.ok(JSON.parse(succeeds(box, 'unmet', '--json').stdout).rows.some((row) => row.id === 'G1'));
assert.equal(JSON.parse(succeeds(box, 'show', 'G1', '--json').stdout).standing.met.length, 0);
const page = join(box.dir, 'legacy.html');
@@ -261,6 +266,7 @@ test('[S5,S18] legacy receipts preserve their shape and cannot meet required SSH
assert.notEqual(invalid.status, 0);
assert.match(invalid.stderr, /BAD_SIGNER/u);
assert.equal(readFileSync(file, 'utf8'), original, 'legacy signer validation refuses before appending');
+ succeeds(box, 'check');
});
test('[S17,S19] an existing empty signer file cannot silently fall back to unsigned sign-offs', (t) => {
@@ -326,3 +332,31 @@ test('[S21] setup refuses inline key data and files containing a GPG public key'
assert.match(wrongFormat.stderr, /NOT_SSH_KEY/u);
assert.equal(existsSync(join(box.root, '.pullboard/signers')), false);
});
+
+test('[S21] setup chooses the oldest root with a hash tie-break and refuses an unanchored shallow clone', (t) => {
+ const box = fixture(t);
+ box.env.GIT_COMMITTER_DATE = '2000-01-01T00:00:00Z';
+ const roots = ['first unrelated root', 'second unrelated root'].map((message) => box.git('commit-tree', 'HEAD^{tree}', '-m', message));
+ delete box.env.GIT_COMMITTER_DATE;
+ roots.forEach((hash, index) => {
+ box.git('branch', `root-${index}`, hash);
+ box.git('merge', '--quiet', '--allow-unrelated-histories', `root-${index}`, '-m', 'chore: merge an unrelated root');
+ });
+ const shallow = join(box.dir, 'unanchored-shallow');
+ execFileSync('git', ['clone', '-q', '--depth=1', `file://${box.root}`, shallow], { env: box.env, stdio: 'pipe' });
+ const refused = spawnSync(process.execPath, [BIN, 'spec', 'signers', 'add', '--key', box.co.publicKey, '--by', 'CO'], { cwd: shallow, env: box.env, encoding: 'utf8' });
+ assert.notEqual(refused.status, 0);
+ assert.match(refused.stderr, /SHALLOW_BEFORE_OPT_IN/u);
+ assert.match(refused.stderr, /git fetch --unshallow/u);
+ assert.equal(existsSync(join(shallow, '.pullboard/first-commit')), false);
+ succeeds(box, 'signers', 'add', '--by', 'CO');
+ const anchor = join(box.root, '.pullboard/first-commit');
+ assert.equal(readFileSync(anchor, 'utf8').trim(), roots.sort()[0]);
+ rmSync(anchor);
+ for (const args of [['check'], ['signoff', 'G1', '--by', 'CO']]) {
+ const result = box.run('spec', ...args);
+ assert.notEqual(result.status, 0);
+ assert.match(result.stderr, /NO_FIRST_COMMIT/u);
+ assert.equal(existsSync(anchor), false, 'signing and checking never reconstruct a missing anchor');
+ }
+});