Files
Donny/강동윤andClaude Opus 5.5 b3f9132e00 ci(pr-policy): hold community PRs with needs:maintainer-decision (ENG-1576) (#2534)
* ci(pr-policy): hold a community PR with needs:maintainer-decision

Maintainers held community PRs whose issue or direction was undecided by
converting them to draft. A draft says the author is still working, and
the month-old stale close still closed them. The new label says the wait
is on the maintainers:

- the stale close skips a PR that carries it;
- /ready refuses it, and the review-label sweep removes Ready for Human
  Review from it;
- adding it removes Ready for Human Review at once. The labeled event runs
  in its own concurrency group, so a size label added after a push never
  replaces a queued push run.

The 72-hour compliance close still applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(babysit): report needs:maintainer-decision as a blocker

pr-status.ts read no labels, so it called a PR waiting on a maintainer
decision READY and babysit added Ready for Human Review, which the sweep
then removed again. It now reports a maintainer-decision blocker, and the
skill says to stop and hand off on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(review-label): tell the author to wait, and allow a second label delete

The /ready reply asks the author to fix each blocker, but only a
maintainer removes needs:maintainer-decision; its reason now says so.
A push run and a labeled run can both see Ready for Human Review and
delete it, and the second DELETE is a 404 that failed the run; the drop
job now treats a 404 as done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(babysit): stop on a maintainer decision only after the push

Blocker 6 said to handle the other blockers and then stop, which read as
stopping before the verify, push, and reply steps that follow the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(babysit): loop until a maintainer decision is the only blocker

Stopping right after the push skipped the CI wait in loop step 6, so a
fix that broke CI would be handed off unseen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(babysit): keep --watch waiting when only a maintainer decision blocks

verdictOf returned ACTION for any blocker, so --watch stopped at once on
a PR whose only blocker is needs:maintainer-decision, while its checks
still ran. That blocker alone now waits for pending checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:30:16 +01:00

218 lines
7.8 KiB
TypeScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
DECISION_LABEL,
GRACE_MS,
STALE_LABEL,
TAKEOVER_LABEL,
TAKEOVER_MARKER,
graceExpired,
isCommunity,
isStale,
monthBefore,
outstanding,
payloadAuthor,
problems,
section,
takeoverChange,
takeoverComment,
type Author,
type OpenPullRequest,
} from './rules.ts';
const template = `<!--
Title: Conventional Commits.
-->
## What
<!-- The change as a user meets it. -->
-
## Why
-
## How it works
1.
## Issue
<!-- Fixes #123. Required for fix, chore, test, perf, ci, build, and revert PRs. -->
## Verified
Ran it locally: yes | no - <why>
-
## Checklist
- [ ] Changeset added.
`;
const filled = `## What
- Keeps the cursor after a reload.
## Why
- A reload moved it to the start of the field.
## How it works
1. The reload handler restores the saved selection.
## Issue
Fixes #42
## Verified
Ran it locally: yes
- \`pnpm test\` passes.
`;
const community: Author = { login: 'someone', association: 'CONTRIBUTOR', bot: false, fromFork: true };
test('a filled template on a fix passes', () => {
assert.deepEqual(problems({ title: 'fix(web): keep the cursor', body: filled, closingIssues: 0 }), []);
});
test('the untouched template fails every section', () => {
const found = problems({ title: 'fix: something', body: template, closingIssues: 0 });
assert.equal(found.length, 3);
assert.match(found[0] ?? '', /needs an existing issue/);
assert.match(found[1] ?? '', /description is empty/);
assert.match(found[2] ?? '', /Verified/);
});
test('a bad title is the only problem reported', () => {
const found = problems({ title: 'Fix the cursor', body: template, closingIssues: 0 });
assert.equal(found.length, 1);
assert.match(found[0] ?? '', /Conventional Commit/);
});
test('feat, docs, and refactor need no issue', () => {
const body = filled.replace('Fixes #42', '');
for (const title of ['feat(cli)!: add a flag', 'docs: fix a link', 'refactor: split a file']) {
assert.deepEqual(problems({ title, body, closingIssues: 0 }), [], title);
}
assert.equal(problems({ title: 'chore(deps): bump', body, closingIssues: 0 }).length, 1);
});
test('a closing keyword GitHub resolved counts as the issue', () => {
const body = filled.replace('Fixes #42', '');
assert.deepEqual(problems({ title: 'fix: x', body, closingIssues: 1 }), []);
});
test('an issue URL under ## Issue counts, a PR URL does not', () => {
const issue = filled.replace('Fixes #42', 'https://github.com/e2e-inc/e2e/issues/42');
const pull = filled.replace('Fixes #42', 'https://github.com/e2e-inc/e2e/pull/42');
assert.deepEqual(problems({ title: 'fix: x', body: issue, closingIssues: 0 }), []);
assert.equal(problems({ title: 'fix: x', body: pull, closingIssues: 0 }).length, 1);
});
test('a description without the template heading counts', () => {
const body = '- Keeps the cursor after a reload.\n\n## Issue\n\nFixes #42\n\n## Verified\n\nRan it locally: yes\n';
assert.deepEqual(problems({ title: 'fix: x', body, closingIssues: 0 }), []);
assert.equal(problems({ title: 'fix: x', body: body.replace('- Keeps the cursor after a reload.', ''), closingIssues: 0 }).length, 1);
});
test('one filled description section is enough, placeholders are not', () => {
const body = template.replace('1.', '1. The reload handler restores the saved selection.').replace('yes | no - <why>', 'yes');
assert.deepEqual(problems({ title: 'feat: x', body, closingIssues: 0 }), []);
assert.match(problems({ title: 'feat: x', body: body.replace('1. The reload handler restores the saved selection.', '1.'), closingIssues: 0 })[0] ?? '', /description is empty/);
});
test('an unclosed HTML comment hides the rest of the body', () => {
assert.equal(section('## Verified\n\nyes <!-- note\n## Issue\n#1', 'Verified'), 'yes');
assert.equal(section('## Verified\n\na <!-- x --> b', 'Verified'), 'a b');
});
test('section stops at the next heading and drops comments', () => {
assert.equal(section(template, 'Issue'), '');
assert.equal(section(filled, 'what'), '- Keeps the cursor after a reload.');
assert.equal(section(filled, 'Missing'), undefined);
});
test('maintainers, bots, and branches in the repo are not community', () => {
assert.equal(isCommunity(community), true);
assert.equal(isCommunity({ ...community, association: 'MEMBER' }), false);
assert.equal(isCommunity({ ...community, bot: true }), false);
assert.equal(isCommunity({ ...community, fromFork: false }), false);
});
test('the grace period is 72 hours from the flag', () => {
const flagged = '2026-10-23T00:00:00Z';
const at = Date.parse(flagged);
assert.equal(graceExpired(flagged, at + GRACE_MS - 1), false);
assert.equal(graceExpired(flagged, at + GRACE_MS), true);
});
test('monthBefore clamps to the shorter month', () => {
assert.equal(monthBefore(new Date('2026-03-31T12:00:00Z')).toISOString(), '2026-02-28T12:00:00.000Z');
assert.equal(monthBefore(new Date('2026-10-22T00:00:00Z')).toISOString(), '2026-09-22T00:00:00.000Z');
});
test('a month-old community PR with under 2 positive reactions is stale', () => {
const now = new Date('2026-10-22T00:00:00Z');
const old: OpenPullRequest = {
createdAt: '2026-09-01T00:00:00Z',
author: community,
labels: [],
reactions: [
{ content: 'THUMBS_UP', count: 1 },
{ content: 'EYES', count: 5 },
],
approved: false,
};
assert.equal(isStale(old, now), true);
assert.equal(isStale({ ...old, reactions: [...old.reactions, { content: 'ROCKET', count: 1 }] }, now), false);
assert.equal(isStale({ ...old, createdAt: '2026-10-01T00:00:00Z' }, now), false);
assert.equal(isStale({ ...old, approved: true }, now), false);
assert.equal(isStale({ ...old, labels: [STALE_LABEL] }, now), false);
assert.equal(isStale({ ...old, labels: [TAKEOVER_LABEL] }, now), false);
assert.equal(isStale({ ...old, labels: ['size:S', DECISION_LABEL] }, now), false);
assert.equal(isStale({ ...old, author: { ...community, association: 'OWNER' } }, now), false);
});
test('a taken over PR has nothing outstanding', () => {
const failing = { title: 'not a conventional title', body: '', closingIssues: 0 };
assert.equal(outstanding({ ...failing, labels: ['size:S'] }).length, 1);
assert.deepEqual(outstanding({ ...failing, labels: ['size:S', TAKEOVER_LABEL] }), []);
});
test('the takeover announcement follows the label', () => {
const body = takeoverComment('contributor', 'maintainer');
assert.ok(body.startsWith(TAKEOVER_MARKER));
assert.match(body, /@contributor, .*@maintainer is taking over this PR/);
const taken = { labels: [TAKEOVER_LABEL], author: 'contributor', maintainer: 'maintainer', announced: undefined };
assert.deepEqual(takeoverChange(taken), { announce: body, maintainer: 'maintainer' });
assert.equal(takeoverChange({ ...taken, announced: body }), undefined);
assert.deepEqual(takeoverChange({ ...taken, maintainer: 'other', announced: body }), {
announce: takeoverComment('contributor', 'other'),
maintainer: 'other',
});
assert.equal(takeoverChange({ ...taken, maintainer: undefined }), undefined);
assert.equal(takeoverChange({ ...taken, labels: [], announced: body }), 'withdraw');
assert.equal(takeoverChange({ ...taken, labels: [] }), undefined);
});
test('payloadAuthor tells a fork PR from a branch in the repository', () => {
const pr = {
author_association: 'CONTRIBUTOR',
user: { login: 'contributor', type: 'User' },
head: { repo: { full_name: 'contributor/e2e' } },
base: { repo: { full_name: 'e2e-inc/e2e' } },
};
assert.equal(isCommunity(payloadAuthor(pr)), true);
assert.equal(isCommunity(payloadAuthor({ ...pr, head: { repo: { full_name: 'e2e-inc/e2e' } } })), false);
assert.equal(isCommunity(payloadAuthor({ ...pr, user: { login: 'dependabot[bot]', type: 'Bot' } })), false);
assert.equal(isCommunity(payloadAuthor({ ...pr, head: { repo: null } })), true);
});