From 0b6ee5b7085e8e2affd875c00852ad5a4944f489 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:43:37 +0000 Subject: [PATCH 1/2] fix(pr-queue): lens rules follow-ups from #283's lenses (#303) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - no_lens_text: the <, >, [ and ] one clean pass leaves become blanks, so nested markup in a quoted comment cannot turn into a lens field when the reader cleans it again; keep_markdown checks both readings. - Fences follow GFM: a line with an info string no longer closes a fence, and a backtick line with another backtick after it opens none (plain_lines and unquoted_lines share fence_step). - A second header below a valid one counts in the forms `lens —`, `lens –` and `lens=` too (not `LENS = '...'`, test code in reports). - README: in a fix-round comment, a sha goes on its own line; a quote does not help a lens field. The queue's advice says so. - Tests for the two round-1 mutation gaps (tab before `>`, fence kind and length). Fixes #303 Co-Authored-By: Claude Opus 5.5 --- fork-ci/actions/pr-queue/README.md | 23 ++++++++ fork-ci/actions/pr-queue/lens.py | 76 ++++++++++++++++--------- fork-ci/actions/pr-queue/lens.test.py | 80 ++++++++++++++++++++++++++- 3 files changed, 153 insertions(+), 26 deletions(-) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 744fc8c817bd1..2e0c9355e3ab2 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -268,6 +268,29 @@ or `lens –`, quoted or not), or a `read at` with a hex sha outside a `>` quote (a fenced or indented block is no quote). To name a sha a lens read in such a comment, quote that line with `>`. +A quote does not help a lens field: a line like `the security lens — fixed in +` blocks for good, quoted or not, and `not a lens:` cannot clear it. In a +fix-round or note comment, put each sha on a line of its own, with no `lens` +and `:`, `=`, `—` or `–` before it on that line: + +``` +not a lens: fix round 2 for the security and state lenses +- security, major: fixed, with a test that fails on the old head. +- state, minor: left as is, because ... +Fixed in: + +``` + +A comment holds one lens: below a valid header, a line that starts with +`lens:`, `lens —`, `lens –` or `lens=` and names a sha is a second header, and +the comment reads nothing. (`LENS = '...'`, with a blank before the `=`, is no +second header: a report's test code assigns sample headers that way.) + +Fenced blocks are read as GitHub renders them: only a line of the same +character, at least as long and with nothing after it, closes a fence +(```` ```js ```` inside an open fence is code), and a backtick line with +another backtick after it is inline code, not a fence. + A comment that looks like a report but is not one valid read is a lens of its own, keyed by that comment. Posting the report again the right way adds a new read and leaves the old comment blocking, and hiding it is not enough either. diff --git a/fork-ci/actions/pr-queue/lens.py b/fork-ci/actions/pr-queue/lens.py index 600d6c9e8498b..f4c8671fea071 100644 --- a/fork-ci/actions/pr-queue/lens.py +++ b/fork-ci/actions/pr-queue/lens.py @@ -25,6 +25,10 @@ # that is indented 4+ spaces, quoted or a fence is never the header (lens_header), but its header line still counts as # one (lens_problem: fail closed). LENS_RE = re.compile(r'lens\s*:\s*(.*)', re.I) +# A line that starts with a lens field in a form loose_header reads (`lens:`, `lens —`, `lens –`, and `lens=` with no +# blank before the `=`): below the first line, one with a sha is a second lens's header (lens_problem; issue #303). +# `LENS = '...'` is no field here: a report's test code assigns sample headers that way. +FIELD_START_RE = re.compile(r'lens(?:\s*[:—–]|=)\s*(.*)', re.I) # The name ends at the first field: ` · reviewer:` or ` · read at:` (also `read at `; the separator may also be # `,` `—` or none). A bare `reviewer` or `read at` stays in the name (`data-integrity reviewer 1` and `... 2` are two # lenses). @@ -38,7 +42,8 @@ # leaves the old one; hiding the old one is not enough either. # The queue posts this text, so it never holds the lens marker with its colon (no_lens_text). NO_HEADER_WAY_OUT = ('delete that comment (hiding it is not enough), or edit it to start with `not a lens` and a colon ' - 'and hold no lens header line, with any line that names the sha a lens read quoted with `>`, or') + 'and hold no lens header line and no sha on a line with a lens field, with any line that names ' + 'the sha a lens read quoted with `>`, or') EDITED = 'edited after posting: post a new comment instead' # A review's edit and hidden flags, by review node id, as the caller read them with a query of its own (pr_queue # review_flags). gh pr view never fetches them for reviews but prints `includesCreatedEdit: false` anyway, so a review @@ -205,18 +210,31 @@ def lens_header(body, narrow=False): return name, (at.group(1).lower() if at else None) +# A fence as GitHub (GFM) reads one: an opening line is 3+ backticks or tildes after at most 3 spaces, and a backtick +# fence's info string holds no backtick (```` ```x``` ```` is inline code, no fence). Only a line of the same character, +# at least as long, with nothing but blanks after it closes the fence (```` ```js ```` inside an open fence is code). An +# unclosed fence runs to the end of the comment. Issue #303: a line with an info string closed the fence, and a +# backtick line with a backtick after it opened one, so lines GitHub shows as code were read as quotes or plain text, +# and plain lines as code. +FENCE_OPEN_RE = re.compile(r' {0,3}(?:(`{3,})[^`]*|(~{3,}).*)') +FENCE_CLOSE_RE = re.compile(r' {0,3}(`{3,}|~{3,})[ \t]*') + + +def fence_step(fence, line): + """(the fence open after this line or None, whether the line belongs to a fence), given the fence open before it.""" + if fence: + m = FENCE_CLOSE_RE.fullmatch(line) + return (None if m and m.group(1)[0] == fence[0] and len(m.group(1)) >= len(fence) else fence), True + m = FENCE_OPEN_RE.fullmatch(line) + return (m.group(1) or m.group(2), True) if m else (None, False) + + def plain_lines(body): - """The comment's lines outside fenced blocks, 4-space/tab indented blocks and quotes.""" + """The comment's lines outside fenced blocks (fence_step), 4-space/tab indented blocks and quotes.""" out, fence = [], None for line in (body or '').splitlines(): - m = re.match(r' {0,3}(`{3,}|~{3,})', line) - if fence: - if m and m.group(1)[0] == fence[0] and len(m.group(1)) >= len(fence): - fence = None - continue - if m: - fence = m.group(1) - elif line.strip() and not re.match(r' {4}|\t|[ ]{0,3}>', line): + fence, fenced = fence_step(fence, line) + if not fenced and line.strip() and not re.match(r' {4}|\t|[ ]{0,3}>', line): out.append(line) return out @@ -226,13 +244,8 @@ def unquoted_lines(body): indented block is code, and the line stays.""" out, fence = [], None for line in (body or '').splitlines(): - m = re.match(r' {0,3}(`{3,}|~{3,})', line) - if fence: - if m and m.group(1)[0] == fence[0] and len(m.group(1)) >= len(fence): - fence = None - elif m: - fence = m.group(1) - elif re.match(r' {0,3}>', line): + fence, fenced = fence_step(fence, line) + if not fenced and re.match(r' {0,3}>', line): continue out.append(line) return out @@ -256,13 +269,24 @@ def no_lens_text(text, keep_markdown=False): """Text that can never count as a lens read, name a lens or look like a lens report (lens_problem), for anything the queue quotes into a comment (gh errors): no `read at`, no lens field (`lens:`, `lens=`, `lens —`, `lens –`), no `safe to merge`. keep_markdown: the - queue's own advice (a command in backticks, a `` placeholder) stays as written when, read without its markdown, - it holds none of these; otherwise it is cleaned like any other text.""" + queue's own advice (a command in backticks, a `` placeholder) stays as written when, read without its markdown + either way (clean_inline narrow or not), it holds none of these; otherwise it is cleaned like any other text.""" plain = clean_inline(text) - out = re.sub(r'\bread([\s-]*)at\b', r'read\1@', plain, flags=re.I) + if keep_markdown and _no_lens_forms(plain) == plain: # the reader cleans the text as written once, either way + narrow = clean_inline(text, narrow=True) + if _no_lens_forms(narrow) == narrow: + return text + # Cleaned text is cleaned AGAIN by the reader, and nested markup (`lens<b>=`, `lens[[](z)](w)=`) left by one + # pass would turn into a field on the second (issue #303). So the `<` `>` `[` `]` one pass left become blanks: with + # none of them, another pass (either way) changes nothing. + return _no_lens_forms(re.sub(r'[<>\[\]]', ' ', plain)) + + +def _no_lens_forms(text): + """The text with every lens form no_lens_text names rewritten.""" + out = re.sub(r'\bread([\s-]*)at\b', r'read\1@', text, flags=re.I) out = re.sub(r'\bsafe(\s+)to(\s+)merge\b', r'safe\1to\2land', out, flags=re.I) - out = re.sub(r'\blens(\s*)[:=—–]', r'lens\1-', out, flags=re.I) # every field form loose_header reads - return text if keep_markdown and out == plain else out + return re.sub(r'\blens(\s*)[:=—–]', r'lens\1-', out, flags=re.I) # every field form loose_header reads def check_state(c): @@ -355,9 +379,11 @@ def norm(line): first = next((line for line in lines if line.strip()), '') normed, start = [norm(line) for line in lines], f'starts with {first.strip()[:60]!r}' at = next((i for i, line in enumerate(lines) if line.strip()), 0) - # a header line, or (after the first line) a line starting `lens:` with a sha in any form (a second lens's - # loosely written read behind a valid header). Only at the line start: `lens:` in mid-line is often a mention. - headers = sum(header_line(line) or (i > at and bool((m := LENS_RE.match(line)) and HEX_RE.search(m.group(1)))) + # a header line, or (after the first line) a line starting with a lens field in a form FIELD_START_RE reads and + # a sha in any form (a second lens's loosely written read behind a valid header). Only at the line start: + # `lens:` in mid-line is often a mention. + headers = sum(header_line(line) + or (i > at and bool((m := FIELD_START_RE.match(line)) and HEX_RE.search(m.group(1)))) for i, line in enumerate(normed)) if headers > 1: return f'{EMBEDDED} {headers} times (post one comment per lens), {start}' diff --git a/fork-ci/actions/pr-queue/lens.test.py b/fork-ci/actions/pr-queue/lens.test.py index d2ed01c94248f..1e41710c465ee 100644 --- a/fork-ci/actions/pr-queue/lens.test.py +++ b/fork-ci/actions/pr-queue/lens.test.py @@ -6,7 +6,7 @@ committed, with the source's override prefix set to `proj ready --head`. Where the port differs from the source on purpose, the replay says so (Corpus). """ -import copy, json, os, re, sys, unittest +import copy, json, os, random, re, sys, unittest sys.dont_write_bytecode = True # no __pycache__ next to the scripts @@ -98,6 +98,28 @@ def test_a_hex_word_without_a_digit_is_no_sha(self): self.assertIsNone(SOURCE.lens_problem(post('Notes\n```\nlens: effaced\n```'))) self.assertIn(lens.EMBEDDED, SOURCE.lens_problem(post('Notes\n```\nlens: effaced1\n```'))) + def test_a_second_header_in_any_field_form_below_a_valid_one_counts(self): # issue #303 point 3 + first, hex = f'lens: tests · reviewer: x · read at: {SHA_B}\n\n', NotALens.HEX + for second in (f'Lens — security · read at: {hex}', f'lens= security {hex[:10]}', + f'**Lens** – security ({hex[:7]})', f'- lens=security read at {hex}', + f'lens: security reviewed at {hex[:10]}'): + with self.subTest(second=second): + self.assertIn('2 times', SOURCE.lens_problem(post(first + second))) + self.assertEqual(SOURCE.reviewed_head(pr(post(first + second)))[:2], (True, None)) + for note in ('Lens — security: nothing found', 'the security lens — see above', f'see lens= {hex} later', + f" LENS = 'lens: correctness · reviewer: a · read at: {hex[:7]}'"): # test code in a report + with self.subTest(note=note): # no sha, or the field is not at the line start: still one valid read + self.assertIsNone(SOURCE.lens_problem(post(first + note))) + + def test_plain_lines_follow_githubs_fences(self): # issue #303 point 3: the same fence rule as unquoted_lines + self.assertEqual(lens.plain_lines('a\n```\nx\n```js\nb\n```\nc'), ['a', 'c']) # ```js is code, not a close + self.assertEqual(lens.plain_lines('a\n```x```\nb'), ['a', '```x```', 'b']) # inline code, no fence + self.assertEqual(lens.plain_lines('a\n~~~ x ~~~\nb\n~~~\nc'), ['a', 'c']) # a tilde info string may hold one + self.assertEqual(lens.plain_lines('a\n````\n```\nb\n````\nc'), ['a', 'c']) + self.assertEqual(lens.plain_lines('a\n```\nb'), ['a']) # unclosed: to the end + # the rendered `safe to merge` line below the inner fence is plain text, and blocks + self.assertIsNotNone(SOURCE.lens_problem(post('Notes\n```\nx\n```py\ny\n```\nsafe to merge: no\n```'))) + class NotALens(unittest.TestCase): """Issue #77: below a `not a lens:` first line, a lens read written another way (no colon after `lens`, another @@ -154,6 +176,54 @@ def test_the_queues_quote_of_any_lens_field_never_reads_as_a_lens_line(self): self.assertFalse(lens.loose_header(lens.norm_line(quoted)), quoted) self.assertIsNone(self.problem(f'Auto-merge OFF: {quoted}'), quoted) + def test_the_queues_quote_of_nested_markup_never_reads_as_a_lens_line(self): # issue #303 point 1 + for field in (':', '=', '—', '–'): + for line in (f'lens<b>{field} sec {self.HEX[:10]} NOT SAFE', f'lens[[](z)](w){field} sec {self.HEX}', + f'lens<<b>c>{field} sec {self.HEX[:10]}', f'lens[[[](z)](y)](w){field} {self.HEX}', + f'read<b> at {self.HEX}', f'safe<b> to merge: no ({self.HEX[:10]})'): + with self.subTest(line=line): + quoted = lens.no_lens_text(line) + for narrow in (False, True): + self.assertFalse(lens.loose_header(lens.norm_line(quoted, narrow)), quoted) + self.assertIsNone(self.problem(f'pr_queue turned auto-merge OFF: {quoted}'), quoted) + + def test_the_queues_quote_of_any_text_reads_the_same_when_cleaned_again(self): # issue #303 point 1 + rnd = random.Random(303) + parts = ['lens', 'read', ' at', 'safe', ' to ', 'merge', ':', '=', '—', '–', '<', '>', '', ' the security lens — fixed in {self.HEX[:8]}' # a quote does not help + self.assertIn(lens.EMBEDDED, self.problem(quoted)) + self.assertIsNone(self.problem(f'not a lens: round 2\nthe security lens — fixed in:\n{self.HEX[:8]}')) + self.assertIsNone(self.problem(f'not a lens: round 2\nthe security lens: fixed.\n> read at {self.HEX}')) + + def test_a_quote_marker_after_a_tab_is_code_not_a_quote(self): # #283 bypass M9: `\s*>` would clear it + self.assertIsNotNone(self.problem(f'not a lens: notes\n\n\t> read at {self.HEX}')) + + def test_only_a_fence_of_the_same_kind_and_length_closes_one(self): # #283 bypass M10: any fence line closed + for body in (f'not a lens: notes\n~~~\n```\n> read at {self.HEX}\n~~~', + f'not a lens: notes\n````\n```\n> read at {self.HEX}\n````', + f'not a lens: notes\n```\n~~~\n> read at {self.HEX}\n```'): + with self.subTest(body=body): + self.assertIn(lens.OPT_OUT_READ, self.problem(body)) + + def test_a_fence_line_with_an_info_string_does_not_close_a_fence(self): # issue #303 point 3, GFM + for close in ('``` y', '```js', '~~~ y'): + body = (f'not a lens: r2\n{close[:3]}\nx\n{close}\n> correctness lens NOT SAFE read at {self.HEX}\n' + f'{close[:3]}') + with self.subTest(close=close): + self.assertIn(lens.OPT_OUT_READ, self.problem(body)) + self.assertIsNone(self.problem(f'not a lens: r2\n```\nx\n``` \n> read at {self.HEX}')) # blanks only: closes + def test_the_way_out_names_the_quote_and_never_reads_as_a_report(self): self.assertIn('`>`', lens.NO_HEADER_WAY_OUT) self.assertEqual(lens.no_lens_text(lens.NO_HEADER_WAY_OUT, keep_markdown=True), lens.NO_HEADER_WAY_OUT) @@ -222,6 +292,14 @@ def test_advice_that_holds_a_lens_word_is_cleaned_like_any_text(self): # also for text, out in (('`lens: x`', 'lens- x'), ('re`ad at`: x', 'read @: x'), ('**safe to merge**', 'safe to land')): self.assertEqual(lens.no_lens_text(text, keep_markdown=True), out) + def test_advice_whose_narrow_reading_holds_a_lens_word_is_cleaned(self): # issue #303: the reader reads both ways + text = '' # one tag read the wide way; ` Date: Fri, 20 Nov 2026 04:27:47 +0000 Subject: [PATCH 2/2] pr-queue: one-line quoted errors, fence tests, README format and code-block note (#591 lenses) Co-Authored-By: Claude Opus 5.5 --- fork-ci/actions/pr-queue/README.md | 6 ++++-- fork-ci/actions/pr-queue/lens.test.py | 11 +++++++++++ fork-ci/actions/pr-queue/pr_queue.py | 4 +++- fork-ci/actions/pr-queue/pr_queue.test.py | 9 +++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 2e0c9355e3ab2..167e5a04653ba 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -284,11 +284,13 @@ Fixed in: A comment holds one lens: below a valid header, a line that starts with `lens:`, `lens —`, `lens –` or `lens=` and names a sha is a second header, and the comment reads nothing. (`LENS = '...'`, with a blank before the `=`, is no -second header: a report's test code assigns sample headers that way.) +second header: a report's test code assigns sample headers that way.) Lines in +code blocks count too, so a report quotes sample headers with placeholders +(``), never a real-looking sha (seven or more hex digits). Fenced blocks are read as GitHub renders them: only a line of the same character, at least as long and with nothing after it, closes a fence -(```` ```js ```` inside an open fence is code), and a backtick line with +(` ```js ` inside an open fence is code), and a backtick line with another backtick after it is inline code, not a fence. A comment that looks like a report but is not one valid read is a lens of its diff --git a/fork-ci/actions/pr-queue/lens.test.py b/fork-ci/actions/pr-queue/lens.test.py index 1e41710c465ee..70f46e810af35 100644 --- a/fork-ci/actions/pr-queue/lens.test.py +++ b/fork-ci/actions/pr-queue/lens.test.py @@ -224,6 +224,17 @@ def test_a_fence_line_with_an_info_string_does_not_close_a_fence(self): # issu self.assertIn(lens.OPT_OUT_READ, self.problem(body)) self.assertIsNone(self.problem(f'not a lens: r2\n```\nx\n``` \n> read at {self.HEX}')) # blanks only: closes + def test_a_longer_closing_fence_closes_one_and_only_blanks_may_follow_it(self): # GFM; #591 lens mutants + self.assertIsNone(self.problem(f'not a lens: r2\n```\nx\n````\n> read at {self.HEX}')) + # a no-break space is no space or tab: the fence stays open, the quote is code + self.assertIn(lens.OPT_OUT_READ, self.problem(f'not a lens: r2\n```\nx\n```\u00a0\n> read at {self.HEX}')) + + def test_a_fence_opens_and_closes_only_after_at_most_3_spaces(self): # GFM; #591 lens mutants + self.assertIn(lens.OPT_OUT_READ, self.problem(f'not a lens: r2\n ```\n> read at {self.HEX}')) + self.assertIsNone(self.problem(f'not a lens: r2\n ```\n\n> read at {self.HEX}')) # indented code, no fence + self.assertIn(lens.OPT_OUT_READ, + self.problem(f'not a lens: r2\n```\nx\n ```\n> read at {self.HEX}\n```')) + def test_the_way_out_names_the_quote_and_never_reads_as_a_report(self): self.assertIn('`>`', lens.NO_HEADER_WAY_OUT) self.assertEqual(lens.no_lens_text(lens.NO_HEADER_WAY_OUT, keep_markdown=True), lens.NO_HEADER_WAY_OUT) diff --git a/fork-ci/actions/pr-queue/pr_queue.py b/fork-ci/actions/pr-queue/pr_queue.py index 9a64f40cc907c..3e4cd509692eb 100755 --- a/fork-ci/actions/pr-queue/pr_queue.py +++ b/fork-ci/actions/pr-queue/pr_queue.py @@ -1481,7 +1481,9 @@ def leave_off(self, n, why, advice=''): text) is cleaned of them and of markdown; `advice`, the queue's own text from the config (a command in backticks, a `` placeholder), keeps its markdown unless it holds one (lens.no_lens_text). 0, or SILENT when the comment failed (the caller keeps STATE, so the next run says it).""" - why = lens.no_lens_text(why) + (' ' + lens.no_lens_text(advice, keep_markdown=True) if advice else '') + # One line: a multi-line gh error could start a line with `covered:`, `checks:` or a heading naming a lens. + why = lens.no_lens_text(' '.join(why.split())) + why += ' ' + lens.no_lens_text(advice, keep_markdown=True) if advice else '' print(f'#{n}: auto-merge left OFF: {why}') r = self.gh_write('pr', 'comment', str(n), '--repo', self.repo, '--body', f'pr_queue turned auto-merge OFF: {why}\nNeeds a lens read of any new commits, then ' diff --git a/fork-ci/actions/pr-queue/pr_queue.test.py b/fork-ci/actions/pr-queue/pr_queue.test.py index 8c5abddd1737e..cee3a3483c821 100644 --- a/fork-ci/actions/pr-queue/pr_queue.test.py +++ b/fork-ci/actions/pr-queue/pr_queue.test.py @@ -610,6 +610,15 @@ def test_failed_update_or_arm_stays_off(self): self.assertIn('back on', f.comments[0]) self.assertNotRegex(f.comments[0], r'(?i)read at\s*:', 'the quoted gh error had one') + def test_a_multi_line_gh_error_is_quoted_on_one_line(self): # no `covered:`/`checks:` line or lens heading + f = self.fake() + self.q.gh = self.q.gh_write = f + self.assertEqual(run_quiet(self.q.leave_off, 7, 'gh failed\ncovered: x\nchecks: y\n# security lens')[0], 0) + why, needs = f.comments[0].split('\n') + self.assertTrue(why.startswith('pr_queue turned auto-merge OFF: gh failed covered'), why) + self.assertIn('checks', why) + self.assertTrue(needs.startswith('Needs a lens read'), needs) + def test_a_failed_comment_keeps_the_state(self): # still OFF and silent: the run fails, the next run says it f = self.fake('resolved', fail=('comment',)) self.assertEqual(self.update(f)[0], Q.SILENT)