Files
PaperClipAI/.github/scripts/check-pr-template.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

89 lines
2.7 KiB
JavaScript

#!/usr/bin/env node
/**
* check-pr-template.mjs
* Checks that a PR body contains all required sections from the PR template.
* Export: checkTemplate(prBody: string) → { passed: boolean, failures: string[] }
*/
import { fileURLToPath } from 'node:url';
const REQUIRED_SECTIONS = [
{ heading: '## Thinking Path', minSentences: 3 },
{ heading: '## What Changed', minSentences: 1 },
{ heading: '## Verification', minSentences: 1 },
{ heading: '## Risks', minSentences: 1 },
{ heading: '## Model Used', minSentences: 1 },
];
const MODEL_PLACEHOLDERS = [
'provider, model id',
'your model',
'<model>',
];
function extractSectionContent(body, heading) {
const idx = body.indexOf(heading);
if (idx === -1) return null;
const after = body.slice(idx + heading.length);
const nextHeading = after.search(/\n## /);
return (nextHeading === -1 ? after : after.slice(0, nextHeading)).trim();
}
function countSentences(text) {
// Split on terminal punctuation, bullet/quote line starts (`-`, `*`, `>`), or
// blank lines so non-prose Thinking Paths (bullet lists, blockquotes) are
// counted by item rather than as a single sentence.
return text.split(/[.!?]+\s+|\n\s*[-*>]+\s+|\n{2,}/).filter(s => s.trim().length > 5).length;
}
export function checkTemplate(body) {
const failures = [];
if (!body || !body.trim()) {
for (const { heading } of REQUIRED_SECTIONS) {
failures.push(`Missing section: **${heading}**`);
}
return { passed: false, failures };
}
for (const { heading, minSentences } of REQUIRED_SECTIONS) {
const content = extractSectionContent(body, heading);
if (content === null) {
failures.push(`Missing section: **${heading}**`);
continue;
}
if (!content || content === '_No response_' || /^<!--/.test(content)) {
failures.push(`Empty section: **${heading}**`);
continue;
}
if (heading === '## Thinking Path') {
const n = countSentences(content);
if (n < minSentences) {
failures.push(
`**Thinking Path** needs more detail (${n} sentence${n === 1 ? '' : 's'} — aim for 3+)`
);
}
}
if (heading === '## Model Used') {
const lower = content.toLowerCase();
if (MODEL_PLACEHOLDERS.some(p => lower.includes(p.toLowerCase()))) {
failures.push(
'**Model Used** contains placeholder text — please specify the actual model used (or "None — human-authored")'
);
}
}
}
return { passed: failures.length === 0, failures };
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const body = process.env.PR_BODY ?? '';
const result = checkTemplate(body);
console.log(JSON.stringify(result));
process.exit(result.passed ? 0 : 1);
}