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(hooks): preserve version probe refusals [P3,P4]

Corey Olson5f51bfebe088
diff --git a/src/hooks.js b/src/hooks.js
index b5f2334e..7f63d77a 100644
--- a/src/hooks.js
+++ b/src/hooks.js
@@ -693,7 +693,12 @@ export function hookScript(hook, version = installerVersion()) {
' bin="$1"; scope="$2"',
// Shell builtins only, so a hook works on a PATH that has no tail or sed: keep the last line of --version.
// The probe gets EOF; the delegated pre-push hook must receive Git's original ref records.
- ' nl=$(printf \'\\n_\'); nl=${nl%_}; have=$("$bin" --version </dev/null 2>/dev/null); have=${have##*"$nl"}',
+ // A failed probe already explains its refusal on stderr; preserve stdout refusals too, without guessing a version.
+ ' have=$("$bin" --version </dev/null) || {',
+ ' [ -z "$have" ] || printf \'%s\\n\' "$have" >&2',
+ ' exit 1',
+ ' }',
+ ' nl=$(printf \'\\n_\'); nl=${nl%_}; have=${have##*"$nl"}',
' if [ "$have" != "$want" ]; then',
' newer=$(node -e \'const [a,b]=process.argv.slice(1).map(v=>String(v).split(".").map(n=>parseInt(n,10)||0));for(let i=0;i<3;i++)if(a[i]!==b[i]){process.stdout.write(a[i]>b[i]?"yes":"no");process.exit(0)}process.stdout.write("no")\' "$have" "$want" 2>/dev/null)',
' if [ "$newer" = yes ]; then fix="pullboard init"; else fix="npm i $scope pullboard@$want"; fi',
diff --git a/test/hooks.test.js b/test/hooks.test.js
index 5769cdbf..7893fdc1 100644
--- a/test/hooks.test.js
+++ b/test/hooks.test.js
@@ -337,3 +337,28 @@ test('pre-push keeps its ref records when the version query reads stdin [C3,L3,I
'the real hook still admits the checked and gated commit');
assert.equal(readFileSync(box.env.HOOK_VERSION_STDIN, 'utf8'), '', 'the successful push also preserves its refs');
});
+
+for (const channel of ['stderr', 'stdout', 'matching-output']) {
+ test(`a failed ${channel} hook version probe shows its refusal before rules run [C1,C3,P3,P4]`, (t) => {
+ const box = stagedRepo(t);
+ const bin = join(box.root, '.probe-bin');
+ mkdirSync(bin);
+ const executable = join(bin, 'pullboard');
+ const refusal = 'probe refused: install Node 22.13 or newer, then retry';
+ const output = channel === 'stdout'
+ ? `printf '%s\\n' '${refusal}'`
+ : `${channel === 'matching-output' ? "printf '%s\\n' '0.9.0'; " : ''}printf '%s\\n' '${refusal}' >&2`;
+ writeFileSync(executable, `#!/bin/sh\nif [ "$1" = --version ]; then ${output}; exit 7; fi\nprintf '%s\\n' 'RULE_RAN' >&2\nexit 0\n`);
+ chmodSync(executable, 0o755);
+ const env = { ...process.env, PATH: `${bin}:${process.env.PATH}`, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
+ for (const hook of ['pre-commit', 'pre-merge-commit', 'commit-msg', 'pre-push']) {
+ const file = join(box.root, `try-${hook}`);
+ writeFileSync(file, hookScript(hook, '0.9.0'));
+ const result = spawnSync('/bin/sh', [file, join(box.root, 'MESSAGE')], { cwd: box.root, env, input: 'private ref records\n', encoding: 'utf8', timeout: 6000 });
+ assert.notEqual(result.status, 0, `${hook} must refuse a failed probe even if it prints the matching version`);
+ assert.ok(result.stderr.includes(refusal), `${hook} must show the probe's own refusal: ${result.stderr}`);
+ assert.doesNotMatch(result.stderr, /these hooks were installed|Run: npm i|Run: pullboard init|RULE_RAN/u, `${hook} must not invent version advice or run rules`);
+ assert.equal(result.stdout, '', `${hook} reports the refusal on stderr`);
+ }
+ });
+}