fix(ship-release): push guards skip only when origin has no base branch; a refused run or unreachable origin stops

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-11-03 04:49:19 +00:00
1 parent e9b98e2da8
commit f44e61c7ee
3 files changed
+30 -2

No files matched your search

+4 -1
View File
@@ -488,7 +488,10 @@ function prepushGuards(cwd: string, base: string | undefined): { line: string; s
const pg = bin(cwd, 'gstack-pregate', ['--stage', 'guards', '--allow-repo-commands', '--json', '--out', out, ...(base ? ['--base', base] : [])], 3_600_000);
let res: { status?: string; verdict?: string; tree?: string; code?: string; detail?: string; fix?: string; checks?: { id: string; status: string; detail?: string; fix?: string }[] } = {};
try { res = JSON.parse(pg.stdout.trim().split('\n').pop() ?? ''); } catch { /* unreadable: stops below */ }
if (res.status === 'refused' && res.code === 'POLICY_SOURCE_UNAVAILABLE' && /is not a resolvable commit/.test(res.detail ?? '')) return { line: `GUARDS: not run (no base branch to read guards from: ${res.detail})` };
const missing = res.status === 'refused' && res.code === 'POLICY_SOURCE_UNAVAILABLE' && !base ? /origin\/(\S+) is not a resolvable commit/.exec(res.detail ?? '')?.[1] : undefined;
const onOrigin = missing ? git(cwd, ['ls-remote', '--heads', 'origin', `refs/heads/${missing}`], 120_000) : null;
if (onOrigin && onOrigin.status !== 0) return { line: 'GUARDS: not run (origin unreachable)', stop: `cannot verify the remote branch (${firstLine(onOrigin.stderr)}): restore access before pushing` };
if (onOrigin?.status === 0 && !onOrigin.stdout.trim()) return { line: `GUARDS: not run (origin has no ${missing} branch to read guards from)` };
if (res.status === 'refused') return { line: `GUARDS: refused ${res.code}`, stop: `the pre-push guards could not run (${res.detail}; fix: ${res.fix}): repair it, then rerun push` };
if (res.tree && res.tree !== tree) return { line: `GUARDS: not certified (they checked the working tree ${res.tree.slice(0, 12)}, not HEAD's tree ${tree.slice(0, 12)})`, stop: 'the working tree differs from HEAD (uncommitted or untracked files): commit or stash them, then rerun push' };
const verdict = res.verdict ?? `unreadable (exit ${pg.status}: ${firstLine(pg.stderr)})`;