Skip to content

3D engine that AI agents drive

Fail test-each-file on an empty match and remind a long draft before it closes (#2594)

Nguyen Xuan Anaac97a9eb3fb
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8d1b4342..fedcb434 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -218,7 +218,7 @@ Docs-only, CI-only and test-only pull requests skip everything except the local
- The comment updates itself when you fix an item. One reminder follows when 24 hours are left.
- A maintainer gives a first answer within about 7 days. That reply time is separate from the bot clock, which counts only items on your side. If an item is still open 72 hours after the first comment (the end of that UTC day, weekends included), the bot closes the pull request. It invites you to reopen it once the item is fixed, and reopening starts the time again.
-- Pull requests from the owner, members, collaborators and bots never close by themselves. Drafts and pull requests labelled `needs-owner-decision` do not close either.
+- Pull requests from the owner, members, collaborators and bots never close by themselves. Drafts and pull requests labelled `needs-owner-decision` do not close either; the clock of a draft restarts once it passes the reminder time, so marking it ready later still gets the reminder first.
- Labels and the milestone never count against you. The bot adds `needs-triage` when they are missing and `status:needs-author` while something of yours is missing.
For maintainers: the workflow is `.github/workflows/pr-metadata.yml`, and the rules are the pure modules `scripts/pr-metadata-check.mjs` (what is missing) and `scripts/pr-metadata-flow.mjs` (the clock and the wording). The workflow runs on `pull_request_target`, so it never checks out or runs the code of the pull request. It reads the description and the file list through the API only. Do not change that. It is not a required check.
diff --git a/scripts/pr-metadata-flow.mjs b/scripts/pr-metadata-flow.mjs
index ff07b29a..89da5aec 100644
--- a/scripts/pr-metadata-flow.mjs
+++ b/scripts/pr-metadata-flow.mjs
@@ -89,8 +89,13 @@ export function decideActions({ now, contributorFixes, previousState, exempt, dr
if (!failing) {
return { statusState: previousState ? {} : null, remind: false, close: false };
}
- const firstFailedAt = (!reopened && previousState?.firstFailedAt) || new Date(now).toISOString();
- const reminderSentAt = reopened ? undefined : previousState?.reminderSentAt;
+ const storedFirstFailedAt = (!reopened && previousState?.firstFailedAt) || new Date(now).toISOString();
+ const storedElapsedHours = (now - Date.parse(storedFirstFailedAt)) / HOUR_MS;
+ // A draft never closes, so its clock does not run past the reminder time: marking it ready later starts the last
+ // stretch again and the one reminder still comes before the close, as the contributing guide promises.
+ const clockStopped = draft && storedElapsedHours >= REMINDER_AFTER_HOURS;
+ const firstFailedAt = clockStopped ? new Date(now).toISOString() : storedFirstFailedAt;
+ const reminderSentAt = reopened || clockStopped ? undefined : previousState?.reminderSentAt;
const elapsedHours = (now - Date.parse(firstFailedAt)) / HOUR_MS;
const protectedFromTimers = exempt || draft || labels.includes(NEEDS_OWNER_DECISION_LABEL);
const remind = !protectedFromTimers && !reminderSentAt && elapsedHours >= REMINDER_AFTER_HOURS && elapsedHours < CLOSE_AFTER_HOURS;
diff --git a/scripts/test-each-file.mjs b/scripts/test-each-file.mjs
index 14f0fa05..0a7809c8 100644
--- a/scripts/test-each-file.mjs
+++ b/scripts/test-each-file.mjs
@@ -16,6 +16,12 @@ const testFiles = readdirSync(testsDirectory)
.filter(name => !nameFragment || name.includes(nameFragment))
.sort();
+// A fragment that matches nothing is a typo, and "0 of 0 pass" would read as green.
+if (testFiles.length === 0) {
+ console.error(`No test file in tests/ matches "${nameFragment ?? ''}". Pass part of a tests/*.test.js file name, or no argument to run every file.`);
+ process.exit(1);
+}
+
function runTestFile(name) {
return new Promise(resolve => {
const startedAt = Date.now();
diff --git a/tests/pr-metadata-check.test.js b/tests/pr-metadata-check.test.js
index 24e464ee..2e2dda95 100644
--- a/tests/pr-metadata-check.test.js
+++ b/tests/pr-metadata-check.test.js
@@ -395,3 +395,20 @@ test('the CI gate fails a shipped change without a note and a protected file edi
assert.deepEqual(failingGatesFor(['CHANGELOG.md']).map(gate => gate.name), ['protected files']);
assert.deepEqual(failingGatesFor(['docs/a.md']), []);
});
+
+test('a draft left past the close time is reminded before it closes once it is marked ready', () => {
+ const start = Date.parse('2026-11-01T00:00:00.000Z');
+ const base = { contributorFixes: someFix, exempt: false, labels: [] };
+ const state = { firstFailedAt: '2026-11-01T00:00:00.000Z' };
+ const whileDraft = decideActions({ ...base, draft: true, previousState: state, now: start + 100 * HOUR_MS });
+ assert.ok(!whileDraft.close && !whileDraft.remind);
+ const readyAt = start + 101 * HOUR_MS;
+ const ready = decideActions({ ...base, draft: false, previousState: whileDraft.statusState, now: readyAt });
+ assert.ok(!ready.close, 'a ready PR must not close on the run that follows a long draft');
+ const reminder = decideActions({ ...base, draft: false, previousState: ready.statusState, now: readyAt + REMINDER_AFTER_HOURS * HOUR_MS });
+ assert.ok(reminder.remind && !reminder.close);
+ const closing = decideActions({ ...base, draft: false, previousState: reminder.statusState, now: readyAt + CLOSE_AFTER_HOURS * HOUR_MS });
+ assert.ok(closing.close);
+ const earlyDraft = decideActions({ ...base, draft: true, previousState: state, now: start + 10 * HOUR_MS });
+ assert.equal(earlyDraft.statusState.firstFailedAt, '2026-11-01T00:00:00.000Z');
+});
diff --git a/tests/script-false-greens.test.js b/tests/script-false-greens.test.js
index d816c52c..665b1dc5 100644
--- a/tests/script-false-greens.test.js
+++ b/tests/script-false-greens.test.js
@@ -58,3 +58,11 @@ test('a group heading in one fragment does not regroup the bullets of the next f
assert.equal(entries.find(entry => entry.issue === 1).group, 'Breaking changes');
assert.equal(entries.length, 2);
});
+
+test('test-each-file fails and names the fragment when no test file matches', () => {
+ const script = fileURLToPath(new URL('../scripts/test-each-file.mjs', import.meta.url));
+ const result = spawnSync(process.execPath, [script, 'no-such-test-file-fragment'], { encoding: 'utf8', windowsHide: true });
+ assert.equal(result.status, 1, result.stdout);
+ assert.match(result.stderr, /No test file in tests\/ matches "no-such-test-file-fragment"/);
+ assert.doesNotMatch(result.stdout, /0 of 0/);
+});