Files
PaperClipAI/.github/scripts/check-pr-dedup-search.mjs
T
Harold KimandPaperclip 98df214917 fix: fail closed on unusable Codex auth during sandbox auth merge
When reusing a Codex sandbox, the workspace-restore step now performs
an auth-merge check before adopting the sandbox's auth.json. The merge
fails closed when:

- host or sandbox Codex auth is unusable (missing token or account)
- the subscription payload shapes differ between host and sandbox
- subscription account identities do not match

Additional hardening: node absence on PATH during the embedded decision
script now exits non-zero instead of silently falling through. Co-change
comments link parseAuth (the embedded script) to hasUsableAuthPayload
(codex-home.ts) so a future auth-format change cannot silently diverge
between the two implementations.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-07-09 10:08:57 +00:00

72 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
/**
* check-pr-dedup-search.mjs
* Checks that the PR body affirms the author searched for similar PRs before
* opening this one. Looks for a checked checklist line matching the dedup
* affirmation in the PR template. Respects the same skip prefixes as the
* linked-issue gate.
*
* Export: checkDedupSearch(prBody, prTitle) → { passed, failures }
*/
import { fileURLToPath } from 'node:url';
const SKIP_PREFIXES = ['docs', 'chore', 'build', 'ci', 'style', 'test', 'revert'];
// Match a markdown checkbox line whose label mentions searching for similar
// PRs. Examples that should match (checked):
// - [x] I searched for similar open/closed PRs and confirmed this is not a duplicate
// - [X] I searched the GitHub PR list (open + recently closed) for similar PRs ...
// * [x] Searched for similar PRs — not a duplicate
const DEDUP_CHECKBOX_RE =
/^\s*[-*]\s*\[\s*([ xX])\s*\][^\n]*search(?:ed)?[^\n]*(?:similar|duplicate|prior)[^\n]*\bprs?\b/im;
function parsePrefix(title) {
if (!title) return null;
const match = title.match(/^([a-z]+)(?:\([^)]*\))?:/);
return match ? match[1].toLowerCase() : null;
}
export function checkDedupSearch(body, prTitle = '') {
const prefix = parsePrefix(prTitle);
if (prefix && SKIP_PREFIXES.includes(prefix)) {
return { passed: true, failures: [] };
}
if (!body || !body.trim()) {
return {
passed: false,
failures: ['PR body is empty — please fill out the PR template'],
};
}
const match = body.match(DEDUP_CHECKBOX_RE);
if (!match) {
return {
passed: false,
failures: [
'Add the dedup-search checkbox to your PR description and check it once ' +
'you have searched the GitHub PR list for similar PRs. See the PR template ' +
'at .github/PULL_REQUEST_TEMPLATE.md and CONTRIBUTING.md → "Before You Start: Search First".',
],
};
}
const checked = match[1] === 'x' || match[1] === 'X';
return {
passed: checked,
failures: checked ? [] : [
'Please confirm you searched the GitHub PR list for similar PRs by ' +
'checking the dedup-search checkbox in your PR description ' +
'(`- [x] I searched ...`). See CONTRIBUTING.md → "Before You Start: Search First".',
],
};
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const body = process.env.PR_BODY ?? '';
const title = process.env.PR_TITLE ?? '';
const result = checkDedupSearch(body, title);
console.log(JSON.stringify(result));
process.exit(result.passed ? 0 : 1);
}