Clearer errors for GitHub email-privacy pushes, approval refusals and bisect case names (#4748)

/ship now tells you to fix your commit email when GitHub refuses a push
with GH007, instead of sending you into a pointless merge;
`gstack-approvals` says which `--owner-ref` check failed; and the merge
queue's bisect accepts a red judge case whose name has a space.

Why: three small, plainly correct fixes from outside reports (#4738,
#4718 with #4720, #4724 for #3580), taken as one batch.

Nothing to do.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: Barack-zero-to-one <121355791+Barack-zero-to-one@users.noreply.github.com>
Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Review-Finding: p1/adversarial-native#1 reader=adversarial-native
Review-Finding: p1/adversarial-native#3 reader=adversarial-native
Review-Finding: p1/specialist-batched#1 reader=testing
This commit is contained in:
authored and GitHub committed 2026-11-23 19:26:27 +00:00
1 parent 0d6cc1be56
commit 100e109ccd
14 files changed
+174 -21

No files matched your search

+65
View File
@@ -599,3 +599,68 @@ describe('import --autoplan --stack', () => {
expect(bin(['import', '--autoplan', tmp('appr-run-'), '--branch', 'feature/one', '--stack', 'feature/one'], { cwd }).status).toBe(2);
});
});
// Value: protects=each --owner-ref refusal of rule and round-grant names the one check that failed and the ref shape OWNER_REF accepts, never echoes the rejected ref, and every APPROVAL_RECORD_INVALID fix clause stops pointing at add's flags;
// fails_when=a bad ref, a missing --words and a missing --by print one shared sentence again, the refusal prints the raw ref, or fix: sends rule, round-grant, lane-exception or gate to add (--ask, --scope) (#4718, idea from @Barack-zero-to-one in #4720);
// why_new=no test read the refusal text, only its exit code; seam=gstack-approvals rule|round-grant|lane-exception|gate
describe('APPROVAL_RECORD_INVALID names the failed check and no other command (#4718)', () => {
const committed = () => {
const cwd = repo();
spawnSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.invalid', 'commit', '-q', '--allow-empty', '-m', 'init'], { cwd, timeout: 30_000 });
return { cwd, env: { GSTACK_STATE_ROOT: tmp('appr-state-') } };
};
const split = (err: string) => { const at = err.indexOf('; fix: '); return { why: err.slice(0, at), fix: err.slice(at + 7) }; };
const RULE = ['rule', '--finding', 'a.txt:1:docs', '--head', 'HEAD', '--reason', 'synthetic'];
const REF = 'SHIP-161:2026-11-22T18:42:14Z';
const BAD = 'ship-161:2026-11-22T18:40:00Z';
test('rule: a bad ref is refused for its shape alone, without echoing it; a good ref still records', () => {
const o = committed();
const r = bin([...RULE, '--words', 'A', '--by', 'owner', '--owner-ref', BAD], o);
expect([r.status, r.err]).toEqual([2, expect.stringContaining('(APPROVAL_RECORD_INVALID)')]);
const { why } = split(r.err);
expect(why).toContain('--owner-ref');
expect(why).toMatch(/uppercase/);
expect(why).not.toContain(BAD);
expect(why).not.toContain('--words');
expect(why).not.toContain('--by');
const ok = bin([...RULE, '--words', 'A', '--by', 'owner', '--owner-ref', REF], o);
expect(ok.status, ok.err).toBe(0);
});
test('rule: a good ref without --words names --words alone, and without --by names --by alone', () => {
const noWords = split(bin([...RULE, '--by', 'owner', '--owner-ref', REF], committed()).err).why;
expect(noWords).toContain('--words');
expect(noWords).not.toContain('--by');
expect(noWords).not.toMatch(/uppercase/);
const noBy = split(bin([...RULE, '--words', 'A', '--owner-ref', REF], committed()).err).why;
expect(noBy).toContain('--by');
expect(noBy).not.toContain('--words');
expect(noBy).not.toMatch(/uppercase/);
});
test('round-grant: a bad ref is refused for its shape alone; a good ref without --words names --words', () => {
const grant = ['round-grant', '--pr', '7', '--head', 'HEAD', '--kind', 'extra-round', '--reason', 'r', '--by', 'Captain'];
const bad = split(bin([...grant, '--owner-ref', 'ship-161:x', '--words', 'w'], committed()).err).why;
expect(bad).toMatch(/uppercase/);
expect(bad).not.toContain('ship-161');
expect(bad).not.toContain('--words');
const noWords = split(bin([...grant, '--owner-ref', REF], committed()).err).why;
expect(noWords).toContain('--words');
expect(noWords).not.toMatch(/uppercase/);
});
test('the fix clause of rule, round-grant, lane-exception and gate names no flag of add', () => {
const o = committed();
for (const args of [[...RULE, '--words', 'A', '--by', 'owner', '--owner-ref', BAD], ['round-grant'], ['lane-exception'], ['gate']]) {
const r = bin(args, o);
expect([args[0], r.status, r.err]).toEqual([args[0], 2, expect.stringContaining('(APPROVAL_RECORD_INVALID)')]);
const { fix } = split(r.err);
expect(fix).not.toContain('gstack-approvals add');
expect(fix).not.toContain('--ask');
expect(fix).not.toContain('--scope');
expect(fix).toContain('nothing was written');
}
});
});
+35
View File
@@ -331,6 +331,41 @@ describe('push (Step 17)', () => {
expect(r.stdout).toContain('never force-push');
});
// Value: protects=a push the remote refuses (GitHub's GH007 email privacy block, a protected branch) stops with the remote's own reason and what to change, never the fetch-and-merge route, and keeps PUSH_REJECTED;
// fails_when=any output holding "rejected" is read as a non-fast-forward and sends the user into a merge and a rerun of Steps 5-16 (#4738); seam=git push against a bare origin whose pre-receive hook declines; no_claim=GitHub's exact wording beyond the GH007 code
test('a remote refusal stops with its reason, and GH007 says to use the no-reply email, not to merge (#4738)', () => {
const f = fx();
const hook = path.join(f.origin, 'hooks', 'pre-receive');
const decline = (lines: string[]) => fs.writeFileSync(hook, `#!/bin/sh\n${lines.map(l => `echo '${l}' >&2`).join('\n')}\nexit 1\n`, { mode: 0o755 });
decline(['error: GH007: Your push would publish a private email address.', 'You can make your email public or disable this protection by visiting:', 'https://github.com/settings/emails']);
const gh007 = f.run(RELEASE, ['push', '--branch', 'feat'], { GSTACK_SESSION_KIND: 'unattended' });
expect(gh007.status, gh007.stdout + gh007.stderr).toBe(3);
expect(gh007.stdout).toContain('GH007');
expect(gh007.stdout).toContain('user.email');
expect(gh007.stdout).toContain('noreply');
expect(gh007.stdout).not.toContain('non-fast-forward');
expect(gh007.stdout).not.toContain('merge the remote');
expect(lineOf(gh007.stdout, 'PUSH')).toBe('PUSH: failed reason=PUSH_REJECTED');
f.git('branch', '-m', 'fix-non-fast-forward-GH007');
decline(['Trace: 0123abcd', 'error: GH006: Protected branch update failed for refs/heads/fix-non-fast-forward-GH007.']);
const protectedBranch = f.run(RELEASE, ['push', '--branch', 'fix-non-fast-forward-GH007'], { GSTACK_SESSION_KIND: 'unattended' });
expect(protectedBranch.status).toBe(3);
expect(protectedBranch.stdout).toContain('the remote refused the push (GH006: Protected branch update failed');
expect(protectedBranch.stdout).not.toContain('merge the remote');
expect(protectedBranch.stdout).not.toContain('noreply');
expect(lineOf(protectedBranch.stdout, 'PUSH')).toBe('PUSH: failed reason=PUSH_REJECTED');
const token = `ghp_${'a'.repeat(36)}`;
decline([`error: GH013: Push cannot contain secrets: ${token}`]);
const secret = f.run(RELEASE, ['push', '--branch', 'fix-non-fast-forward-GH007'], { GSTACK_SESSION_KIND: 'unattended' });
expect(secret.stdout).toContain('the remote refused the push (GH013: Push cannot contain secrets');
expect(secret.stdout).not.toContain(token);
decline(['nope']);
const plain = f.run(RELEASE, ['push', '--branch', 'fix-non-fast-forward-GH007'], { GSTACK_SESSION_KIND: 'unattended' });
expect(plain.stdout).toContain('the remote refused the push (pre-receive hook declined)');
expect(lineOf(plain.stdout, 'PUSH')).toBe('PUSH: failed reason=PUSH_REJECTED');
expect(f.git('ls-remote', '--heads', 'origin').stdout.trim()).not.toContain('fix-non-fast-forward');
});
// Value: protects=a never-pushed branch whose name breaks the repo's plain-words policy stops before the push, and a plain name pushes; fails_when=a coded or jargon branch name reaches origin, or a plain one is refused;
// why_new=plain public record (docs/ship-policy.md#plain-titles); seam=.gstack/plain-titles.json, git ls-remote; no_claim=branches already on origin
test('a never-pushed branch name with a tracker code or coined term in its front stops; a plain name pushes', () => {