@devries-cameron20 / t3code-1 / commits / 5b5f1bc18a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): PR watch wakes quote a bot comment's text, not its HTML (#37032)

Co-authored-by: Taylor Dolezal <117500+onlydole@users.noreply.github.com>

Julius Marminge committed Nov 14, 2026 at 19:52 UTC 5b5f1bc18a2f62b2810ce23bf04a77c09657c965
2 files changed +115 -2
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+41
@@ -735,6 +735,47 @@ describe("evaluatePullRequestWatch", () => {
735 assert.include(text, `"${"x".repeat(196)}..."`);
736 });
737
738 + it.each([
739 + [
740 + "a bot's leading badge",
741 + '<a href="https://app.coderabbit.ai/change-stack/o/r/pull/1?cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://coderabbit.ai/badge-dark.svg"><img alt="Severity > `Minor`" src="https://coderabbit.ai/badge.svg"></picture></a>\r\n\r\n_⚠️ Potential issue_ | _🟠 Major_\r\n\r\n**Guard the empty list.**',
742 + "_⚠️ Potential issue_ | _🟠 Major_ **Guard the empty list.**",
743 + ],
744 + [
745 + "tags in prose and a hidden comment",
746 + "<!-- state -->\n<details>\n<summary>Why</summary>\n\n<p>Guard this</p>, then <br/>retry.\n</details>",
747 + "Why Guard this , then retry.",
748 + ],
749 + [
750 + "type arguments",
751 + "Return Promise<void>, not Promise<A> or Vec<code>.",
752 + "Return Promise<void>, not Promise<A> or Vec<code>.",
753 + ],
754 + [
755 + "code spans and fences",
756 + "Replace `<div>` with ``<span>``:\n~~~html\n<p>Done</p>\n~~~\r\nor\r\n```html\r\n<b>Done</b>\r\n```",
757 + "Replace `<div>` with ``<span>``: ~~~html <p>Done</p> ~~~ or ```html <b>Done</b> ```",
758 + ],
759 + [
760 + "indented code",
761 + "Use this replacement:\n\n <div>\n <span>Ready</span>\n </div>\n\nKeep the <b>wrapper</b>.",
762 + "Use this replacement: <div> <span>Ready</span> </div> Keep the wrapper .",
763 + ],
764 + ["an indented continuation of an HTML block", "<div>\n <span>Ready</span>\n</div>", "Ready"],
765 + ])("quotes a remark's text without its HTML tags: %s", (_name, body, quoted) => {
766 + const report = evaluatePullRequestWatch(watch(), detail(), [
767 + remark("reviewer", "2026-10-02T12:06:00Z", body),
768 + ]);
769 + const { text } = pullRequestWatchMessage({
770 + number: 1,
771 + url: "https://github.com/o/r/pull/1",
772 + baseBranch: "main",
773 + headSha: null,
774 + report,
775 + });
776 + assert.include(text, `: "${quoted}" `);
777 + });
778 +
779 it("reports a conflict once, until the branch is clean again", () => {
780 const conflicting = detail({ mergeability: "conflicting" });
781 const first = evaluatePullRequestWatch(watch(), conflicting, noRemarks);
apps/server/src/orchestration-v2/pullRequestWatch.ts
+74 -2
@@ -261,9 +261,81 @@ export function evaluatePullRequestWatch(
261 };
262 }
263
264 +// GitHub renders these, so in a remark's prose they are presentation, not what the reviewer said.
265 +// Lowercase only: `Promise<T>` is a type argument.
266 +const TAG_NAMES =
267 + "a|abbr|b|blockquote|br|caption|cite|code|dd|del|details|div|dl|dt|em|h[1-6]|hr|i|img|ins|kbd|li|mark|ol|p|picture|pre|q|s|samp|small|source|span|strike|strong|sub|summary|sup|table|tbody|td|tfoot|th|thead|tr|tt|ul|var";
268 +// A code span comes first so its tags stay literal; it cannot cross a blank line. A tag stops at
269 +// the next `<`, which keeps unclosed openers from rescanning the rest of the body.
270 +const PROSE_MARKUP = new RegExp(
271 + "(?<!`)(?<ticks>`+)(?!`)(?:(?!\\n[ \\t\\r]*\\n)[\\s\\S])*?(?<!`)\\k<ticks>(?!`)" +
272 + `|<(?<closing>/?)(?<name>${TAG_NAMES})(?=[\\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>`,
273 + "g",
274 +);
275 +
276 +function withoutTags(prose: string): string {
277 + // An opener glued to an identifier is a type argument (`Vec<code>`); it and its closer stay.
278 + const kept = new Map<string, number>();
279 + let text = "";
280 + let from = 0;
281 + for (const match of prose.matchAll(PROSE_MARKUP)) {
282 + const name = match.groups?.name;
283 + if (name === undefined) continue;
284 + const held = kept.get(name) ?? 0;
285 + if (match.groups?.closing === "/") {
286 + if (held > 0) {
287 + kept.set(name, held - 1);
288 + continue;
289 + }
290 + } else if (/\w/.test(prose.charAt(match.index - 1))) {
291 + kept.set(name, held + 1);
292 + continue;
293 + }
294 + text += `${prose.slice(from, match.index)} `;
295 + from = match.index + match[0].length;
296 + }
297 + return text + prose.slice(from);
298 +}
299 +
300 +// Drops HTML tags from Markdown prose. Fenced and indented code blocks pass through untouched.
301 +function withoutMarkup(body: string): string {
302 + const parts: Array<string> = [];
303 + let prose: Array<string> = [];
304 + let fence: string | undefined;
305 + let afterText = false;
306 + const code = (line: string) => {
307 + if (prose.length > 0) parts.push(withoutTags(prose.join("\n")));
308 + prose = [];
309 + parts.push(line);
310 + afterText = false;
311 + };
312 + for (const line of body.split("\n")) {
313 + if (fence !== undefined) {
314 + const closer = line.trim();
315 + if (closer.length >= fence.length && closer.replaceAll(fence.charAt(0), "") === "") {
316 + fence = undefined;
317 + }
318 + code(line);
319 + continue;
320 + }
321 + const opener = /^ {0,3}(`{3,}|~{3,})([\s\S]*)$/.exec(line);
322 + if (opener?.[1] !== undefined && !(opener[1].startsWith("`") && opener[2]?.includes("`"))) {
323 + fence = opener[1];
324 + code(line);
325 + } else if (!afterText && /^(?: {4}| {0,3}\t)\s*\S/.test(line)) {
326 + // Indented code needs a blank line before it; after text the indent is a continuation.
327 + code(line);
328 + } else {
329 + prose.push(line);
330 + afterText = line.trim() !== "";
331 + }
332 + }
333 + if (prose.length > 0) parts.push(withoutTags(prose.join("\n")));
334 + return parts.join("\n");
335 +}
336 +
337 function snippet(body: string): string {
265 - const text = body
266 - .replaceAll(/<!--[\s\S]*?-->/g, " ")
338 + const text = withoutMarkup(body.replaceAll(/<!--[\s\S]*?-->/g, " "))
339 .replaceAll(/\s+/g, " ")
340 .trim();
341 if (text.length <= SNIPPET_LENGTH) return text;