From 6e3ea9fbd04c5f45b93856bcc6ae29e24e449d9d Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Sat, 21 Nov 2026 21:34:00 +0530 Subject: [PATCH] fix(ci): strip HTML comments from PR bodies in one pass, skipping Markdown code (#7306) Closes #7292 --- .github/scripts/pr-checks.cjs | 70 +++++++++++++++++++++++++++++++++-- scripts/pr-checks.test.mjs | 62 ++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 5 deletions(-) diff --git a/.github/scripts/pr-checks.cjs b/.github/scripts/pr-checks.cjs index 1f9a73fdd4..576302e065 100644 --- a/.github/scripts/pr-checks.cjs +++ b/.github/scripts/pr-checks.cjs @@ -85,6 +85,69 @@ const isDocsFile = (file) => { const isTestFile = (file) => /(^|\/)(__tests__|test|tests)\//.test(file) || /\.(test|spec)\.[^/]+$/.test(file) || /\.snap$/.test(file); +const FENCE_OPEN = /^ {0,3}(`{3,}(?=[^`\n]*$)|~{3,})/; + +// The text of a PR description a reader sees: each HTML comment replaced by a +// space, one pass from left to right, so removing one never joins its +// neighbours into another comment, number or image. `` and `` are complete, empty comments. + const close = text.indexOf("-->", i + 2); + if (close !== -1 || /^ {0,3}/g, ""); - const runtimeRow = (body, runtime) => { const escaped = runtime.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); const match = new RegExp(`^\\|\\s*${escaped}\\s*\\|(.*)\\|\\s*$`, "im").exec(body); @@ -322,5 +383,6 @@ module.exports = { hasMarkerComment, isMaintainer, isWaived, + linkedIssueNumbers, listPullFiles, }; diff --git a/scripts/pr-checks.test.mjs b/scripts/pr-checks.test.mjs index e07290accf..29620dc813 100644 --- a/scripts/pr-checks.test.mjs +++ b/scripts/pr-checks.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; import { test } from 'node:test'; -const { evaluateRuntimeProof } = createRequire(import.meta.url)('../.github/scripts/pr-checks.cjs'); +const { evaluateRuntimeProof, evaluateVisualEvidence, linkedIssueNumbers } = createRequire(import.meta.url)('../.github/scripts/pr-checks.cjs'); const body = (rows, known) => `## Affected surfaces\n\n| Runtime | What you ran and saw |\n|---|---|\n${Object.entries(rows).map(([k,v])=>`| ${k} | ${v} |`).join('\n')}\n\n## Known problems\n\n${known}\n\n\n`; const f = (...names) => names.map((filename) => ({ filename, status: 'modified' })); @@ -47,3 +47,63 @@ test('a relay change is run through the relay from a desktop client and from a p assert.deepEqual(run(relay, { Relay: 'Relay-only pairing: desktop app and the iOS Simulator both sent a prompt and streamed the reply' }).unproven, []); assert.deepEqual(run(f('packages/web/server/lib/share-pages/relay-client.js'), {}).unproven, []); }); + +test('text GitHub hides inside an HTML comment never counts as the author\'s answer', () => { + const electron = f('packages/electron/main.mjs'); + const evaluate = (text) => evaluateRuntimeProof({ pr: { body: text, draft: false }, files: electron }); + const row = '| Desktop (Electron) | Ran in Electron on macOS and saw the window open |'; + assert.deepEqual(evaluate(`## Affected surfaces\n${row}\n`).unproven, []); + // An unclosed comment hides everything after it. + assert.deepEqual(evaluate(`## Affected surfaces\n \nNone').knownProblems, false); +}); + +test('a literal comment marker in visible text does not hide what follows', () => { + const electron = f('packages/electron/main.mjs'); + const evaluate = (text) => evaluateRuntimeProof({ pr: { body: text, draft: false }, files: electron }); + const row = '| Desktop (Electron) | Ran in Electron on macOS and saw the window open |'; + assert.deepEqual(evaluate(`## Affected surfaces\nThe parser now skips \`-- \n${row}\n`).unproven, []); + // A backtick that never closes is plain text, so the comment after it is real. + assert.deepEqual(evaluate(`## Affected surfaces\nit\`s ok\n${row}\n`).unproven, []); + assert.deepEqual(evaluate(`## Affected surfaces\nit\`s\n\n`).unproven, ['Desktop (Electron)']); + // An unclosed marker mid-sentence, in a quoted fence or in indented code is text. + assert.deepEqual(evaluate(`## Affected surfaces\nWrite \n`), true); + assert.equal(missing(`## Screenshots\n[before](https://example.org/image.png)\n'), true); +}); + +test('a Part of link inside an HTML comment links nothing', async () => { + const github = { + graphql: async () => ({ + repository: { pullRequest: { closingIssuesReferences: { nodes: [ + { number: 5, repository: { nameWithOwner: 'openchamber/openchamber' } }, + { number: 6, repository: { nameWithOwner: 'someone/else' } }, + ] } } }, + }), + }; + const linked = (body) => linkedIssueNumbers({ github, owner: 'openchamber', repo: 'openchamber', pr: { number: 1, body } }); + assert.deepEqual(await linked('Part of #7\n\n3'), [5, 12]); +});