Skip to content

3D engine that AI agents drive

Fix three false greens in the PR metadata and triage gates (#2589)

Nguyen Xuan An778d0d7cdf82
diff --git a/scripts/pr-metadata-check.mjs b/scripts/pr-metadata-check.mjs
index e87eb551..1266ce99 100644
--- a/scripts/pr-metadata-check.mjs
+++ b/scripts/pr-metadata-check.mjs
@@ -27,7 +27,7 @@ const lightPathPattern = /^(docs\/|\.github\/|tests\/|changes\/)|\.md$/;
const lookNamePattern = /(^|[-_/.])(shaders?|glsl|lights?|lighting|materials?|environment|shadows?|tone|tonemap|fog|sky|post|bloom|ssao|taa|exposure)(?=$|[-_/.])/i;
const lookRootPattern = /^(src|packages)\//;
-const linkedIssuePattern = /\b(?:closes|close|closed|fixes|fix|fixed|resolves|resolve|resolved|part of)\s+(?:#\d+|https:\/\/github\.com\/codepawl\/crucible\/issues\/\d+)/i;
+const linkedIssuePattern = /\b(?:closes|close|closed|fixes|fix|fixed|resolves|resolve|resolved|part of):?\s+(?:#\d+|https:\/\/github\.com\/codepawl\/crucible\/issues\/\d+)/i;
const localPathPatterns = [
/[A-Za-z]:\\+(?:Users|Documents and Settings)\\/i,
/(?:^|[\s`"'(=])\/home\/[A-Za-z0-9._-]+/,
@@ -177,7 +177,7 @@ function contributorFixesFor(pr, files, light) {
}
const touchesLook = paths.some(isLookPath);
- if (touchesLook && !pr.lookApproved && !imagePattern.test(body)) {
+ if (touchesLook && !pr.lookApproved && !imagePattern.test(visibleBody)) {
fixes.push(fix(
'look-without-image',
'This changes how a scene looks, so add a before and an after picture to the description.',
diff --git a/scripts/triage-should-run.mjs b/scripts/triage-should-run.mjs
index 40de9be8..b081a1d9 100644
--- a/scripts/triage-should-run.mjs
+++ b/scripts/triage-should-run.mjs
@@ -91,10 +91,17 @@ function sinceYesterday() {
return new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString().replace(/\.\d+Z$/, 'Z');
}
-// A failed count blocks the run: the limits fail closed.
+// The limits fail closed: anything but a whole number of zero or more blocks the run. A missing total_count prints
+// 'null', and NaN would compare false against every limit and skip it.
+export function parseCountOrBlock(apiOutput) {
+ const text = String(apiOutput ?? '').trim();
+ return /^\d+$/.test(text) ? Number(text) : Number.POSITIVE_INFINITY;
+}
+
+// A failed count blocks the run too.
function countOrBlock(path, query) {
try {
- return Number(callApi([path, ...query, '--jq', '.total_count']).trim());
+ return parseCountOrBlock(callApi([path, ...query, '--jq', '.total_count']));
} catch {
return Number.POSITIVE_INFINITY;
}
diff --git a/tests/pr-metadata-check.test.js b/tests/pr-metadata-check.test.js
index 24e464ee..eef25cbe 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 look change whose only picture sits inside an HTML comment still asks for a picture', () => {
+ const hidden = `${withoutEvidence}<!-- ![after](https://github.com/user-attachments/assets/after.png) -->\n`;
+ const lookFiles = [file('src/shaders.js'), file('changes/12.md')];
+ assert.deepEqual(fixIds({ pr: pullRequest({ body: hidden }), files: lookFiles }), ['look-without-image']);
+ const visible = `${withoutEvidence}![after](https://github.com/user-attachments/assets/after.png)\n`;
+ assert.deepEqual(fixIds({ pr: pullRequest({ body: visible }), files: lookFiles }), []);
+});
+
+test('GitHub also links a closing keyword followed by a colon', () => {
+ for (const line of ['Closes: #12', 'Fixes: #12', 'Part of: #12', 'CLOSES: #12']) {
+ const body = goodBody.replace('Closes #12', line);
+ assert.deepEqual(fixIds({ pr: pullRequest({ body }), files: shippedFiles }), [], line);
+ }
+ const noNumber = goodBody.replace('Closes #12', 'Closes: nothing');
+ assert.deepEqual(fixIds({ pr: pullRequest({ body: noNumber }), files: shippedFiles }), ['missing-issue-link']);
+});
diff --git a/tests/triage-bot-hardening.test.js b/tests/triage-bot-hardening.test.js
index a3ee3938..46ceeab5 100644
--- a/tests/triage-bot-hardening.test.js
+++ b/tests/triage-bot-hardening.test.js
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
-import { MAX_ITEMS_PER_AUTHOR_PER_DAY, MAX_RUNS_PER_DAY, decideTriage, hasStickyComment } from '../scripts/triage-should-run.mjs';
+import { MAX_ITEMS_PER_AUTHOR_PER_DAY, MAX_RUNS_PER_DAY, decideTriage, hasStickyComment, parseCountOrBlock } from '../scripts/triage-should-run.mjs';
import { LABEL_ALLOWLIST } from '../scripts/triage-apply-labels.mjs';
import { APPROVAL_PHRASES, COMMENT_MARKER, buildCommentBody, claimsApproval, containsSecretValue, sanitizeComment } from '../scripts/triage-post-comment.mjs';
import { isDryRun, loadTriageItem, parseDispatchNumber } from '../scripts/triage-load-item.mjs';
@@ -214,3 +214,13 @@ test('every path the settings deny to Read is also denied to Grep and Glob on th
}
}
});
+
+test('a count that is missing or not a whole number blocks the run instead of skipping the limit', () => {
+ assert.equal(parseCountOrBlock('7\n'), 7);
+ assert.equal(parseCountOrBlock('0\n'), 0);
+ for (const unusable of ['null\n', '', ' ', 'NaN', '-1', '2.5', undefined]) {
+ assert.equal(parseCountOrBlock(unusable), Number.POSITIVE_INFINITY, String(unusable));
+ }
+ const blocked = decide({}, { authorItemsToday: parseCountOrBlock('null'), runsToday: 0 });
+ assert.equal(blocked.run, false);
+});