From e9090698e0b106dcf0fa77c9696458fd4a8a1a36 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:37:57 +0100 Subject: [PATCH 1/3] fix(fork-ci): only a comment with the lens marker is a lens report (#865) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The merge gate read any comment that looked like a lens report (a `## Lens A` heading, `safe to merge`, `covered:`/`checks:` lines) as a broken report, and held the head until someone deleted or edited it. Now a comment is a lens report only when it carries the lens marker: a line that starts with the lens field (`lens:`, `lens=`, `lens —`, `lens –`), names a read (`read at` and a hex sha), or has a lens field with a hex sha after it, read with Markdown stripped, in code blocks and quotes too. A lens report that is not one valid read still blocks, exactly as before. A look-alike without the marker neither reads nor blocks: the run log and the head check's summary name it as "not a lens report" with the reason, and a required lens it was meant to be still fails as missing. One rule on both sides: lens.has_marker and its TS port hasMarker, with new shared `scans` vectors (a `not_lens` field) both sides replay. The review kit's `check` reads the same rule (`not a lens, no lens marker`), and COMMENTS.md defines the marker with checked examples. Co-Authored-By: Claude Opus 5.5 --- .../src/fork/reviewRules/lensComment.ts | 55 ++++- .../src/fork/reviewRules/reviewRules.test.ts | 41 +++- fork-ci/RELEASE-NOTES.md | 14 ++ fork-ci/actions/head-check/README.md | 6 +- fork-ci/actions/head-check/head_check.py | 10 +- fork-ci/actions/head-check/head_check.test.py | 33 ++- fork-ci/actions/pr-queue/README.md | 31 ++- fork-ci/actions/pr-queue/lens.py | 86 +++++-- fork-ci/actions/pr-queue/lens.test.py | 144 +++++++++++- fork-ci/actions/pr-queue/pr_queue.test.py | 11 +- fork-ci/actions/pr-queue/review.vectors.json | 212 ++++++++++++++++-- fork-ci/actions/pr-queue/review_judge.test.py | 10 +- fork-kit/review/COMMENTS.md | 52 ++++- fork-kit/review/SKILL.md | 4 +- fork-kit/review/lib/review_kit.py | 2 + fork-kit/review/tests/comments.test.py | 12 +- 16 files changed, 634 insertions(+), 89 deletions(-) diff --git a/apps/server/src/fork/reviewRules/lensComment.ts b/apps/server/src/fork/reviewRules/lensComment.ts index 8f246736b9011..ee744d2a3cf2f 100644 --- a/apps/server/src/fork/reviewRules/lensComment.ts +++ b/apps/server/src/fork/reviewRules/lensComment.ts @@ -1,7 +1,7 @@ /** - * Port of lens.py's header rules and lens.Review.lens_problem/lens_scan (fork-ci/actions/pr-queue), held to the shared - * vectors and the gate's lens corpus. A comment that only looks like a report, or holds a second header, is a - * NO_HEADER entry that reads nothing, as in the gate. The caller picks the posts that count, in the gate's order. + * Port of lens.py's lens rules (fork-ci/actions/pr-queue), held to the shared vectors and the gate's corpus. A lens + * report (one with the lens marker) that is not one valid read is a NO_HEADER entry; a look-alike without the marker + * is no report (notLens). The caller picks the posts that count, in the gate's order. */ import { ALNUM, @@ -55,6 +55,8 @@ export const NO_HEADER = "comment without a first-line lens header"; export const EDITED = "edited after posting: post a new comment instead"; export const HIDDEN = "hidden: post a new comment instead"; export const EMBEDDED = "holds a lens header line"; +export const NO_MARKER = + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha)"; const OPT_OUT_READ = "says on its first line that it is no lens report, but holds a hex read-at sha outside a `>` quote"; @@ -193,6 +195,19 @@ function looseHeader(line: string): boolean { return !!m && HEX_RE.test(m[1]!); } +/** lens.marker_line: the line starts with the lens field, names a read (`read at `) or a lens field with a sha. */ +const markerLine = (line: string) => + FIELD_START_RE.test(line) || READ_AT_RE.test(line) || looseHeader(line); + +/** + * lens.has_marker: a line of the comment, in a code block or quote too, read either way, carries the lens marker. + * Only such a comment is a lens report (COMMENTS.md, "The lens marker"). + */ +export function hasMarker(body: string): boolean { + const lines = splitlines(body); + return [false, true].some((narrow) => lines.some((line) => markerLine(normLine(line, narrow)))); +} + const starts = (first: string) => `starts with ${repr(cut(strip(first), 60))}`; /** lens.Review.read_problem: lensProblem's rules with one way of reading tags and links. */ @@ -236,11 +251,26 @@ function readProblem(body: string, narrow: boolean): string | null { } /** - * lens.Review.lens_problem: why a comment that looks like a lens report is not one valid read, or null. Every line - * counts, in fences and quotes too; read both ways (narrow or not). An override comment (` <40-hex sha>:`) - * never counts. + * lens.Review.lens_problem: why a lens report (a comment with the lens marker) is not one valid read, so it blocks; + * null when it is one, carries no marker, or does not look like a report. */ export function lensProblem(body: string, overridePrefix?: string): string | null { + const problem = looksProblem(body, overridePrefix); + return problem && hasMarker(body) ? problem : null; +} + +/** lens.Review.not_lens_report: why a comment that looks like a lens report is none (no lens marker), or null. */ +export function notLensReport(body: string, overridePrefix?: string): string | null { + const problem = looksProblem(body, overridePrefix); + return problem && !hasMarker(body) ? `${NO_MARKER}; it looks like one: ${problem}` : null; +} + +/** + * lens.Review.looks_problem: why a comment that looks like a lens report is not one valid read, with or without the + * marker, or null. Every line counts, in fences and quotes too; read both ways (narrow or not). An override comment + * (` <40-hex sha>:`) never counts. + */ +export function looksProblem(body: string, overridePrefix?: string): string | null { if ( overridePrefix !== undefined && body.startsWith(`${overridePrefix} `) && @@ -276,16 +306,23 @@ export interface LensScan { readonly history: Array<[string, string | null]>; /** Each lens key's newest [sha or null, why it reads nothing or null]. */ readonly entries: Record; + /** [where, why] of each post that looks like a report but has no lens marker (lens.Review.not_lens_reports). */ + readonly notLens: Array<[string, string]>; } /** lens.Review.lens_scan on posts that count, with the repository's override prefix. */ export function lensScan(posts: ReadonlyArray, overridePrefix?: string): LensScan { const history: Array<[string, string | null]> = []; const entries: Record = {}; + const notLens: Array<[string, string]> = []; posts.forEach((post, i) => { - const problem = lensProblem(post.body, overridePrefix); + const problem = looksProblem(post.body, overridePrefix); + const where = post.where ?? `post ${i + 1}`; + if (problem && !hasMarker(post.body)) { + notLens.push([where, `${NO_MARKER}; it looks like one: ${problem}`]); + return; + } if (problem) { - const where = post.where ?? `post ${i + 1}`; entries[`${NO_HEADER} (${where}, ${problem}${post.hidden ? ", hidden" : ""})`] = [null, null]; return; } @@ -295,5 +332,5 @@ export function lensScan(posts: ReadonlyArray, overridePrefix?: string const why = post.hidden ? HIDDEN : post.edited ? EDITED : null; entries[lensKey(header[0])] = why ? [null, why] : [header[1], null]; }); - return { history, entries }; + return { history, entries, notLens }; } diff --git a/apps/server/src/fork/reviewRules/reviewRules.test.ts b/apps/server/src/fork/reviewRules/reviewRules.test.ts index ccba74f148b5c..1eb1f3d987efe 100644 --- a/apps/server/src/fork/reviewRules/reviewRules.test.ts +++ b/apps/server/src/fork/reviewRules/reviewRules.test.ts @@ -11,10 +11,14 @@ import { EMBEDDED, HIDDEN, NO_HEADER, + NO_MARKER, + hasMarker, lensHeader, lensKey, lensProblem, lensScan, + looksProblem, + notLensReport, } from "./lensComment.ts"; import { ReviewPlanError, globMatches, planReview, type ReviewBlock } from "./plan.ts"; import { repr, splitlines } from "./pyText.ts"; @@ -47,7 +51,7 @@ const FIELDS: Record | null> = { globs: null, cases: ["name", "config", "changes", "weight", "lenses", "hits", "protected"], findings: ["name", "group", "body", "findings", "section"], - scans: ["name", "posts", "history", "entries"], + scans: ["name", "posts", "history", "entries", "not_lens"], rounds: [ "name", "config", @@ -150,7 +154,11 @@ describe("the shared vectors", () => { it("every scan", () => { assert.isAtLeast(V.scans.length, 31); for (const s of V.scans) - assert.deepStrictEqual(scan(s), { history: s.history, entries: s.entries }, s.name); + assert.deepStrictEqual( + scan(s), + { history: s.history, entries: s.entries, notLens: s.not_lens ?? [] }, + s.name, + ); }); it("every round", () => { @@ -208,7 +216,7 @@ describe("rounds meet old, repeated, edited, deleted and empty state", () => { ); }); it("a pull request with no lens comments is round 0 and passes", () => { - assert.deepStrictEqual(lensScan([]), { history: [], entries: {} }); + assert.deepStrictEqual(lensScan([]), { history: [], entries: {}, notLens: [] }); const r = replayRound( named("rounds", "a pull request with no lens comments is round 0 and passes"), ); @@ -245,6 +253,33 @@ describe("rounds meet old, repeated, edited, deleted and empty state", () => { assert.lengthOf(Object.keys(reposted.entries), 2); assert.include(Object.keys(reposted.entries)[0], EMBEDDED); }); + it("a look-alike without the lens marker is no lens report; one with it still blocks (#865)", () => { + const near = scan( + named("scans", "a lens heading with no lens marker is no lens report (issue 865)"), + ); + assert.deepStrictEqual([near.history, near.entries], [[], {}]); + assert.lengthOf(near.notLens, 1); + assert.include(near.notLens[0]![1], NO_MARKER); + const read = scan( + named("scans", "a lens heading that names a read carries the marker and reads nothing"), + ); + assert.isTrue(Object.keys(read.entries)[0]!.startsWith(NO_HEADER)); + assert.deepStrictEqual(read.notLens, []); + const beside = scan( + named("scans", "a near miss beside a report of the same lens and head leaves the read"), + ); + assert.deepStrictEqual(beside.entries, { code: ["a".repeat(40), null] }); + for (const body of [ + "## Lens A\nmajor: none", + "lgtm, safe to merge", + "Here.\nread at: 1234567", + ]) { + const looks = looksProblem(body); + assert.isNotNull(looks, body); + assert.strictEqual(lensProblem(body), hasMarker(body) ? looks : null, body); + assert.strictEqual(notLensReport(body) !== null, !hasMarker(body), body); + } + }); it("an override comment never reads as a lens report, with the repository's prefix only", () => { const body = named("scans", "an override comment that looks like a report is never one") .posts[0].body; diff --git a/fork-ci/RELEASE-NOTES.md b/fork-ci/RELEASE-NOTES.md index 1cfa9a5482f6d..48f70b747ea46 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -13,6 +13,20 @@ nothing. ## After ci/v14 +### pr-queue and head-check: only a comment with the lens marker is a lens report (#865) + +A comment counts as a lens report only when it carries the lens marker: a line that starts with the lens field +(`lens:`, `lens=`, `lens —`, `lens –`), names a read (`read at` and a hex sha), or has a lens field with a hex sha after +it (Markdown stripped, in code blocks and quotes too). A lens report that is not exactly one valid read still blocks, as +before. A comment that only looks like one without the marker (a `## Lens A` heading, `safe to merge`, `covered:` and +`checks:` lines) no longer blocks: the run log and the head check's summary name it as `not a lens report` with the +reason. Comments with the marker read exactly as before. T3's copy (`apps/server/src/fork/reviewRules`) and the review +kit's `check` read the same rule from the shared vectors. + +**Upgrade:** a lens report written without the marker now counts for nothing, so a lens that posts one has not +reported: list required lenses (`required-lenses`, or a `review` block in `enforce`) so a missing read still fails the +head check, and have lenses run the kit's `check` before posting. + ### pr-queue: what counts as a `state:` line is gate code (#797) `review_judge.has_state_line` holds the rule for a lens report's `state:` line (an answer after the colon, outside code diff --git a/fork-ci/actions/head-check/README.md b/fork-ci/actions/head-check/README.md index 702c74de21c3f..02c91cadeeab1 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -214,7 +214,11 @@ labels or changed paths, say) and pass it in. The log and the job summary list each lens with `ok` or `fail` and a short reason (the sha it read, an override, edited, hidden, a short sha, required -but missing). +but missing). A comment that looks like a lens report but carries no lens +marker (the pr-queue README, "Lens comments") is no lens report: it gets a row +`not a lens report ()`, `ok`, with the reason, and never fails the +check; a required lens it was meant to be still fails as missing, and the +reason says how many such comments there are. | Exit | Meaning | | ---- | -------------------------------------------------------------------------------- | diff --git a/fork-ci/actions/head-check/head_check.py b/fork-ci/actions/head-check/head_check.py index 03adf131c7704..ee2a4c10a3a82 100644 --- a/fork-ci/actions/head-check/head_check.py +++ b/fork-ci/actions/head-check/head_check.py @@ -213,8 +213,10 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l reviewed, read, why = review.reviewed_head(pr) missing = [name for key, name in required.items() if key not in reads] found = ', '.join(sorted(reads)) or 'none' + # comments that look like a lens report but carry no lens marker: no report, so they pass; named, never silent + notes = [(f'{lens.NOT_LENS} ({where})', True, why) for where, why in review.not_lens_reports(pr)] if not reads and not required: - return True, 'no lens comments and no required lens: nothing to compare', [] + return True, 'no lens comments and no required lens: nothing to compare', notes ok, how = same_change(checkout, head, read) if reviewed and read else (False, None) rows = [(name, False, f'required: no lens comment of a counted author has this name (lenses found: {found})') for name in missing] @@ -226,10 +228,14 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l else: text = f'{"override " if override else "read "}{sha[:12]}: {how}' rows.append(((f'{key} (required)' if key in required else key), bool(sha and read and ok), text)) + rows += notes if missing: where = ' or the review rules of the config' if rules_name_lenses else '' + near = (f'; {len(notes)} comment(s) look like a lens report but carry no lens marker, so they are not one ' + f'(rows "{lens.NOT_LENS}")') if notes else '' return False, (f'required lens without a read: {", ".join(missing)}. No counted lens comment has that name: ' - f'check it in required-lenses (one name per line){where}; lenses found: {found}'), rows + f'check it in required-lenses (one name per line){where}; lenses found: {found}' + f'{near}'), rows if not read: return False, why, rows return ok, how, rows diff --git a/fork-ci/actions/head-check/head_check.test.py b/fork-ci/actions/head-check/head_check.test.py index 6902dee39ee6f..245d37eca13e5 100644 --- a/fork-ci/actions/head-check/head_check.test.py +++ b/fork-ci/actions/head-check/head_check.test.py @@ -385,15 +385,31 @@ def test_a_bot_counts_for_nothing_even_as_owner(self): self.assertTrue(self.verdict([self.p.lens('correctness', A), self.p.lens('x', B, login=login)])[0]) def test_an_old_format_report_reads_nothing(self): # old state: reports from before the fixed grammar - for body in (f'## Correctness {LENS}\nsafe to merge: yes', f'Review (correctness) read at: {A}', - f'```\n{LENS}: correctness · read at: {A}\n```', 'covered: all\nchecks: ran the tests'): - with self.subTest(body=body): + for body in (f'## Correctness {LENS}\nread at: {A}', f'Review (correctness) read at: {A}', + f'```\n{LENS}: correctness · read at: {A}\n```', f'covered: all\n{LENS}: correctness'): + with self.subTest(body=body): # each carries the lens marker: a lens report, broken, so it blocks ok, _, rows = self.verdict([self.p.lens('correctness', A), self.p.post(body)]) self.assertFalse(ok) self.assertIn(lens.NO_HEADER, ' '.join(name for name, _, _ in rows)) + def test_a_look_alike_without_the_lens_marker_passes_and_is_named(self): # issue #865 + for body in (f'## Correctness {LENS}\nsafe to merge: yes', 'covered: all\nchecks: ran the tests', + f'## {LENS.title()} A\nblocker: none\nmajor: none'): + with self.subTest(body=body): + ok, why, rows = self.verdict([self.p.lens('correctness', A), self.p.post(body)]) + self.assertTrue(ok, why) + self.assertEqual([(name.split(' (')[0], good) for name, good, _ in rows], + [('correctness', True), (lens.NOT_LENS, True)]) + self.assertIn(lens.NO_MARKER, rows[1][2]) + ok, why, rows = self.verdict([self.p.post(body)]) # alone: no lens comments, still named + self.assertTrue(ok, why) + self.assertEqual([(name.split(' (')[0], good) for name, good, _ in rows], [(lens.NOT_LENS, True)]) + ok, why, rows = self.verdict([self.p.post(body)], required='correctness') # fail closed + self.assertFalse(ok) + self.assertIn('carry no lens marker', why) + def test_a_deleted_comment_counts_no_more(self): # deleted: GitHub no longer lists it - look_alike = self.p.post('safe to merge') + look_alike = self.p.post(f'read at: {A[:7]}') good = self.p.lens('correctness', A) self.assertFalse(self.verdict([look_alike, good])[0]) self.assertTrue(self.verdict([good])[0]) @@ -2185,7 +2201,7 @@ def test_an_inline_look_alike_or_a_changed_inline_lens_fails(self): # reads no for node, says in ((self.inline_lens(self.read[:7]), 'reads nothing'), (self.inline_lens(self.read, includesCreatedEdit=True), 'edited after posting'), (self.inline_lens(self.read, isMinimized=True), 'hidden'), - (inline_node('safe to merge'), 'reads nothing')): + (inline_node(f'read at: {self.read}'), 'reads nothing')): with self.subTest(node=node['body'][:30], says=says): code, out = run_cli(self.path, fake_gh((0, bare), flags=[flags_page(inline=[node])])) self.assertEqual(code, 1, out) @@ -2242,6 +2258,13 @@ def test_more_than_100_inline_comments_are_all_read(self): self.assertEqual(code, 1, out) self.assertIn('could not read the pull request', out) + def test_a_near_miss_passes_and_the_summary_names_it(self): # issue #865 + answer = json.dumps(pr([self.p.lens('correctness', self.read), self.p.post('## Lens A\nmajor: none')], + head=self.read)) + code, out = run_cli(self.path, fake_gh((0, answer)), env=self.env) + self.assertEqual(code, 0, out) + self.assertRegex(self.read_file('summary.md'), rf'\| {lens.NOT_LENS} \([^|]*\) \| ok \| no lens marker') + def test_pass_and_fail_reach_the_exit_code_summary_and_output(self): code, out = run_cli(self.path, fake_gh((0, self.good)), env=self.env) self.assertEqual(code, 0, out) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index ea2b377c8e92a..3e31cc7d06729 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -555,12 +555,23 @@ resolved comment still counts. Its ways out are the same as any comment's (delete it, `not a lens: ...`, or an override). The grammar is fixed: a project writes its lens reports this way, it does not -configure another way. It fails closed. A comment that looks like a lens report -but is not exactly one valid read counts as a lens that read nothing, so the -queue never takes a reviewed pull request for an unreviewed one. Looking like a -report means any of: `lens:`, `read at`, `safe to merge`, a `## ... lens` -heading near the top, or two `covered:`/`checks:` lines. A comment that is no -report says so on its first line, `not a lens: ...`. That clears it unless one of +configure another way. A comment is a lens report only when it carries the lens +marker: a line (Markdown stripped, in a code block or quote too) that starts +with the lens field (`lens:`, `lens=`, `lens —` or `lens –`), names a read +(`read at` and a hex sha), or has a lens field with a hex sha after it anywhere. +On a lens report the rules fail closed: one that is not exactly one valid read +counts as a lens that read nothing, so the queue never takes a reviewed pull +request for an unreviewed one. A comment without the marker is no lens report, +however much it looks like one (a `## ... lens` heading near the top, +`safe to merge`, `lens:` in mid-line, or two `covered:`/`checks:` lines): it +neither reads nor blocks, the run log names it, and the head check's summary +lists it as `not a lens report` with the reason (issue 865: such a heading, +posted from the owner's account, held pull requests with no one seeing why). A +lens whose report has no marker has therefore posted nothing: a required lens +still has no read, and the head check fails on that. Lenses check their +comment with the review kit's `check` before posting (fork-kit/review). A +comment that is no report but holds a marker says so on its first line, +`not a lens: ...`. That clears it unless one of its lines is a lens header, a lens field with a sha (`lens:`, `lens=`, `lens —` 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 @@ -591,16 +602,16 @@ 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 +A lens report (a comment with the marker) that 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. The ways out: delete it, edit its first line to `not a lens: ...` with no lens header line left in it and any `read at ` quoted with `>`, or post an override for the head. These shapes were measured on this repository's 677 pull request comments by -people (November 2026): 25 are flagged, before and after the `not a lens:` -rule above. Of the 25, 7 are real lens reports with a broken header (one of +people (November 2026, before the lens marker rule): 25 are flagged, before and +after the `not a lens:` rule above. Of the 25, 7 are real lens reports with a broken header (one of them NOT SAFE), caught by the `## ... lens` heading rule (6) or a hex `read at` (1); 13 are fix-round comments caught by the same heading rule and 5 fix-round comments with a `lens:` or `read at` in their text, and diff --git a/fork-ci/actions/pr-queue/lens.py b/fork-ci/actions/pr-queue/lens.py index 1a1fd5200b69b..39821dc48346a 100644 --- a/fork-ci/actions/pr-queue/lens.py +++ b/fork-ci/actions/pr-queue/lens.py @@ -64,10 +64,11 @@ # `lens:`, a `read at:` or `read at `, `safe to merge`, or in its first TOP_LINES plain lines a Markdown heading # naming a lens (LOOKS_HEADING_RE reads the raw line: normalising drops `#`), or two `covered:`/`checks:` field lines; # on ANY line, fenced, indented or quoted too, a `read at` with a hex sha, a header line or a `lens:` field with any hex -# sha (loose_header). Such a comment without a valid first-line header is a lens that read nothing. So is a comment -# with two or more header lines (one comment per lens). A round, fix or note comment says so on its first line, -# `not a lens: ...`; that clears it only when none of its lines is a header line or a lens field with a sha, and no line -# outside a `>` quote (a fence or an indented block is no quote) holds a hex `read at` (unquoted_lines, issue #77). +# sha (loose_header). Such a comment without a valid first-line header is a lens that read nothing when it carries the +# lens marker (has_marker), and no lens report at all without it (issue #865). So is a comment with two or more header +# lines (one comment per lens). A round, fix or note comment says so on its first line, `not a lens: ...`; that clears +# it only when none of its lines is a header line or a lens field with a sha, and no line outside a `>` quote (a fence +# or an indented block is no quote) holds a hex `read at` (unquoted_lines, issue #77). LOOKS_RE = re.compile(r'\blens\s*:|\bread[\s-]*at\b\s*(?::|[0-9a-f]{7})|\bsafe\s+to\s+merge\b', re.I) NOT_A_LENS_RE = re.compile(r'not\s+a\s+lens\s*:', re.I) FIELD_LINE_RE = re.compile(r'(?:covered|checks)\s*:', re.I) @@ -75,6 +76,9 @@ TOP_LINES = 5 # Any hex sha with a digit (7-40 hex, not part of a longer word): `abc1234`, never `defaced` or `facade1x`. HEX_RE = re.compile(r'(?` quote keeps such a line from counting.""" + field spelling) looks like a report too; only a `>` quote keeps such a line from counting. What a comment looks + like is looks_problem; it blocks only with the lens marker (issue #865, class Marker).""" HEX = '7838aaec7c3cb4b6deaafa3d8cd701dd6f737f9a' def problem(self, body): - return SOURCE.lens_problem(post(body)) + return SOURCE.looks_problem(post(body)) def test_a_lens_line_without_the_colon_below_the_opt_out_blocks(self): for read in (self.HEX, self.HEX[:10], 'abc1234'): @@ -240,6 +253,116 @@ def test_the_way_out_names_the_quote_and_never_reads_as_a_report(self): self.assertEqual(lens.no_lens_text(lens.NO_HEADER_WAY_OUT, keep_markdown=True), lens.NO_HEADER_WAY_OUT) +class Marker(unittest.TestCase): + """Issue #865: a comment is a lens report only when it carries the lens marker (lens.has_marker: a line starting + `lens:`, a lens field naming a sha, or `read at `). One that only looks like a report without it is no lens + report: it neither reads nor blocks, and not_lens_reports names it (the head check's summary). A lens report that + is not one valid read still blocks.""" + READ = f'lens: correctness · reviewer: x · read at: {SHA_B}\nstate: fine\nblocker: none\nmajor: none' + NEAR = ('## Lens A\nblocker: none\nmajor: none', '## Lens correctness\nsafe to merge: yes', 'lgtm, safe to merge', + 'covered: a.py\nchecks: ran the tests', 'The merge-path lens: nothing found', + '**Lens correctness** (round 2)\nverdict: not safe to merge') + BROKEN = (f'Here is my review.\n{READ}', # the header not on the first line + f'{READ}\nlens: state · reviewer: x · read at: {SHA_B}', # two lenses in one comment + 'lens: · reviewer: x · read at: \nmajor: none', # a placeholder name: names no lens + f'## Lens A\nread at: {SHA_B}\nmajor: none', # a lens heading that names a read + f'reviewer: lens-a · read at: {SHA_B[:7]}', # a read, short sha, no lens field + f'Report — lens: code at {NotALens.HEX[:10]}', # a lens field naming a sha mid-line + f'```\n{READ}\n```') # in a code block + + def setUp(self): + self.lines = [] + self.r = lens.Review((), 'tool ready --head', 'OWNER', ('OWNER',), log=self.lines.append) + + def test_a_near_miss_is_no_lens_report_and_is_named(self): + for body in self.NEAR: + with self.subTest(body=body): + self.assertFalse(lens.has_marker(body)) + self.assertIsNotNone(self.r.looks_problem(post(body)), 'it looks like a report') + self.assertIsNone(self.r.lens_problem(post(body)), 'but blocks nothing') + self.assertIn(lens.NO_MARKER, self.r.not_lens_report(post(body))) + self.assertEqual(self.r.reviewed_head(pr(post(body))), (False, None, 'no lens comments')) + p = pr(post(self.READ), post(body, url='https://github.test/c2', when='2026-01-02T00:00:00Z')) + self.assertEqual(self.r.reviewed_head(p), (True, SHA_B, 'every lens read it')) + self.assertEqual([w for w, _ in self.r.not_lens_reports(p)], ['https://github.test/c2']) + self.assertEqual(self.r.lens_scan(p)[1], [('correctness', SHA_B)], 'no round either') + + def test_a_lens_report_with_a_broken_body_still_blocks(self): # fail closed: never a pass + for body in self.BROKEN: + with self.subTest(body=body): + self.assertTrue(lens.has_marker(body)) + self.assertIsNotNone(self.r.lens_problem(post(body))) + self.assertIsNone(self.r.not_lens_report(post(body))) + p = pr(post(self.READ), post(body, when='2026-01-02T00:00:00Z')) + self.assertEqual(self.r.reviewed_head(p)[:2], (True, None)) + self.assertEqual(self.r.not_lens_reports(p), []) + + def test_a_valid_report_and_a_plain_comment_read_as_before(self): # old comments on open PRs: same answers + self.assertIsNone(self.r.lens_problem(post(self.READ))) + self.assertIsNone(self.r.not_lens_report(post(self.READ))) + self.assertIsNone(self.r.not_lens_report(post('Thanks, merging after CI.'))) + self.assertEqual(self.r.reviewed_head(pr(post(self.READ))), (True, SHA_B, 'every lens read it')) + opt_out = f'not a lens: round 2\n> read at {SHA_B}' + self.assertEqual((self.r.lens_problem(post(opt_out)), self.r.not_lens_report(post(opt_out))), (None, None)) + + def test_every_problem_with_the_marker_is_the_old_answer(self): # the marker only ever drops a block + for body in self.NEAR + self.BROKEN + (self.READ, 'Thanks', f'not a lens: x\nread at: {SHA_B}'): + with self.subTest(body=body): + looks, now = self.r.looks_problem(post(body)), self.r.lens_problem(post(body)) + self.assertEqual(now, looks if lens.has_marker(body) else None) + self.assertEqual(self.r.not_lens_report(post(body)) is not None, looks is not None and now is None) + + def test_the_marker_is_read_both_ways_and_in_any_markdown(self): + for body in ('**Lens:** a', '## lens: a', '- lens: a', '> lens: a', ' lens: a', f'| read at | {SHA_B} |', + f'read at: `{SHA_B[:7]}`', f'lens: x · read at: {SHA_B}', + 'Lens — a', 'lens= a'): + with self.subTest(body=body): + self.assertTrue(lens.has_marker(body)) + for body in ('lensing: a', 'the lens: a', 'read at: the old head', 'lenses: a', 'not a lens: a', 'LENS = x'): + with self.subTest(body=body): + self.assertFalse(lens.has_marker(body)) + + def test_edited_and_hidden_near_misses_stay_no_report(self): + for flags in ({'includesCreatedEdit': True}, {'isMinimized': True}, {'includesCreatedEdit': ...}): + with self.subTest(flags=flags): + p = pr(post(self.READ), post(self.NEAR[0], when='2026-01-02T00:00:00Z', **flags)) + self.assertEqual(self.r.reviewed_head(p), (True, SHA_B, 'every lens read it')) + self.assertEqual(len(self.r.not_lens_reports(p)), 1) + + def test_a_report_edited_to_drop_its_marker_is_as_if_deleted(self): # GitHub keeps no old text: only now counts + dropped = post(self.NEAR[0].replace('Lens A', 'Lens correctness'), when='2026-01-02T00:00:00Z', + includesCreatedEdit=True) + self.assertEqual(self.r.reviewed_head(pr(post(self.READ), dropped)), (True, SHA_B, 'every lens read it')) + kept = post(self.READ.replace(SHA_B, SHA_A), when='2026-01-02T00:00:00Z', includesCreatedEdit=True) + reviewed, sha, why = self.r.reviewed_head(pr(post(self.READ), kept)) + self.assertEqual((reviewed, sha), (True, None), 'an edited report with its marker still reads nothing') + self.assertIn(lens.EDITED, why) + + def test_two_comments_for_one_lens_and_head(self): + later = post(self.READ.replace('major: none', 'major: x is cut'), when='2026-01-02T00:00:00Z') + found, history = self.r.lens_scan(pr(post(self.READ), later)) + self.assertEqual(list(found), ['correctness']) + self.assertIs(found['correctness'][3], later, 'the newer report is the one judged') + self.assertEqual(history, [('correctness', SHA_B)] * 2) + near = post(f'## Lens correctness\nmajor: none\nsafe to merge: yes', when='2026-01-02T00:00:00Z') + found, history = self.r.lens_scan(pr(post(self.READ), near)) + self.assertIs(found['correctness'][3]['body'], self.READ, 'a near miss never replaces the report') + self.assertEqual(history, [('correctness', SHA_B)]) + + def test_a_near_miss_is_logged_once_and_quotes_only_its_start(self): + p = pr(post(self.NEAR[0], url='https://github.test/c1')) + self.r.reviewed_head(p) + self.r.reviewed_head(p) + self.assertEqual(len(self.lines), 1, self.lines) + self.assertTrue(self.lines[0].startswith(f'{lens.NOT_LENS} (https://github.test/c1): {lens.NO_MARKER}')) + + def test_a_strangers_near_miss_is_still_only_logged_as_ignored(self): + p = pr(stranger(self.NEAR[0], url='https://github.test/s1')) + self.assertEqual(self.r.not_lens_reports(p), []) + self.assertEqual(len(self.lines), 1) + self.assertIn('ignored a lens-looking post https://github.test/s1', self.lines[0]) + + class Markdown(unittest.TestCase): """clean_inline keeps the source's answers (`]*>` tags, `!?\\[([^\\]]*)\\]\\([^)]*\\)` links) in linear time.""" @@ -383,7 +506,8 @@ def test_a_strangers_look_alike_or_junk_comment_neither_vouches_nor_blocks(self) for junk in ('lgtm, safe to merge', 'looks fine, read at: deadbee1', f'read at: {SHA_A[:7]}', f'lens: correctness · reviewer: x · read at: {SHA_A[:7]}', f'lens: other · read at: {SHA_B}'): self.assertEqual(self.head(self.OWN, stranger(junk)), (True, SHA_A, 'every lens read it'), junk) - self.assertIsNotNone(self.R.lens_problem(post('lgtm, safe to merge')), 'the same text from the owner blocks') + self.assertIsNotNone(self.R.looks_problem(post('lgtm, safe to merge')), 'the same text from the owner looks') + self.assertIsNotNone(self.R.lens_problem(post(f'Hi\nlens: other · read at: {SHA_B}')), 'this one blocks') def test_a_hidden_lens_comment_reads_nothing_until_that_lens_posts_again(self): # hidden (minimized) is how old review rounds are tidied away, so hiding must never make a reviewed PR look @@ -397,7 +521,7 @@ def test_a_hidden_lens_comment_reads_nothing_until_that_lens_posts_again(self): self.assertEqual(self.head(self.OWN, dict(newer, isMinimized=True))[:2], (True, None), 'a hidden newest read does not bring the older read back') self.assertEqual(self.head(hidden, newer), (True, SHA_B, 'every lens read it'), 'a new comment of the lens counts') - for junk in ('lgtm, safe to merge', f'lens: correctness · read at {SHA_B[:7]}'): # hidden look-alikes block too + for junk in (f'Review\nlens: x · read at: {SHA_B}', f'lens: correctness · read at {SHA_B[:7]}'): # hidden too self.assertEqual(self.head(post(junk, isMinimized=True))[:2], (True, None), junk) def test_hidden_posts_that_never_counted_stay_ignored(self): @@ -611,7 +735,7 @@ def test_a_strangers_review_is_ignored(self): def test_a_counted_authors_look_alike_review_blocks(self): own = post(f'lens: correctness · reviewer: x · read at: {SHA_A}', when='2026-01-01T00:00:00Z') - reviewed, sha, why = self.head([own], [self.review('lgtm, safe to merge')]) + reviewed, sha, why = self.head([own], [self.review(f'Review\nlens: design · read at: {SHA_A}')]) self.assertEqual((reviewed, sha), (True, None)) self.assertIn(lens.NO_HEADER, why) @@ -649,7 +773,7 @@ def test_the_newest_of_comments_and_inline_comments_counts(self): def test_a_counted_authors_inline_look_alike_blocks(self): own = post(self.READ_B) - for body in ('lgtm, safe to merge', f'lens: design · read at: {SHA_B[:7]}'): + for body in (f'Review\nlens: design · read at: {SHA_B}', f'lens: design · read at: {SHA_B[:7]}'): reviewed, sha, why = self.head([own], [self.inline(body)]) self.assertEqual((reviewed, sha), (True, None), body) diff --git a/fork-ci/actions/pr-queue/pr_queue.test.py b/fork-ci/actions/pr-queue/pr_queue.test.py index cacb535d410ea..233b088858717 100644 --- a/fork-ci/actions/pr-queue/pr_queue.test.py +++ b/fork-ci/actions/pr-queue/pr_queue.test.py @@ -3798,13 +3798,22 @@ def test_a_push_after_an_inline_lens_read_is_not_re_armed(self): # the head ho def test_an_inline_lens_look_alike_blocks_like_any_other(self): fence = '`' * 3 for body in (f'{fence}\n{LENS}: correctness · reviewer: x · read at: {self.c}\n{fence}', - 'this one is safe to merge', f'{LENS}: correctness · reviewer: x · read at: {self.c[:7]}'): + f'this one is safe to merge, read at {self.c}', + f'{LENS}: correctness · reviewer: x · read at: {self.c[:7]}'): with self.subTest(body=body): f = self.fake(inline=[inline_node(body)]) code, out = self.update(f) self.assertOff(f, code, 'unclear') self.assertFalse(f.updated) + def test_an_inline_look_alike_without_the_lens_marker_holds_nothing(self): # issue #865 + for n, body in enumerate(('this one is safe to merge', '## Lens A\nmajor: none'), 2): + with self.subTest(body=body): # each named once in the run log (a Review logs each post once) + f = self.fake(inline=[self.lens(self.c), inline_node(body, n=n)]) + code, out = self.update(f) + self.assertEqual((code, f.armed, f.comments), (0, self.up, []), out) + self.assertIn(lens.NOT_LENS, out) + def test_an_edited_or_hidden_inline_lens_reads_nothing(self): for change, why in (({'edited': True}, lens.EDITED), ({'hidden': True}, lens.HIDDEN)): with self.subTest(change=change): diff --git a/fork-ci/actions/pr-queue/review.vectors.json b/fork-ci/actions/pr-queue/review.vectors.json index 6a065e72e39dc..4216d863474f6 100644 --- a/fork-ci/actions/pr-queue/review.vectors.json +++ b/fork-ci/actions/pr-queue/review.vectors.json @@ -1,5 +1,5 @@ { - "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a post that only looks like a report is a `comment without a first-line lens header` entry that reads nothing). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", + "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a lens report, one with the lens marker, that is not one valid read is a `comment without a first-line lens header` entry that reads nothing; `not_lens`, when there is one: [where, why] of each post that looks like a report but has no lens marker, so is no lens report, as lens.Review.not_lens_reports names them). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", "config_path": ".github/pr-queue.json", "override_prefix": "override for head", "globs": [ @@ -1836,49 +1836,52 @@ "entries": {} }, { - "name": "headerless covered and checks fields read nothing", + "name": "headerless covered and checks fields are no lens report: no marker", "posts": [ { "body": "Review done.\ncovered: the gate\nchecks: tests" } ], "history": [], - "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with 'Review done.')": [ - null, - null + "entries": {}, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:00Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with 'Review done.'" ] - } + ] }, { - "name": "safe to merge in prose reads nothing, its start cut at 60 characters", + "name": "safe to merge in prose is no lens report, its start cut at 60 characters", "posts": [ { "body": "🎉 Looked through every changed file again today and I think this one is safe to merge." } ], "history": [], - "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with '🎉 Looked through every changed file again today and I think ')": [ - null, - null + "entries": {}, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:00Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '🎉 Looked through every changed file again today and I think '" ] - } + ] }, { - "name": "a heading naming a lens near the top reads nothing", + "name": "a heading naming a lens near the top is no lens report: no marker", "posts": [ { "body": "## Code lens\nAll fine." } ], "history": [], - "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with '## Code lens')": [ - null, - null + "entries": {}, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:00Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Code lens'" ] - } + ] }, { "name": "an override comment that looks like a report is never one", @@ -1939,6 +1942,177 @@ null ] } + }, + { + "name": "a lens heading with no lens marker is no lens report (issue 865)", + "posts": [ + { + "body": "## Lens A\nblocker: none\nmajor: none" + } + ], + "history": [], + "entries": {}, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:00Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Lens A'" + ] + ] + }, + { + "name": "a lens heading that names a read carries the marker and reads nothing", + "posts": [ + { + "body": "## Lens A\nread at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: none" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with '## Lens A')": [ + null, + null + ] + } + }, + { + "name": "a read without a lens field carries the marker and reads nothing", + "posts": [ + { + "body": "reviewer: lens-a · read at: 1234567\nmajor: none" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with 'reviewer: lens-a · read at: 1234567')": [ + null, + null + ] + } + }, + { + "name": "a near miss beside a report of the same lens and head leaves the read", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "## Code lens\nsafe to merge: yes\nmajor: none" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + }, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:01Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Code lens'" + ] + ] + }, + { + "name": "an edited or hidden near miss is still no lens report", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "## Code lens\nmajor: none", + "edited": true + }, + { + "body": "covered: a\nchecks: b", + "hidden": true + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + }, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:01Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Code lens'" + ], + [ + "by someone at 2026-01-01T00:00:02Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with 'covered: a'" + ] + ] + }, + { + "name": "a report edited to drop its marker counts as deleted", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "## Code lens\nmajor: x is cut", + "edited": true + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + }, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:01Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Code lens'" + ] + ] + }, + { + "name": "a report edited with its marker kept reads nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "edited": true + } + ], + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "entries": { + "code": [null, "edited after posting: post a new comment instead"] + } + }, + { + "name": "two reports of one lens at one head: the newer is the entry, both are history", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: x is cut" + } + ], + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + ], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + } + }, + { + "name": "a not-a-lens note with an unquoted read still reads nothing: the read is the marker", + "posts": [ + { + "body": "not a lens: round 2\nlens correctness, read at 1234567" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, says on its first line that it is no lens report, but holds a hex read-at sha outside a `>` quote, starts with 'not a lens: round 2')": [ + null, + null + ] + } } ], "rounds": [ diff --git a/fork-ci/actions/pr-queue/review_judge.test.py b/fork-ci/actions/pr-queue/review_judge.test.py index f3590095f0e3f..825a2b9d18cdd 100644 --- a/fork-ci/actions/pr-queue/review_judge.test.py +++ b/fork-ci/actions/pr-queue/review_judge.test.py @@ -375,10 +375,10 @@ def test_the_same_comments_give_the_same_verdict(self): # runs again: pure SECTIONS = {'about', 'config_path', 'override_prefix', 'globs', 'configs', 'cases', 'findings', 'scans', 'rounds'} FIELDS = {'cases': {'name', 'config', 'changes', 'weight', 'lenses', 'hits', 'protected'}, 'findings': {'name', 'group', 'body', 'findings', 'section'}, - 'scans': {'name', 'posts', 'history', 'entries'}, + 'scans': {'name', 'posts', 'history', 'entries', 'not_lens'}, 'rounds': {'name', 'config', 'history', 'reports', 'decided', 'changes', 'override_authors', 'findings', 'expect'}} -SCAN = lens.Review((), VECTORS['override_prefix'], 'OWNER', ('OWNER',)) +SCAN = lens.Review((), VECTORS['override_prefix'], 'OWNER', ('OWNER',), log=lambda *_: None) def scan(posts): @@ -386,8 +386,8 @@ def scan(posts): 'createdAt': f'2026-01-01T00:{i // 60:02d}:{i % 60:02d}Z', 'includesCreatedEdit': p.get('edited', False), 'isMinimized': p.get('hidden', False)} for i, p in enumerate(posts)] - found, history = SCAN.lens_scan({'comments': comments, 'reviews': []}) - return [list(h) for h in history], {k: [v[1], v[2]] for k, v in found.items()} + found, history, notes = SCAN.scan_posts({'comments': comments, 'reviews': []}) + return [list(h) for h in history], {k: [v[1], v[2]] for k, v in found.items()}, [list(n) for n in notes] def replay_round(v): @@ -413,7 +413,7 @@ def test_every_scan(self): # same comment twice, edited, hidden, old forms, no self.assertGreaterEqual(len(VECTORS['scans']), 31) for v in VECTORS['scans']: with self.subTest(v['name']): - self.assertEqual(scan(v['posts']), (v['history'], v['entries'])) + self.assertEqual(scan(v['posts']), (v['history'], v['entries'], v.get('not_lens', []))) def test_every_round(self): self.assertGreaterEqual(len(VECTORS['rounds']), 28) diff --git a/fork-kit/review/COMMENTS.md b/fork-kit/review/COMMENTS.md index 56ee904f5813e..1886ac7792e7e 100644 --- a/fork-kit/review/COMMENTS.md +++ b/fork-kit/review/COMMENTS.md @@ -1,8 +1,10 @@ # Lens comments: the format the gate reads A lens posts its report as one pull request comment. The merge gate (`fork-ci/actions/pr-queue`) reads that comment -with fixed rules and fails closed: a comment that looks like a report but is not one valid read blocks the head. This -page shows the format with examples. The rules themselves are the gate's code and its README (sections +with fixed rules. A comment that carries the lens marker (below) is a lens report, and the gate fails closed on it: one +that is not exactly one valid read blocks the head. A comment without the marker is no lens report however much it +looks like one: it never reads and never blocks, and the gate's summary names it `not a lens report` with the reason. +This page shows the format with examples. The rules themselves are the gate's code and its README (sections [Lens comments](../../fork-ci/actions/pr-queue/README.md#lens-comments) and [Review rules](../../fork-ci/actions/pr-queue/README.md#review-rules)); the gate's test vectors ([review.vectors.json](../../fork-ci/actions/pr-queue/review.vectors.json)) pin how it judges paths and lens counts. @@ -14,6 +16,20 @@ comment.md` (`--settings` when the project's kit settings are not at `.github/re The examples use the override prefix `tool ready --head`. A project's prefix is `override.prefix` in its queue config. +## The lens marker + +A comment carries the lens marker when one of its lines, read with Markdown stripped (emphasis, links, tags, quote, +list and heading marks), in a code block or quote too: + +- starts with the lens field: `lens:` (also `lens=`, `lens —`, `lens –`), or +- names a read: `read at` and a hex sha (`read at: 0123abc`, `read-at 0123abc`), or +- has a lens field followed by a hex sha anywhere in the line (`the security lens — fixed in 0123abc`). + +A real report has it on its first line, the header. The marker decides only whether a comment is a lens report; the +rest of this page decides whether that report is one valid read. A heading such as `## Lens A`, `safe to merge`, or +`covered:` and `checks:` lines are no marker: such a comment is `not a lens`, `no lens marker`, and a lens whose report +reads that way has posted nothing the gate counts (a required lens then still has no read). + ## The shape ``` @@ -60,7 +76,8 @@ Each example says, on the line before it, what the gate reads, as words: | `blocker`, `major` | an open blocker or major: the gate holds the head until a new read on a fixed head, or a person | | `no findings section` | no blocker and major labels: with `findings` on, the gate does not take the read | | `state`, `no state` | a `state:` line with an answer, or none | -| `reads nothing` | looks like a lens report but is not one valid read: the gate counts it as a blocking problem | +| `reads nothing` | carries the lens marker but is not one valid read: the gate counts it as a blocking problem | +| `no lens marker` | looks like a lens report but carries no lens marker: no lens report, never a read or a block, named in the summary | | `not a lens` | not a lens report at all (a plain comment, or one that opts out with `not a lens:`): ignored | | `override` | an override comment for that sha (counts only from the configured author association, never edited and not hidden) | @@ -208,6 +225,9 @@ major: none ## Comments that read nothing or are no report +A comment with the lens marker that is not one valid read blocks the head (`reads nothing`). One without the marker +is no report, however much it looks like one (`no lens marker`). + No findings section: only a major label, no blocker label. The gate sees no section and does not take the read. The gate reads: `lens code, read, no findings section, no state` @@ -228,7 +248,7 @@ blocker: none major: none ``` -The header is not the first line. The comment looks like a report, so it is a blocking problem. +The header is not the first line. The comment carries the lens marker, so it is a blocking problem. The gate reads: `reads nothing` @@ -252,10 +272,22 @@ blocker: none major: none ``` -A report with no header, only report fields. +A lens heading that names a read: `read at` and a sha are the marker, so this is a broken report, and it blocks. The gate reads: `reads nothing` +```text +## Lens code +read at: 0123456789abcdef0123456789abcdef01234567 +blocker: none +major: none +``` + +A report with no header, only report fields: no marker, so no lens report. It does not block, and it counts for +nothing: the lens has not reported. + +The gate reads: `not a lens, no lens marker` + ```text covered: src/queue.ts checks: ran the tests @@ -263,6 +295,16 @@ blocker: none major: none ``` +A lens-like heading with no marker: no lens report. + +The gate reads: `not a lens, no lens marker` + +```text +## Lens A +blocker: none +major: none +``` + A note between rounds (for example from the orchestrator, after it checked a fix diff) opts out with `not a lens:` on its first line. It must not hold a `read at` sha outside a `>` quote, so a sha goes on its own line. diff --git a/fork-kit/review/SKILL.md b/fork-kit/review/SKILL.md index e5805f2d1d4f5..109524596ef6d 100644 --- a/fork-kit/review/SKILL.md +++ b/fork-kit/review/SKILL.md @@ -195,7 +195,9 @@ python3 -I fork-kit/review/lib/review_kit.py check --root [--settings Exit 0 only for a read of that head with a findings section, no blocker or major, and a state line; otherwise exit 1, and it prints how the gate reads it. A report with a real blocker or major exits 1 **by design**: post it when the -words read `read, blocker, state` or `read, major, state`. Never soften or drop a finding to get exit 0. A project may +words read `read, blocker, state` or `read, major, state`. Never soften or drop a finding to get exit 0. Words +`not a lens, no lens marker` mean the gate would not see a report at all (COMMENTS.md, "The lens marker"): fix the +header, never post it that way. A project may also have a check of the posted comment (who wrote it, edits): run it right after posting. A comment is never edited or hidden (an edited or hidden lens comment reads nothing): post a new one. A comment the gate reads as `reads nothing` keeps blocking the head even after a new post: delete it, or edit its first line to start with diff --git a/fork-kit/review/lib/review_kit.py b/fork-kit/review/lib/review_kit.py index aa91684c97ebb..f578d3e81ac89 100644 --- a/fork-kit/review/lib/review_kit.py +++ b/fork-kit/review/lib/review_kit.py @@ -307,6 +307,8 @@ def verdict(body, override_prefix, head=None): return ['override'] if review.lens_problem(post): return ['reads nothing'] + if review.not_lens_report(post): # looks like a report, but without the lens marker it is none (issue #865) + return ['not a lens', 'no lens marker'] header = lens.lens_header(body) if not header: return ['not a lens'] diff --git a/fork-kit/review/tests/comments.test.py b/fork-kit/review/tests/comments.test.py index 8a6b81431ab93..539694dd8f748 100644 --- a/fork-kit/review/tests/comments.test.py +++ b/fork-kit/review/tests/comments.test.py @@ -23,7 +23,7 @@ OTHER = '89abcdef0123456789abcdef0123456789abcdef' CLEAN = f'lens: code · reviewer: a · read at: {SHA}\nstate: a second run does nothing\nblocker: none\nmajor: none\n' WORDS = ('lens', 'round', 'read', 'short sha', 'clean', 'blocker', 'major', 'no findings section', 'state', - 'no state', 'reads nothing', 'not a lens', 'override') + 'no state', 'reads nothing', 'not a lens', 'no lens marker', 'override') def doc(): @@ -166,7 +166,13 @@ def test_an_override(self): self.assertEqual(self.verdict(f'tool ready --head {SHA[:7]}: read the fix'), 'not a lens') def test_a_looking_comment_reads_nothing(self): - self.assertEqual(self.verdict('safe to merge, I think'), 'reads nothing') + self.assertEqual(self.verdict(f'Here it is.\nread at: {SHA}'), 'reads nothing') + + def test_a_look_alike_without_the_lens_marker_is_no_lens(self): # issue #865: named, never blocking + for body in ('safe to merge, I think', '## Lens A\nblocker: none\nmajor: none', 'covered: a\nchecks: b'): + with self.subTest(body=body): + self.assertEqual(self.verdict(body), 'not a lens, no lens marker') + self.assertEqual(self.m.check(body, 'tool ready --head', SHA), (1, 'not a lens, no lens marker')) class Cli(unittest.TestCase): @@ -235,6 +241,8 @@ def test_not_utf8_is_a_plain_message(self): (Doc, 'test_every_example_reads_as_it_says')), 'the gate flags a looking comment': ('if review.lens_problem(post):', 'if False:', (Check, 'test_a_looking_comment_reads_nothing')), + 'a look-alike without the marker is named': ('if review.not_lens_report(post):', 'if False:', + (Check, 'test_a_look_alike_without_the_lens_marker_is_no_lens')), 'every example is compared': ('if got != said:', 'if False:', (Doc, 'test_a_broken_example_fails')), 'the head is lowercased': ("sha != head.lower()", 'sha != head', (Check, 'test_the_head_is_matched_whatever_its_case')), From b1a1a4560a8ce67bc6e13c8f94a05e2f8dc9dd5b Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:46:20 +0000 Subject: [PATCH 2/3] fix(lens): an unmarked report with an open finding still blocks (#865 round 1) A comment without the lens marker that holds an open blocker, major or NOT SAFE is most likely a real report with a broken header. It now blocks as a comment-keyed entry, as on main, so an older or newer clean read of that lens never lets it through, required lens or not. Its reason names the missing marker and the fix: post a new comment whose first line is the lens header, and delete the old one or start it with `not a lens:`. A look-alike with no open finding still never blocks and is named. - One classifier per language: lens.Review.report_problem and reportProblem (lensComment.ts); every reader calls it. - head-check: the marker hint and fix come first; the required-lenses hint only when no look-alike exists; a WARN mark for the not-a-lens-report row. - lens_start keeps notLens and tells the agent its post was ignored. - review kit: `reads nothing, no lens marker` for a blocking look-alike. - Shared vectors: 7 scans and 5 reads for the new rule. - Docs: release notes, pr-queue and head-check READMEs, COMMENTS.md, SKILL.md. Co-Authored-By: Claude Opus 5.5 --- .../src/fork/reviewRules/lensComment.ts | 77 ++++-- .../src/fork/reviewRules/lensStart.test.ts | 48 +++- apps/server/src/fork/reviewRules/lensStart.ts | 11 +- .../src/fork/reviewRules/reviewRules.test.ts | 30 ++ fork-ci/RELEASE-NOTES.md | 12 +- fork-ci/actions/head-check/README.md | 16 +- fork-ci/actions/head-check/head_check.py | 33 ++- fork-ci/actions/head-check/head_check.test.py | 36 ++- fork-ci/actions/pr-queue/README.md | 25 +- fork-ci/actions/pr-queue/lens.py | 97 +++++-- fork-ci/actions/pr-queue/lens.test.py | 83 +++++- fork-ci/actions/pr-queue/review.vectors.json | 261 +++++++++++++++++- fork-ci/actions/pr-queue/review_judge.test.py | 2 +- fork-kit/review/COMMENTS.md | 54 ++-- fork-kit/review/SKILL.md | 4 +- fork-kit/review/lib/review_kit.py | 7 +- fork-kit/review/tests/comments.test.py | 14 +- 17 files changed, 695 insertions(+), 115 deletions(-) diff --git a/apps/server/src/fork/reviewRules/lensComment.ts b/apps/server/src/fork/reviewRules/lensComment.ts index 4f5fb4c082a25..443348faed01d 100644 --- a/apps/server/src/fork/reviewRules/lensComment.ts +++ b/apps/server/src/fork/reviewRules/lensComment.ts @@ -1,10 +1,13 @@ /** * Port of lens.py's lens rules (fork-ci/actions/pr-queue), held to the shared vectors and the gate's corpus. A lens - * report (one with the lens marker) that is not one valid read is a NO_HEADER entry; a look-alike without the marker - * is no report (notLens). The caller picks the posts that count, in the gate's order. + * report (one with the lens marker) that is not one valid read is a NO_HEADER entry, and so is a look-alike without + * the marker that holds an open finding; one with no open finding is no report (notLens). The caller picks the posts + * that count, in the gate's order. */ import * as Schema from "effect/Schema"; +import { readFindings } from "./findings.ts"; + import { ALNUM, B, @@ -65,6 +68,15 @@ const FLAGS_UNREAD = export const EMBEDDED = "holds a lens header line"; export const NO_MARKER = "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha)"; +/** How a lens fixes a report without the marker (lens.REPOST): every reason that names a look-alike says it. */ +export const REPOST = + "post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the " + + "marker into an old comment does not count)"; +/** + * reportProblem's kinds (lens.BROKEN, HELD, NOT_LENS): a lens report (with the marker) that is not one valid read; a + * comment without the marker that holds an open finding (both block); one without either (no report, never blocks). + */ +export type ReportKind = "broken" | "held" | "notLens"; const OPT_OUT_READ = "says on its first line that it is no lens report, but holds a hex read-at sha outside a `>` quote"; @@ -261,18 +273,44 @@ function readProblem(body: string, narrow: boolean): string | null { } /** - * lens.Review.lens_problem: why a lens report (a comment with the lens marker) is not one valid read, so it blocks; - * null when it is one, carries no marker, or does not look like a report. + * lens.Review.report_problem: [why, kind] for a look-alike (looksProblem), null otherwise. Blocks with the marker + * (broken), or without it when readFindings sees an open finding (held: an older clean read must not win). Otherwise + * no lens report (notLens): named, never blocking. */ -export function lensProblem(body: string, overridePrefix?: string): string | null { +export function reportProblem( + body: string, + overridePrefix?: string, +): [why: string, kind: ReportKind] | null { const problem = looksProblem(body, overridePrefix); - return problem && hasMarker(body) ? problem : null; + if (!problem) return null; + if (hasMarker(body)) return [problem, "broken"]; + const found = readFindings(body)[0]; + if (found.length > 0) { + return [ + `${NO_MARKER}, but it holds an open ${found[0]![0]}: ${REPOST}, and delete this one or start it with ` + + `\`not a lens:\`; it looks like one: ${problem}`, + "held", + ]; + } + return [`${NO_MARKER}; it looks like one: ${problem}`, "notLens"]; +} + +/** + * lens.Review.lens_problem: why a comment that looks like a lens report blocks (reportProblem kind broken or held), or + * null: it is one valid read, does not look like a report, or is no lens report (notLensReport). + */ +export function lensProblem(body: string, overridePrefix?: string): string | null { + const got = reportProblem(body, overridePrefix); + return got && got[1] !== "notLens" ? got[0] : null; } -/** lens.Review.not_lens_report: why a comment that looks like a lens report is none (no lens marker), or null. */ +/** + * lens.Review.not_lens_report: why a comment that looks like a lens report is none (no lens marker and no open + * finding: reportProblem kind notLens), or null. + */ export function notLensReport(body: string, overridePrefix?: string): string | null { - const problem = looksProblem(body, overridePrefix); - return problem && !hasMarker(body) ? `${NO_MARKER}; it looks like one: ${problem}` : null; + const got = reportProblem(body, overridePrefix); + return got && got[1] === "notLens" ? got[0] : null; } /** @@ -346,7 +384,10 @@ export interface LensScan { readonly history: Array<[string, string | null]>; /** Each lens key's newest [sha or null, why it reads nothing or null]. */ readonly entries: Record; - /** [where, why] of each post that looks like a report but has no lens marker (lens.Review.not_lens_reports). */ + /** + * [where, why] of each post that looks like a report, has no lens marker and no open finding + * (lens.Review.not_lens_reports). + */ readonly notLens: Array<[string, string]>; } @@ -372,26 +413,24 @@ export function lensEntries( const at: PostAt = [post.when, i]; const { body } = post; const hidden = !post.unread && post.hidden; - let problem: string | null; - let marked: boolean; + let got: [string, ReportKind] | null; let header: [string, string | null] | null; let key: string; try { - problem = looksProblem(body, overridePrefix); - marked = problem !== null && hasMarker(body); - header = problem ? null : lensHeader(body); + got = reportProblem(body, overridePrefix); + header = got ? null : lensHeader(body); key = header ? lensKey(header[0]) : ""; } catch (error) { if (isPyTextError(error) && error.where === undefined) throw new PyTextError({ codePoints: error.codePoints, where: post.where }); throw error; } - if (problem && !marked) { - notLens.push([post.where, `${NO_MARKER}; it looks like one: ${problem}`]); + if (got?.[1] === "notLens") { + notLens.push([post.where, got[0]]); return; } - if (problem) { - key = `${NO_HEADER} (${post.where}, ${problem}${hidden ? ", hidden" : ""})`; + if (got) { + key = `${NO_HEADER} (${post.where}, ${got[0]}${hidden ? ", hidden" : ""})`; entries.set(key, { at, sha: null, why: null, name: null, body }); return; } diff --git a/apps/server/src/fork/reviewRules/lensStart.test.ts b/apps/server/src/fork/reviewRules/lensStart.test.ts index b5cfda8e716a9..9d54fd9306a0d 100644 --- a/apps/server/src/fork/reviewRules/lensStart.test.ts +++ b/apps/server/src/fork/reviewRules/lensStart.test.ts @@ -6,7 +6,7 @@ import * as NodeFS from "node:fs"; import { effectiveReviewRules } from "@t3tools/contracts"; import { assert, describe, it } from "@effect/vitest"; -import { NO_HEADER, lensKey, lensScan } from "./lensComment.ts"; +import { NO_HEADER, NO_MARKER, REPOST, lensKey, lensScan } from "./lensComment.ts"; import { readFindings } from "./findings.ts"; import { byCodePoint } from "./pyText.ts"; import { vectorPosts, type VectorPost } from "./vectors.testkit.ts"; @@ -1032,6 +1032,52 @@ describe("lens_start plans what the gate reads (fix round A+B)", () => { assert.isTrue(gatePasses(basic, [], ["code"], carryOut(covered, after), A)); }); + it("a look-alike without the lens marker (#865): ignored and said so, or, with an open finding, held with the fix", () => { + const note: LensStartPost = { + ...report("code", A), + body: "## Code lens\nAll fine.", + where: "note", + }; + const plan = planLensStart(input({ pullList: [pull(1, { posts: [note] })] })); + assert.deepStrictEqual(lensesOf(plan), ["code"], "the lens has not reported: it starts"); + const said = plan.notes.filter((n) => + n.startsWith("#1: the comment note looks like a lens report"), + ); + assert.lengthOf(said, 1); + assert.include(said[0], "the gate ignores it"); + assert.include(said[0], NO_MARKER); + assert.include(said[0], REPOST); + assert.deepStrictEqual(planLensStart(input({ pullList: [pull(1, { posts: [note] })] })), plan); + const twice = planLensStart( + input({ pullList: [pull(1, { posts: [note, { ...note, where: "again" }] })] }), + ); + assert.lengthOf( + twice.notes.filter((n) => n.includes("the gate ignores it")), + 2, + ); + const held: LensStartPost = { + ...report("code", A), + body: "## Code lens\nblocker: a re-run loses data\nmajor: none", + where: "held", + }; + for (const posts of [ + [report("code", A), held], + [held, report("code", A)], + ]) { + const stuck = planLensStart(input({ pullList: [pull(1, { posts })] })); + assert.deepStrictEqual( + stuck.starts, + [], + "an older or newer clean read never lets it through", + ); + assert.include(stuck.refused[0]!.reason, "a comment that reads nothing"); + assert.include(stuck.refused[0]!.reason, REPOST); + assert.isFalse(gatePasses(basic, [], ["code"], posts, A)); + } + const optedOut = { ...held, body: `not a lens: ${held.body}` }; + assert.isTrue(gatePasses(basic, [], ["code"], [report("code", A), optedOut], A)); + }); + it("a newer override the gate counts is honoured: nothing starts again", () => { const plan = planLensStart( input({ pullList: [pull(1, { head: B, posts: [report("code", A), override(B)] })] }), diff --git a/apps/server/src/fork/reviewRules/lensStart.ts b/apps/server/src/fork/reviewRules/lensStart.ts index 9e8322b3d056d..948e716ad3c16 100644 --- a/apps/server/src/fork/reviewRules/lensStart.ts +++ b/apps/server/src/fork/reviewRules/lensStart.ts @@ -11,6 +11,7 @@ import { type EffectiveReviewRules, type ReviewRunner, reviewLensRunner } from " import { NO_HEADER, + REPOST, lensEntries, lensKey, namesALens, @@ -397,7 +398,7 @@ function readPull( return { refused: `no plan: ${error.reason}; no lens is started rather than too few` }; } const reads = gateReads(pull.posts, overridePrefix); - const { history } = lensEntries(pull.posts, overridePrefix, isOverride); + const { history, notLens } = lensEntries(pull.posts, overridePrefix, isOverride); const rounds = startRounds(block, history, head, pull.changeOf); // The lenses this base can start, by key: the config's, then the input's names (built-in prompt). const approachKey = lensKey(block.rounds.approach_lens); @@ -413,7 +414,13 @@ function readPull( }); } } - const notes: string[] = []; + // A look-alike with no lens marker and no open finding: the gate ignores it, so the lens that posted it has not + // reported. Said, so an agent does not take its post for a read. + const notes: string[] = notLens.map( + ([where, why]) => + `#${pull.number}: the comment ${where} looks like a lens report, but the gate ignores it and counts no read ` + + `from it (${why}); if it was meant as a report: ${REPOST}`, + ); const inputOnly: string[] = []; for (const [key, name] of named) { if (known.has(key)) continue; diff --git a/apps/server/src/fork/reviewRules/reviewRules.test.ts b/apps/server/src/fork/reviewRules/reviewRules.test.ts index 2cce6bc236592..984648f7d1ac5 100644 --- a/apps/server/src/fork/reviewRules/reviewRules.test.ts +++ b/apps/server/src/fork/reviewRules/reviewRules.test.ts @@ -12,6 +12,7 @@ import { HIDDEN, NO_HEADER, NO_MARKER, + REPOST, hasMarker, lensHeader, lensKey, @@ -19,6 +20,7 @@ import { lensScan, looksProblem, notLensReport, + reportProblem, } from "./lensComment.ts"; import { ReviewPlanError, globMatches, planReview, type ReviewBlock } from "./plan.ts"; import { PyTextError } from "./pyText.ts"; @@ -325,6 +327,34 @@ describe("rounds meet old, repeated, edited, deleted and empty state", () => { assert.strictEqual(notLensReport(body) !== null, !hasMarker(body), body); } }); + it("a look-alike without the marker that holds an open finding blocks, names the fix, and an older read does not win (#865 round 1)", () => { + for (const body of [ + "## Code lens\nblocker: a re-run loses data\nmajor: none", + "covered: a\nchecks: b\nmajor: the retry drops a row", + "NOT SAFE to merge (code lens, round 2)\nmore below", + ]) { + const got = reportProblem(body); + assert.strictEqual(got?.[1], "held", body); + assert.strictEqual(lensProblem(body), got![0], body); + assert.isNull(notLensReport(body), body); + assert.isTrue(got![0].startsWith(`${NO_MARKER}, but it holds an open `), got![0]); + assert.include(got![0], REPOST); + } + assert.strictEqual(reportProblem("## Code lens\nAll fine.")?.[1], "notLens"); + assert.strictEqual(reportProblem("Here.\nread at: 1234567")?.[1], "broken"); + assert.isNull(reportProblem(`lens: code · reviewer: a · read at: ${"a".repeat(40)}`)); + for (const name of [ + "a clean read then a newer unmarked report with an open blocker holds the head (issue 865)", + "a clean read then a newer unmarked NOT SAFE verdict holds the head", + ]) { + const got = scan(named("scans", name)); + assert.deepStrictEqual(got.entries.code, ["a".repeat(40), null], name); + const held = Object.keys(got.entries).filter((key) => key.startsWith(NO_HEADER)); + assert.lengthOf(held, 1, name); + assert.include(held[0], REPOST); + assert.deepStrictEqual(got.notLens, [], name); + } + }); it("an override comment never reads as a lens report, with the repository's prefix only", () => { const body = named("scans", "an override comment that looks like a report is never one") .posts[0].body; diff --git a/fork-ci/RELEASE-NOTES.md b/fork-ci/RELEASE-NOTES.md index 48f70b747ea46..3fe71f6accc90 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -19,13 +19,19 @@ A comment counts as a lens report only when it carries the lens marker: a line t (`lens:`, `lens=`, `lens —`, `lens –`), names a read (`read at` and a hex sha), or has a lens field with a hex sha after it (Markdown stripped, in code blocks and quotes too). A lens report that is not exactly one valid read still blocks, as before. A comment that only looks like one without the marker (a `## Lens A` heading, `safe to merge`, `covered:` and -`checks:` lines) no longer blocks: the run log and the head check's summary name it as `not a lens report` with the -reason. Comments with the marker read exactly as before. T3's copy (`apps/server/src/fork/reviewRules`) and the review +`checks:` lines) and holds no open finding no longer blocks: the run log and the head check's summary name it as +`not a lens report` (a `WARN` row) with the reason. One without the marker that holds an open finding (a `blocker:` or +`major:` line that is not `none`, or NOT SAFE, as the findings rules read them) still blocks, as before, whatever an +older or newer read of that lens says: it is most likely a real report with a broken header. Its reason, first in the +head check's, says to post a NEW comment whose first line is `lens: · reviewer: · read at: ` +(editing the marker in does not count) and to delete the old one or start it with `not a lens:`. Comments with the +marker read exactly as before. T3's copy (`apps/server/src/fork/reviewRules`) and the review kit's `check` read the same rule from the shared vectors. **Upgrade:** a lens report written without the marker now counts for nothing, so a lens that posts one has not reported: list required lenses (`required-lenses`, or a `review` block in `enforce`) so a missing read still fails the -head check, and have lenses run the kit's `check` before posting. +head check, and have lenses run the kit's `check` before posting. An old comment without the marker that holds an +open finding blocks as it did before this release; one that holds none stops blocking. ### pr-queue: what counts as a `state:` line is gate code (#797) diff --git a/fork-ci/actions/head-check/README.md b/fork-ci/actions/head-check/README.md index 02c91cadeeab1..68b16059f3df3 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -215,10 +215,18 @@ labels or changed paths, say) and pass it in. The log and the job summary list each lens with `ok` or `fail` and a short reason (the sha it read, an override, edited, hidden, a short sha, required but missing). A comment that looks like a lens report but carries no lens -marker (the pr-queue README, "Lens comments") is no lens report: it gets a row -`not a lens report ()`, `ok`, with the reason, and never fails the -check; a required lens it was meant to be still fails as missing, and the -reason says how many such comments there are. +marker (the pr-queue README, "Lens comments") is no lens report. If it holds no +open finding it gets a row `not a lens report ()`, `WARN` (`warn` in the +summary: it passes, but is not green), with the reason, and never fails the +check on its own. If it holds an open finding (a `blocker:` or `major:` line +that is not `none`, or NOT SAFE) it blocks, as a `fail` row, whether or not a +lens is required and whatever another read of that lens says. A required lens +such a comment was meant to be still fails as missing. In both cases the +failure reason starts with the fix: how many comments look like a lens report +without the marker, and to post a NEW comment whose first line is +`lens: · reviewer: · read at: ` (editing the marker in does +not count). The hint to check the names in `required-lenses` appears only when +no such comment exists. | Exit | Meaning | | ---- | -------------------------------------------------------------------------------- | diff --git a/fork-ci/actions/head-check/head_check.py b/fork-ci/actions/head-check/head_check.py index ee2a4c10a3a82..e3a721e9c8005 100644 --- a/fork-ci/actions/head-check/head_check.py +++ b/fork-ci/actions/head-check/head_check.py @@ -57,6 +57,8 @@ ATTEMPTS, RETRY_SECONDS = 3, 10 FETCH_SECONDS = 120 # a fetch of a read commit that takes longer counts as failed (the job has 15 minutes in all) FIELDS = 'isDraft,headRefOid,comments,reviews' +WARN = 'warn' # a verdict row that passes but a reader should look at (a comment that is no lens report): not green +LOG_MARK = {'ok': 'ok ', 'warn': 'WARN', 'fail': 'FAIL'} SHA = pr_queue.SHA REFUSED = pr_queue.REFUSED # Every git call: the queue's safe flags (no hooks, fsmonitor, commit-graph, replace refs or attributes file). git runs @@ -213,8 +215,10 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l reviewed, read, why = review.reviewed_head(pr) missing = [name for key, name in required.items() if key not in reads] found = ', '.join(sorted(reads)) or 'none' - # comments that look like a lens report but carry no lens marker: no report, so they pass; named, never silent - notes = [(f'{lens.NOT_LENS} ({where})', True, why) for where, why in review.not_lens_reports(pr)] + # comments that look like a lens report but carry no lens marker and hold no open finding: no report, so they pass; + # named in a WARN row, never silent. Those that hold an open finding block: NO_HEADER entries of reads (held). + notes = [(f'{lens.NOT_LENS} ({where})', WARN, why) for where, why in review.not_lens_reports(pr)] + held = review.unmarked_held(pr) if not reads and not required: return True, 'no lens comments and no required lens: nothing to compare', notes ok, how = same_change(checkout, head, read) if reviewed and read else (False, None) @@ -230,17 +234,23 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l rows.append(((f'{key} (required)' if key in required else key), bool(sha and read and ok), text)) rows += notes if missing: + if notes or held: # the fix first: a look-alike is most likely the report, so no config hint + return False, (f'{marker_hint(len(notes) + len(held))}. Required lens without a read: ' + f'{", ".join(missing)}; lenses found: {found}'), rows where = ' or the review rules of the config' if rules_name_lenses else '' - near = (f'; {len(notes)} comment(s) look like a lens report but carry no lens marker, so they are not one ' - f'(rows "{lens.NOT_LENS}")') if notes else '' return False, (f'required lens without a read: {", ".join(missing)}. No counted lens comment has that name: ' - f'check it in required-lenses (one name per line){where}; lenses found: {found}' - f'{near}'), rows + f'check it in required-lenses (one name per line){where}; lenses found: {found}'), rows if not read: - return False, why, rows + return False, (f'{marker_hint(len(held))}; each that holds an open finding blocks until it is deleted or ' + f'starts with `not a lens:`. {why}' if held else why), rows return ok, how, rows +def marker_hint(count): + """The fix for comments that look like a lens report but carry no lens marker, first in a failure reason.""" + return f'{count} comment(s) look like a lens report but carry no lens marker: {lens.REPOST}' + + def escape(text): """One line for a workflow command (::error::) or the log: nothing in a comment can start a command.""" return str(text).replace('%', '%25').replace('\r', '%0D').replace('\n', '%0A') @@ -250,10 +260,15 @@ def cell(text): return re.sub(r'[|<>`\r\n]', ' ', str(text)) +def mark(good): + """A row's mark: ok, warn (WARN: it passes, but a reader should look) or fail.""" + return 'warn' if good is WARN else 'ok' if good else 'fail' + + def report(ok, reason, rows, n, env, out=print): """The log, the step summary (one table, appended) and the `result` output.""" for name, good, text in rows: - out(f' {"ok " if good else "FAIL"} {escape(name)}: {escape(text)}') + out(f' {LOG_MARK[mark(good)]} {escape(name)}: {escape(text)}') out(f'#{n}: head check {"passed" if ok else "FAILED"}: {escape(reason)}' if ok else f'::error::#{n}: head check ' f'failed: {escape(reason)}') summary = env.get('GITHUB_STEP_SUMMARY') @@ -261,7 +276,7 @@ def report(ok, reason, rows, n, env, out=print): lines = [f'### Head check #{n}: {"pass" if ok else "fail"}', '', cell(reason), ''] if rows: lines += ['| lens | | reason |', '| --- | --- | --- |'] - lines += [f'| {cell(name)} | {"ok" if good else "fail"} | {cell(text)} |' for name, good, text in rows] + lines += [f'| {cell(name)} | {mark(good)} | {cell(text)} |' for name, good, text in rows] with open(summary, 'a', encoding='utf-8') as f: f.write('\n'.join(lines) + '\n') output = env.get('GITHUB_OUTPUT') diff --git a/fork-ci/actions/head-check/head_check.test.py b/fork-ci/actions/head-check/head_check.test.py index 245d37eca13e5..9f40d0acdd452 100644 --- a/fork-ci/actions/head-check/head_check.test.py +++ b/fork-ci/actions/head-check/head_check.test.py @@ -399,14 +399,41 @@ def test_a_look_alike_without_the_lens_marker_passes_and_is_named(self): # iss ok, why, rows = self.verdict([self.p.lens('correctness', A), self.p.post(body)]) self.assertTrue(ok, why) self.assertEqual([(name.split(' (')[0], good) for name, good, _ in rows], - [('correctness', True), (lens.NOT_LENS, True)]) + [('correctness', True), (lens.NOT_LENS, H.WARN)]) # passes, but never green self.assertIn(lens.NO_MARKER, rows[1][2]) ok, why, rows = self.verdict([self.p.post(body)]) # alone: no lens comments, still named self.assertTrue(ok, why) - self.assertEqual([(name.split(' (')[0], good) for name, good, _ in rows], [(lens.NOT_LENS, True)]) + self.assertEqual([(name.split(' (')[0], good) for name, good, _ in rows], [(lens.NOT_LENS, H.WARN)]) ok, why, rows = self.verdict([self.p.post(body)], required='correctness') # fail closed self.assertFalse(ok) - self.assertIn('carry no lens marker', why) + self.assertTrue(why.startswith(H.marker_hint(1)), why) # the fix first, with the header line + self.assertIn(lens.REPOST, why) + self.assertNotIn('required-lenses', why, 'no config hint when a look-alike is there') + ok, why, _ = self.verdict([self.p.post('Thanks')], required='correctness') # no look-alike: the config hint + self.assertFalse(ok) + self.assertIn('check it in required-lenses', why) + self.assertNotIn(lens.REPOST, why) + + def test_an_unmarked_look_alike_with_an_open_finding_still_fails(self): # issue #865 round 1 + for body in (f'## {LENS.title()} correctness, round 2\nblocker: a re-run loses data\nmajor: none', + f'## {LENS.title()} correctness, round 2\nverdict: not safe to merge', + 'covered: all\nchecks: ran the tests\nmajor: the retry drops a row'): + with self.subTest(body=body): + for comments in ([self.p.lens('correctness', A), self.p.post(body)], + [self.p.post(body), self.p.lens('correctness', A)]): + ok, why, rows = self.verdict(comments, required='correctness') + self.assertFalse(ok, 'an older or newer clean read never lets it through') + self.assertTrue(why.startswith(H.marker_hint(1)), why) + self.assertEqual([good for _, good, _ in rows], [False, False], 'no one head while it holds') + self.assertEqual(sum(lens.NO_MARKER in name for name, _, _ in rows), 1, rows) + ok, why, rows = self.verdict([self.p.post(body)]) # no required lens: still held + self.assertFalse(ok, why) + self.assertTrue(why.startswith(H.marker_hint(1)), why) + self.assertEqual([name.split(' (')[0] for name, _, _ in rows], [lens.NO_HEADER]) + ok, why, _ = self.verdict([self.p.post(body)], required='correctness') + self.assertFalse(ok) + self.assertTrue(why.startswith(H.marker_hint(1)), why) + self.assertNotIn('required-lenses', why) def test_a_deleted_comment_counts_no_more(self): # deleted: GitHub no longer lists it look_alike = self.p.post(f'read at: {A[:7]}') @@ -2263,7 +2290,8 @@ def test_a_near_miss_passes_and_the_summary_names_it(self): # issue #865 head=self.read)) code, out = run_cli(self.path, fake_gh((0, answer)), env=self.env) self.assertEqual(code, 0, out) - self.assertRegex(self.read_file('summary.md'), rf'\| {lens.NOT_LENS} \([^|]*\) \| ok \| no lens marker') + self.assertRegex(self.read_file('summary.md'), rf'\| {lens.NOT_LENS} \([^|]*\) \| warn \| no lens marker') + self.assertIn(f'WARN {lens.NOT_LENS}', out) def test_pass_and_fail_reach_the_exit_code_summary_and_output(self): code, out = run_cli(self.path, fake_gh((0, self.good)), env=self.env) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index bf72fbe9fd360..50720af0de02a 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -573,11 +573,19 @@ counts as a lens that read nothing, so the queue never takes a reviewed pull request for an unreviewed one. A comment without the marker is no lens report, however much it looks like one (a `## ... lens` heading near the top, `safe to merge`, `lens:` in mid-line, or two `covered:`/`checks:` lines): it -neither reads nor blocks, the run log names it, and the head check's summary -lists it as `not a lens report` with the reason (issue 865: such a heading, -posted from the owner's account, held pull requests with no one seeing why). A -lens whose report has no marker has therefore posted nothing: a required lens -still has no read, and the head check fails on that. Lenses check their +never reads. If it holds no open finding it does not block either: the run log +names it, and the head check's summary lists it as `not a lens report` (a +`WARN` row) with the reason (issue 865: such a heading, posted from the owner's +account, held pull requests with no one seeing why). A lens whose report has no +marker has therefore posted nothing: a required lens still has no read, and the +head check fails on that. If it holds an open finding (a `blocker:` or `major:` +line that is not `none`, or NOT SAFE, as the findings rules below read them) it +is most likely a real report with a broken header, so it blocks like a broken +lens report, keyed by that comment, whatever an older or newer read of that lens +says: an older clean read never wins over it. Its reason says to post a NEW +comment whose first line is `lens: · reviewer: · read at: ` +(editing the marker into the old comment does not count: an edited comment +reads nothing) and to delete the old one or start it with `not a lens:`. Lenses check their comment with the review kit's `check` before posting (fork-kit/review). A comment that is no report but holds a marker says so on its first line, `not a lens: ...`. That clears it unless one of @@ -611,8 +619,9 @@ 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 lens report (a comment with the marker) that 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 +A lens report (a comment with the marker) that is not one valid read, or a +comment without it that holds an open finding, 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. The ways out: delete it, edit its first line to `not a lens: ...` with no lens header line left in it and any `read at ` quoted with `>`, or post an @@ -628,6 +637,8 @@ fix-round comments with a `lens:` or `read at` in their text, and valid lens reads (`Verdict: not safe to merge ...`), so the rules stay as they are: each one that flags an ordinary comment also catches broken reports that read the same way ([issue 76](https://github.com/scuttletoby/t3code/issues/76)). +Under the lens marker rule 10 of the 25 carry no marker: 9 hold no open finding +and are only named, and 1 (a real report with an open major) still blocks. ## The queue diff --git a/fork-ci/actions/pr-queue/lens.py b/fork-ci/actions/pr-queue/lens.py index 39821dc48346a..675c05395d7b7 100644 --- a/fork-ci/actions/pr-queue/lens.py +++ b/fork-ci/actions/pr-queue/lens.py @@ -65,8 +65,8 @@ # naming a lens (LOOKS_HEADING_RE reads the raw line: normalising drops `#`), or two `covered:`/`checks:` field lines; # on ANY line, fenced, indented or quoted too, a `read at` with a hex sha, a header line or a `lens:` field with any hex # sha (loose_header). Such a comment without a valid first-line header is a lens that read nothing when it carries the -# lens marker (has_marker), and no lens report at all without it (issue #865). So is a comment with two or more header -# lines (one comment per lens). A round, fix or note comment says so on its first line, `not a lens: ...`; that clears +# lens marker (has_marker) or, without it, holds an open finding (Review.report_problem); else it is no lens report at +# all (issue #865). So is a comment with two or more header lines (one comment per lens). A round, fix or note comment says so on its first line, `not a lens: ...`; that clears # it only when none of its lines is a header line or a lens field with a sha, and no line outside a `>` quote (a fence # or an indented block is no quote) holds a hex `read at` (unquoted_lines, issue #77). LOOKS_RE = re.compile(r'\blens\s*:|\bread[\s-]*at\b\s*(?::|[0-9a-f]{7})|\bsafe\s+to\s+merge\b', re.I) @@ -76,9 +76,17 @@ TOP_LINES = 5 # Any hex sha with a digit (7-40 hex, not part of a longer word): `abc1234`, never `defaced` or `facade1x`. HEX_RE = re.compile(r'(? · reviewer: · read at: ` (editing the ' + 'marker into an old comment does not count)') OK_CONCLUSIONS = ('SUCCESS', 'SKIPPED', 'NEUTRAL') STRANGER_SCAN = 4096 # characters of a post that does not count read to decide whether to log it @@ -280,7 +288,7 @@ def has_marker(body): """The comment carries the lens marker (COMMENTS.md, "The lens marker"): one of its lines, in a code block or quote too, read either way (clean_inline narrow or not), is a marker_line. Only such a comment is a lens report: one that is not exactly one valid read blocks (lens_problem); without the marker, a comment is no lens report however - much it looks like one (not_lens_reports). Every line lens_problem flags as a header line, a lens field with a + much it looks like one (not_lens_reports), unless it holds an open finding (Review.report_problem). Every line lens_problem flags as a header line, a lens field with a sha or a first-line `lens:` is a marker line, so every comment with such a problem carries the marker.""" lines = (body or '').splitlines() return any(marker_line(norm_line(line, narrow)) for narrow in (False, True) for line in lines) @@ -376,19 +384,39 @@ def override_sha(self, post): m = self.override_re.match(post.get('body') or '') return m.group(1) if m else None - def lens_problem(self, post): - """Why a lens report is not one valid lens read, so it blocks (None: it is one, it carries no lens marker, or - it does not look like a lens report): looks_problem, for a comment that carries the lens marker (has_marker). - One without the marker is no lens report (not_lens_report).""" + def report_problem(self, post): + """(why, kind) for a comment that looks like a lens report but is not one valid read (looks_problem); (None, + None) for a valid read or a comment that does not look like a report. The one rule of issue #865: it blocks, + as a NO_HEADER entry with why as its reason, when it carries the lens marker (has_marker: kind BROKEN), or when + it does not but holds an open finding, a blocker or major line that is not none or a NOT SAFE verdict as + review_judge.read_findings reads them (kind HELD: a real report with a broken header must not pass because an + older read of that lens is clean). Without the marker and with no open finding it is no lens report (kind + NOT_LENS): named, never blocking.""" problem = self.looks_problem(post) - return problem if problem and has_marker(post.get('body') or '') else None + if not problem: + return None, None + body = post.get('body') or '' + if has_marker(body): + return problem, BROKEN + import review_judge # noqa: PLC0415 - review_judge imports this module + found = review_judge.findings(body) + if found: + return (f'{NO_MARKER}, but it holds an open {found[0][0]}: {REPOST}, and delete this one or start it with ' + f'`not a lens:`; it looks like one: {problem}'), HELD + return f'{NO_MARKER}; it looks like one: {problem}', NOT_LENS + + def lens_problem(self, post): + """Why a comment that looks like a lens report blocks (report_problem kind BROKEN or HELD), or None: it is one + valid read, it does not look like a report, or it is no lens report (not_lens_report).""" + why, kind = self.report_problem(post) + return why if kind in (BROKEN, HELD) else None def not_lens_report(self, post): - """Why a comment that looks like a lens report is none (it carries no lens marker), for the summary; None when - it is a lens report (valid or not) or does not look like one.""" - problem = self.looks_problem(post) - return f'{NO_MARKER}; it looks like one: {problem}' if problem and not has_marker(post.get('body') or '') \ - else None + """Why a comment that looks like a lens report is none (no lens marker and no open finding: report_problem + kind NOT_LENS), for the summary; None when it is a lens report (valid or not), blocks, or does not look like + one.""" + why, kind = self.report_problem(post) + return why if kind == NOT_LENS else None def looks_problem(self, post): """Why a comment that looks like a lens report is not one valid lens read (None: it is one, or it does not look @@ -478,10 +506,11 @@ def lens_entries(self, pr): def lens_scan(self, pr): """(entries, history). entries: {lens key: ((when, index), sha or None, why or None, post)}: each lens's NEWEST - header, from the posts that count (counts). A lens report (a comment with the lens marker, has_marker) that is - not one valid read (lens_problem) is an entry of its own, keyed by the comment, with no sha: a correct new post - of that lens does not replace it, and hiding it does not clear it. It reads nothing until it is deleted, its first line is edited - to `not a lens: ...` with no lens header line left in it, or a newer override covers it (NO_HEADER_WAY_OUT). A + header, from the posts that count (counts). A comment that blocks (lens_problem: a lens report, one with the + lens marker, that is not one valid read, or one without the marker that holds an open finding) is an entry of + its own, keyed by the comment, with no sha: a correct new post of that lens does not replace it, and hiding it + does not clear it. It reads nothing until it is deleted, its first line is edited to `not a lens: ...` with no + lens header line left in it, or a newer override covers it (NO_HEADER_WAY_OUT). A lens comment edited after posting (includesCreatedEdit not false: GitHub records that it changed, not what) or hidden (minimized) reads nothing until that lens posts a new comment; so does a review whose flags were not read (FLAGS_UNREAD). A lens-looking post that does not count is logged (log only, never a comment), so a wrong @@ -489,18 +518,25 @@ def lens_scan(self, pr): entry's post. history: [(lens name, sha or None)] of EVERY counted post with a valid lens header, in list order, older rounds and edited or hidden ones too (review_judge.judge_rounds counts the rounds by it: hiding an old round must not lower the count). A comment that looks like a report but carries no lens marker is no entry and - no history (not_lens_reports).""" + no history (not_lens_reports), unless it holds an open finding: then it is such an entry (report_problem).""" return self.scan_posts(pr)[:2] def not_lens_reports(self, pr): - """[(where, why)] of the counted posts that look like a lens report but carry no lens marker (has_marker), in - list order: no lens report, so neither a read nor a block; the head check names each in its summary.""" + """[(where, why)] of the counted posts that look like a lens report but carry no lens marker and hold no open + finding (report_problem), in list order: no lens report, so neither a read nor a block; the head check names + each in its summary.""" return self.scan_posts(pr)[2] + def unmarked_held(self, pr): + """[(where, why)] of the counted posts without the lens marker that block because they hold an open finding + (report_problem), in list order: each is also a NO_HEADER entry of lens_scan. The head check puts the fix + (REPOST) first in its reason when there is one.""" + return self.scan_posts(pr)[3] + def scan_posts(self, pr): - """(entries, history, not lens reports): lens_scan and not_lens_reports in one pass. Each comment that is not a - lens report is logged once per Review.""" - found, history, notes = {}, [], [] + """(entries, history, not lens reports, unmarked held): lens_scan, not_lens_reports and unmarked_held in one + pass. Each comment that is not a lens report is logged once per Review.""" + found, history, notes, held = {}, [], [], [] for when, i, post in self.lens_posts(pr): where = post.get('url') or f'by {(post.get("author") or {}).get("login") or "?"} at {when or "?"}' if not self.counts(post): # the author first: a stranger's text is only ever read in part, for the log @@ -512,14 +548,15 @@ def scan_posts(self, pr): f'{"author association " + association if association else "no author association"} ' f'is not one of lens_author_associations ({", ".join(self.lens_associations)})') continue - problem = self.looks_problem(post) - if problem and not has_marker(post.get('body') or ''): - why = f'{NO_MARKER}; it looks like one: {problem}' - notes.append((where, why)) + problem, kind = self.report_problem(post) + if kind == NOT_LENS: + notes.append((where, problem)) if ('not', where) not in self.logged: self.logged.add(('not', where)) - self.log(f'{NOT_LENS} ({where}): {why}') + self.log(f'{NOT_LENS} ({where}): {problem}') continue + if kind == HELD: + held.append((where, problem)) header = None if problem else lens_header(post.get('body') or '') if problem: hidden = ', hidden' if self.hidden(post) else '' @@ -533,7 +570,7 @@ def scan_posts(self, pr): why = FLAGS_UNREAD if post.get(UNREAD) else HIDDEN if self.hidden(post) \ else EDITED if post.get('includesCreatedEdit') is not False else None found[key] = ((when, i), None, why, post) if why else ((when, i), header[1], None, post) - return found, history, notes + return found, history, notes, held def lens_reads(self, pr): """{lens key: (sha, gap, override)}: what each lens of lens_entries counts as reading, the one rule reviewed_head diff --git a/fork-ci/actions/pr-queue/lens.test.py b/fork-ci/actions/pr-queue/lens.test.py index d22df1d501203..ffbd8ee83c7ce 100644 --- a/fork-ci/actions/pr-queue/lens.test.py +++ b/fork-ci/actions/pr-queue/lens.test.py @@ -14,6 +14,7 @@ sys.path.insert(0, HERE) import config # noqa: E402 import lens # noqa: E402 +import review_judge # noqa: E402 CORPUS = os.path.join(HERE, 'testdata', 'lens-corpus.jsonl') SOURCE = lens.Review(('coderabbitai', 'github-actions', 'copilot'), 'proj ready --head', 'OWNER', ('OWNER',)) @@ -67,7 +68,7 @@ def test_every_recorded_call_gives_the_source_answer(self): 'override_sha': SOURCE.override_sha, 'lens_header': lens.lens_header, 'no_lens_text': lens.no_lens_text, 'latest_checks': lens.latest_checks, 'check_state': lens.check_state, 'lens_key': lens.lens_key} self.assertEqual({c['fn'] for c in cases}, set(fns) | {'full_sha'}) - wrong, changed, opt_out, no_marker = [], 0, 0, [] + wrong, changed, opt_out, no_marker, held = [], 0, 0, [], [] for c in (c for c in cases if c['fn'] in fns): got = json.loads(json.dumps(fns[c['fn']](*c['args']))) if got == c['out']: @@ -90,12 +91,19 @@ def test_every_recorded_call_gives_the_source_answer(self): and SOURCE.looks_problem(*c['args']) == c['out']: no_marker.append(body) # issue #865: no lens marker, no lens report (named, never blocking) continue + if c['fn'] == 'lens_problem' and SOURCE.report_problem(*c['args'])[1] == lens.HELD \ + and got.endswith(f'; it looks like one: {c["out"]}'): + held.append(body) # issue #865: no lens marker but an open finding: it blocks as before, with the fix + continue wrong.append(f'{c["fn"]}{json.dumps(c["args"])[:160]}: got {got!r}, source {c["out"]!r}') self.assertEqual(wrong, [], f'{len(wrong)} of {len(cases)} differ; first: {wrong[:3]}') self.assertEqual(changed, 54, 'answers changed on purpose (a short read or an edited lens comment)') self.assertEqual(opt_out, 2, 'answers changed on purpose (a hex read at below not a lens:, issue #77)') - self.assertEqual(len(no_marker), 7 + 3, 'answers changed on purpose (no lens marker, issue #865)') - for body in (b for b in no_marker if isinstance(b, str)): # a lens heading, `safe to merge`, report fields: never a `lens:` line or a read + self.assertEqual(len(no_marker), 6 + 3, 'answers changed on purpose (no lens marker, issue #865)') + self.assertEqual(len(held), 1, 'old state: a report with an open finding and no marker blocks as before') + self.assertIn('finding: major', held[0]) + # a lens heading, `safe to merge`, report fields: never a `lens:` line or a read + for body in (b for b in no_marker if isinstance(b, str)): self.assertNotRegex(body, r'(?im)^\W*lens\s*:|read[\s-]*at\b\W*[0-9a-f]{7}') @@ -256,12 +264,19 @@ def test_the_way_out_names_the_quote_and_never_reads_as_a_report(self): class Marker(unittest.TestCase): """Issue #865: a comment is a lens report only when it carries the lens marker (lens.has_marker: a line starting `lens:`, a lens field naming a sha, or `read at `). One that only looks like a report without it is no lens - report: it neither reads nor blocks, and not_lens_reports names it (the head check's summary). A lens report that - is not one valid read still blocks.""" + report: it neither reads nor blocks, and not_lens_reports names it (the head check's summary), unless it holds an + open finding (a blocker or major that is not none, or NOT SAFE): then it blocks, as a NO_HEADER entry whose reason + names the missing marker and the fix (report_problem kind HELD). A lens report that is not one valid read still + blocks.""" READ = f'lens: correctness · reviewer: x · read at: {SHA_B}\nstate: fine\nblocker: none\nmajor: none' NEAR = ('## Lens A\nblocker: none\nmajor: none', '## Lens correctness\nsafe to merge: yes', 'lgtm, safe to merge', 'covered: a.py\nchecks: ran the tests', 'The merge-path lens: nothing found', - '**Lens correctness** (round 2)\nverdict: not safe to merge') + '## Lens A, round 2\nblocker: none\nmajor: none\nminor: a typo') + HELD = ('## Lens correctness, round 2\nblocker: a re-run loses data\nmajor: none', + '**Lens correctness** (round 2)\nverdict: not safe to merge', + 'NOT SAFE to merge (code lens, round 2)\nmore below', + 'Code lens, round 2\nsafe to merge: no\nmajor: the retry drops a row', '## Lens A\nmajor: x is cut', + 'covered: a.py\nchecks: ran them\nfinding: blocker a.py:3 loses data') BROKEN = (f'Here is my review.\n{READ}', # the header not on the first line f'{READ}\nlens: state · reviewer: x · read at: {SHA_B}', # two lenses in one comment 'lens: · reviewer: x · read at: \nmajor: none', # a placeholder name: names no lens @@ -306,12 +321,62 @@ def test_a_valid_report_and_a_plain_comment_read_as_before(self): # old commen self.assertEqual((self.r.lens_problem(post(opt_out)), self.r.not_lens_report(post(opt_out))), (None, None)) def test_every_problem_with_the_marker_is_the_old_answer(self): # the marker only ever drops a block - for body in self.NEAR + self.BROKEN + (self.READ, 'Thanks', f'not a lens: x\nread at: {SHA_B}'): + for body in self.NEAR + self.HELD + self.BROKEN + (self.READ, 'Thanks', f'not a lens: x\nread at: {SHA_B}'): with self.subTest(body=body): looks, now = self.r.looks_problem(post(body)), self.r.lens_problem(post(body)) - self.assertEqual(now, looks if lens.has_marker(body) else None) + if lens.has_marker(body): + self.assertEqual(now, looks) + elif looks and review_judge.findings(body): # an open finding without the marker blocks as before + self.assertTrue(now.startswith(lens.NO_MARKER) and now.endswith(f'; it looks like one: {looks}')) + else: + self.assertIsNone(now) self.assertEqual(self.r.not_lens_report(post(body)) is not None, looks is not None and now is None) + def test_an_unmarked_report_with_an_open_finding_blocks_and_names_the_fix(self): # issue #865 round 1 + for body in self.HELD: + with self.subTest(body=body): + self.assertFalse(lens.has_marker(body)) + why = self.r.lens_problem(post(body)) + self.assertTrue(why.startswith(lens.NO_MARKER), why) + self.assertIn(lens.REPOST, why) + self.assertEqual(self.r.report_problem(post(body))[1], lens.HELD) + self.assertIsNone(self.r.not_lens_report(post(body))) + alone = pr(post(body, url='https://github.test/c2')) + self.assertEqual(self.r.reviewed_head(alone)[:2], (True, None), 'no required lens: still held') + self.assertEqual([w for w, _ in self.r.unmarked_held(alone)], ['https://github.test/c2']) + for older, newer in ((post(self.READ), post(body, when='2026-01-02T00:00:00Z')), + (post(body), post(self.READ, when='2026-01-02T00:00:00Z'))): + p = pr(older, newer) # newest wins never lets an older clean read through, and a newer one + reviewed, sha, why = self.r.reviewed_head(p) # does not clear it (keyed by the comment) + self.assertEqual((reviewed, sha), (True, None)) + self.assertIn(lens.NO_MARKER, why) + self.assertEqual(self.r.reviewed_head(p), (reviewed, sha, why), 'run again: the same answer') + self.assertEqual(self.r.not_lens_reports(p), []) + self.assertEqual(self.r.lens_scan(p)[1], [('correctness', SHA_B)], 'no round of its own') + self.assertEqual(self.lines, [], 'a blocking entry is in the verdict, not only in the log') + + def test_an_unmarked_report_with_an_open_finding_posted_twice_holds_twice(self): + p = pr(post(self.READ), post(self.HELD[0], url='https://github.test/c2', when='2026-01-02T00:00:00Z'), + post(self.HELD[0], url='https://github.test/c3', when='2026-01-03T00:00:00Z')) + self.assertEqual([w for w, _ in self.r.unmarked_held(p)], ['https://github.test/c2', 'https://github.test/c3']) + self.assertEqual(sum(k.startswith(lens.NO_HEADER) for k in self.r.lens_scan(p)[0]), 2) + + def test_the_ways_out_of_an_unmarked_report_with_an_open_finding(self): + held = self.HELD[0] + gone = pr(post(self.READ)) # deleted: GitHub no longer lists it + self.assertEqual(self.r.reviewed_head(gone), (True, SHA_B, 'every lens read it')) + opted = post(f'not a lens: round 2 notes\n{held}', when='2026-01-02T00:00:00Z', includesCreatedEdit=True) + self.assertEqual(self.r.reviewed_head(pr(post(self.READ), opted)), (True, SHA_B, 'every lens read it')) + marked = post(f'lens: correctness · reviewer: x · read at: {SHA_B}\n{held}', when='2026-01-02T00:00:00Z', + includesCreatedEdit=True) # the marker edited in: an edited report reads nothing, post anew + reviewed, sha, why = self.r.reviewed_head(pr(post(self.READ), marked)) + self.assertEqual((reviewed, sha), (True, None)) + self.assertIn(lens.EDITED, why) + for flags in ({'includesCreatedEdit': True}, {'isMinimized': True}): # edited or hidden: still holds + with self.subTest(flags=flags): + p = pr(post(self.READ), post(held, when='2026-01-02T00:00:00Z', **flags)) + self.assertEqual(self.r.reviewed_head(p)[:2], (True, None)) + def test_the_marker_is_read_both_ways_and_in_any_markdown(self): for body in ('**Lens:** a', '## lens: a', '- lens: a', '> lens: a', ' lens: a', f'| read at | {SHA_B} |', f'read at: `{SHA_B[:7]}`', f'lens: x · read at: {SHA_B}', @@ -333,6 +398,8 @@ def test_a_report_edited_to_drop_its_marker_is_as_if_deleted(self): # GitHub k dropped = post(self.NEAR[0].replace('Lens A', 'Lens correctness'), when='2026-01-02T00:00:00Z', includesCreatedEdit=True) self.assertEqual(self.r.reviewed_head(pr(post(self.READ), dropped)), (True, SHA_B, 'every lens read it')) + dropped = post(self.HELD[0], when='2026-01-02T00:00:00Z', includesCreatedEdit=True) # but an open finding + self.assertEqual(self.r.reviewed_head(pr(post(self.READ), dropped))[:2], (True, None)) kept = post(self.READ.replace(SHA_B, SHA_A), when='2026-01-02T00:00:00Z', includesCreatedEdit=True) reviewed, sha, why = self.r.reviewed_head(pr(post(self.READ), kept)) self.assertEqual((reviewed, sha), (True, None), 'an edited report with its marker still reads nothing') diff --git a/fork-ci/actions/pr-queue/review.vectors.json b/fork-ci/actions/pr-queue/review.vectors.json index 403234c110331..89b2b6dc8b381 100644 --- a/fork-ci/actions/pr-queue/review.vectors.json +++ b/fork-ci/actions/pr-queue/review.vectors.json @@ -1,5 +1,5 @@ { - "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a lens report, one with the lens marker, that is not one valid read is a `comment without a first-line lens header` entry that reads nothing; `not_lens`, when there is one: [where, why] of each post that looks like a report but has no lens marker, so is no lens report, as lens.Review.not_lens_reports names them). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). `reads`: posts as in `scans` (each by its `author`, else `someone`; an override comment is ` : ...`), the `head`, the reads that are its change merged with the base (`same`) and `override_authors`, under the `basic` rules in enforce with findings judged: lens.Review.lens_reads (each lens key's sha), the keys head_check.review_rounds fails until that lens posts again (`again`: UNREAD, or a report with no findings section) and whether head_check.verdict with the `required` lenses and the rounds pass (`passes`); T3's lens_start reads the same (lensStart.ts), and its vectors hold no finding and stay under the round cap. `unicode`: `refused` is what T3 refuses on a runtime that assigns those code points (a letter, number, mark, format character or space there): a new symbol reads alike on both sides. Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", + "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a lens report, one with the lens marker, that is not one valid read is a `comment without a first-line lens header` entry that reads nothing, and so is a post without the marker that looks like a report and holds an open finding (a blocker or major, or NOT SAFE, as review_judge.read_findings reads it); `not_lens`, when there is one: [where, why] of each post that looks like a report but has no lens marker, so is no lens report, as lens.Review.not_lens_reports names them). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). `reads`: posts as in `scans` (each by its `author`, else `someone`; an override comment is ` : ...`), the `head`, the reads that are its change merged with the base (`same`) and `override_authors`, under the `basic` rules in enforce with findings judged: lens.Review.lens_reads (each lens key's sha), the keys head_check.review_rounds fails until that lens posts again (`again`: UNREAD, or a report with no findings section) and whether head_check.verdict with the `required` lenses and the rounds pass (`passes`); T3's lens_start reads the same (lensStart.ts), and its vectors hold no finding in a report that counts and stay under the round cap. `unicode`: `refused` is what T3 refuses on a runtime that assigns those code points (a letter, number, mark, format character or space there): a new symbol reads alike on both sides. Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", "config_path": ".github/pr-queue.json", "override_prefix": "override for head", "globs": [ @@ -2295,13 +2295,13 @@ ] }, { - "name": "a report edited to drop its marker counts as deleted", + "name": "a report with no open finding edited to drop its marker counts as deleted", "posts": [ { "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" }, { - "body": "## Code lens\nmajor: x is cut", + "body": "## Code lens\nblocker: none\nmajor: none", "edited": true } ], @@ -2316,6 +2316,26 @@ ] ] }, + { + "name": "a report with an open major edited to drop its marker still holds", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none" + }, + { + "body": "## Code lens\nmajor: x is cut", + "edited": true + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Code lens')": [ + null, + null + ] + } + }, { "name": "a report edited with its marker kept reads nothing", "posts": [ @@ -2367,6 +2387,137 @@ null ] } + }, + { + "name": "a clean read then a newer unmarked report with an open blocker holds the head (issue 865)", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ] + } + }, + { + "name": "a clean read then a newer unmarked NOT SAFE verdict holds the head", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\nverdict: not safe to merge" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ] + } + }, + { + "name": "an unmarked report with an open major holds the head", + "posts": [ + { + "body": "Code lens, round 2\nsafe to merge: no\nmajor: the retry drops a row" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with 'Code lens, round 2')": [ + null, + null + ] + } + }, + { + "name": "an unmarked report with an open blocker posted twice holds twice", + "posts": [ + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none" + }, + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ] + } + }, + { + "name": "an unmarked report with an open blocker still holds when edited or hidden", + "posts": [ + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none", + "edited": true + }, + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none", + "hidden": true + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2', hidden)": [ + null, + null + ] + } + }, + { + "name": "a clean read then a newer unmarked note with no open finding leaves the read and is named", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\nblocker: none\nmajor: none\nminor: a typo" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + }, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:01Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Lens code, round 2'" + ] + ] + }, + { + "name": "an unmarked report with an open blocker edited to start with not a lens is no report", + "posts": [ + { + "body": "not a lens: round 2 notes\n## Lens code, round 2\nblocker: a re-run loses data\nmajor: none", + "edited": true + } + ], + "history": [], + "entries": {} } ], "rounds": [ @@ -3427,6 +3578,110 @@ "again": ["code"], "passes": false } + }, + { + "name": "a clean read then a newer unmarked report with an open blocker fails (issue 865)", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "a clean read then a newer unmarked NOT SAFE verdict fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\nverdict: not safe to merge" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "a clean read then an unmarked heading-only note passes", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Code lens\nAll fine." + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "no required lens and only an unmarked report with an open blocker fails", + "posts": [ + { + "body": "## Lens code, round 2\nblocker: a re-run loses data\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": [], + "expect": { + "reads": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "no required lens and only an unmarked note with no open finding passes", + "posts": [ + { + "body": "## Lens code, round 2\nblocker: none\nmajor: none\nminor: a typo" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": [], + "expect": { + "reads": {}, + "again": [], + "passes": true + } } ], "linear": [ diff --git a/fork-ci/actions/pr-queue/review_judge.test.py b/fork-ci/actions/pr-queue/review_judge.test.py index 9a525d015146e..ed63b7bdc3de5 100644 --- a/fork-ci/actions/pr-queue/review_judge.test.py +++ b/fork-ci/actions/pr-queue/review_judge.test.py @@ -391,7 +391,7 @@ def vector_pr(posts): def scan(posts): - found, history, notes = SCAN.scan_posts(vector_pr(posts)) + found, history, notes, _ = SCAN.scan_posts(vector_pr(posts)) return [list(h) for h in history], {k: [v[1], v[2]] for k, v in found.items()}, [list(n) for n in notes] diff --git a/fork-kit/review/COMMENTS.md b/fork-kit/review/COMMENTS.md index 1886ac7792e7e..324ccd9e93993 100644 --- a/fork-kit/review/COMMENTS.md +++ b/fork-kit/review/COMMENTS.md @@ -2,8 +2,11 @@ A lens posts its report as one pull request comment. The merge gate (`fork-ci/actions/pr-queue`) reads that comment with fixed rules. A comment that carries the lens marker (below) is a lens report, and the gate fails closed on it: one -that is not exactly one valid read blocks the head. A comment without the marker is no lens report however much it -looks like one: it never reads and never blocks, and the gate's summary names it `not a lens report` with the reason. +that is not exactly one valid read blocks the head. A comment without the marker that looks like a report is no lens +report and never reads. It blocks only when it holds an open finding (a `blocker:` or `major:` line that is not +`none`, or NOT SAFE): then it is most likely a real report with a broken header, so it holds the head whatever an older +or newer read of that lens says, until it is deleted or starts with `not a lens:`. One with no open finding never +blocks, and the gate's summary names it `not a lens report` with the reason. This page shows the format with examples. The rules themselves are the gate's code and its README (sections [Lens comments](../../fork-ci/actions/pr-queue/README.md#lens-comments) and [Review rules](../../fork-ci/actions/pr-queue/README.md#review-rules)); the gate's test vectors @@ -28,7 +31,10 @@ list and heading marks), in a code block or quote too: A real report has it on its first line, the header. The marker decides only whether a comment is a lens report; the rest of this page decides whether that report is one valid read. A heading such as `## Lens A`, `safe to merge`, or `covered:` and `checks:` lines are no marker: such a comment is `not a lens`, `no lens marker`, and a lens whose report -reads that way has posted nothing the gate counts (a required lens then still has no read). +reads that way has posted nothing the gate counts (a required lens then still has no read). If it holds an open finding +it is `reads nothing`, `no lens marker` and blocks. Either way the fix is a NEW comment whose first line is +`lens: · reviewer: · read at: `: editing the marker into the old comment does not count (an edited +comment reads nothing). ## The shape @@ -66,20 +72,20 @@ minor: ; Each example says, on the line before it, what the gate reads, as words: -| Words | Meaning | -| --------------------- | ------------------------------------------------------------------------------------------------------------------ | -| `lens ` | a lens header naming this lens (`lens_key`: lowercased, a trailing round marker dropped) | -| `round ` | the header carries round marker `r` | -| `read` | the header names a full sha: this is a read of that head | -| `short sha`, `no sha` | the header's sha is short or missing: no read | -| `clean` | a findings section with no blocker and no major | -| `blocker`, `major` | an open blocker or major: the gate holds the head until a new read on a fixed head, or a person | -| `no findings section` | no blocker and major labels: with `findings` on, the gate does not take the read | -| `state`, `no state` | a `state:` line with an answer, or none | -| `reads nothing` | carries the lens marker but is not one valid read: the gate counts it as a blocking problem | -| `no lens marker` | looks like a lens report but carries no lens marker: no lens report, never a read or a block, named in the summary | -| `not a lens` | not a lens report at all (a plain comment, or one that opts out with `not a lens:`): ignored | -| `override` | an override comment for that sha (counts only from the configured author association, never edited and not hidden) | +| Words | Meaning | +| --------------------- | ------------------------------------------------------------------------------------------------------------------- | +| `lens ` | a lens header naming this lens (`lens_key`: lowercased, a trailing round marker dropped) | +| `round ` | the header carries round marker `r` | +| `read` | the header names a full sha: this is a read of that head | +| `short sha`, `no sha` | the header's sha is short or missing: no read | +| `clean` | a findings section with no blocker and no major | +| `blocker`, `major` | an open blocker or major: the gate holds the head until a new read on a fixed head, or a person | +| `no findings section` | no blocker and major labels: with `findings` on, the gate does not take the read | +| `state`, `no state` | a `state:` line with an answer, or none | +| `reads nothing` | not one valid read that the gate counts as a blocking problem: it carries the lens marker, or holds an open finding | +| `no lens marker` | looks like a lens report but carries no lens marker: never a read; a block only with `reads nothing` (open finding) | +| `not a lens` | not a lens report at all (a plain comment, or one that opts out with `not a lens:`): ignored | +| `override` | an override comment for that sha (counts only from the configured author association, never edited and not hidden) | ## Good reports @@ -226,7 +232,7 @@ major: none ## Comments that read nothing or are no report A comment with the lens marker that is not one valid read blocks the head (`reads nothing`). One without the marker -is no report, however much it looks like one (`no lens marker`). +is no report, however much it looks like one (`no lens marker`), and it blocks only when it holds an open finding. No findings section: only a major label, no blocker label. The gate sees no section and does not take the read. @@ -305,6 +311,18 @@ blocker: none major: none ``` +A lens-like heading with no marker that holds an open finding: most likely a real report with a broken header, so it +blocks, whatever another read of that lens says. Delete it or start it with `not a lens:`, and post a new comment with +the header. + +The gate reads: `reads nothing, no lens marker` + +```text +## Lens A +blocker: a second run loses the saved rows +major: none +``` + A note between rounds (for example from the orchestrator, after it checked a fix diff) opts out with `not a lens:` on its first line. It must not hold a `read at` sha outside a `>` quote, so a sha goes on its own line. diff --git a/fork-kit/review/SKILL.md b/fork-kit/review/SKILL.md index 109524596ef6d..d0ced90df6788 100644 --- a/fork-kit/review/SKILL.md +++ b/fork-kit/review/SKILL.md @@ -196,8 +196,8 @@ python3 -I fork-kit/review/lib/review_kit.py check --root [--settings Exit 0 only for a read of that head with a findings section, no blocker or major, and a state line; otherwise exit 1, and it prints how the gate reads it. A report with a real blocker or major exits 1 **by design**: post it when the words read `read, blocker, state` or `read, major, state`. Never soften or drop a finding to get exit 0. Words -`not a lens, no lens marker` mean the gate would not see a report at all (COMMENTS.md, "The lens marker"): fix the -header, never post it that way. A project may +`not a lens, no lens marker` mean the gate would not see a report at all, and `reads nothing, no lens marker` mean it +blocks the head without reading it (COMMENTS.md, "The lens marker"): fix the header, never post it that way. A project may also have a check of the posted comment (who wrote it, edits): run it right after posting. A comment is never edited or hidden (an edited or hidden lens comment reads nothing): post a new one. A comment the gate reads as `reads nothing` keeps blocking the head even after a new post: delete it, or edit its first line to start with diff --git a/fork-kit/review/lib/review_kit.py b/fork-kit/review/lib/review_kit.py index f578d3e81ac89..d6718de014e1a 100644 --- a/fork-kit/review/lib/review_kit.py +++ b/fork-kit/review/lib/review_kit.py @@ -305,9 +305,12 @@ def verdict(body, override_prefix, head=None): post = {'body': body, 'authorAssociation': 'OWNER', 'includesCreatedEdit': False, 'createdAt': '1'} if review.override_sha(post): return ['override'] - if review.lens_problem(post): + kind = review.report_problem(post)[1] # the gate's one rule for a comment that looks like a report (issue #865) + if kind == lens.BROKEN: return ['reads nothing'] - if review.not_lens_report(post): # looks like a report, but without the lens marker it is none (issue #865) + if kind == lens.HELD: # no lens marker, but an open finding: it blocks until deleted or `not a lens:` + return ['reads nothing', 'no lens marker'] + if kind == lens.NOT_LENS: # no lens marker and no open finding: no report, never a read or a block return ['not a lens', 'no lens marker'] header = lens.lens_header(body) if not header: diff --git a/fork-kit/review/tests/comments.test.py b/fork-kit/review/tests/comments.test.py index 539694dd8f748..9feea1cd00e54 100644 --- a/fork-kit/review/tests/comments.test.py +++ b/fork-kit/review/tests/comments.test.py @@ -174,6 +174,13 @@ def test_a_look_alike_without_the_lens_marker_is_no_lens(self): # issue #865: self.assertEqual(self.verdict(body), 'not a lens, no lens marker') self.assertEqual(self.m.check(body, 'tool ready --head', SHA), (1, 'not a lens, no lens marker')) + def test_a_look_alike_without_the_lens_marker_with_an_open_finding_blocks(self): # issue #865 round 1 + for body in ('## Lens A\nblocker: a re-run loses data\nmajor: none', 'covered: a\nchecks: b\nmajor: a dropped row', + 'NOT SAFE to merge (lens A)\nmore below'): + with self.subTest(body=body): + self.assertEqual(self.verdict(body), 'reads nothing, no lens marker') + self.assertEqual(self.m.check(body, 'tool ready --head', SHA), (1, 'reads nothing, no lens marker')) + class Cli(unittest.TestCase): def setUp(self): @@ -239,10 +246,13 @@ def test_not_utf8_is_a_plain_message(self): "words.append('state')", (Check, 'test_a_missing_state_line_fails')), 'a short sha is no read': ("if not lens.FULL_SHA.fullmatch(sha or ''):", 'if not sha:', (Doc, 'test_every_example_reads_as_it_says')), - 'the gate flags a looking comment': ('if review.lens_problem(post):', 'if False:', + 'the gate flags a looking comment': ('if kind == lens.BROKEN:', 'if False:', (Check, 'test_a_looking_comment_reads_nothing')), - 'a look-alike without the marker is named': ('if review.not_lens_report(post):', 'if False:', + 'a look-alike without the marker is named': ('if kind == lens.NOT_LENS:', 'if False:', (Check, 'test_a_look_alike_without_the_lens_marker_is_no_lens')), + 'a look-alike with an open finding blocks': ( + 'if kind == lens.HELD:', 'if False:', + (Check, 'test_a_look_alike_without_the_lens_marker_with_an_open_finding_blocks')), 'every example is compared': ('if got != said:', 'if False:', (Doc, 'test_a_broken_example_fails')), 'the head is lowercased': ("sha != head.lower()", 'sha != head', (Check, 'test_the_head_is_matched_whatever_its_case')), From 236fa9f745afa98c8fedcd11bc19352add4ce3ff Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:45:06 +0100 Subject: [PATCH 3/3] fix(lens): an unmarked NOT SAFE under the heading or in a sentence still blocks (#865 round 2) - report_problem/reportProblem read a comment without the marker with read_findings(unmarked): its first two lines as heading and title line, and "not safe to merge" on any line outside a fenced block as NOT SAFE. Shared scans and reads vectors for both shapes, with and without a required lens; "not safe to run twice" stays clean. - head_gate's check-run summary shows a WARN row as warn, not ok. - One way-out constant per language (HELD_WAY_OUT); the head-check reason says the fix and the way out once and names held comments by where they are, also in "lenses found". - The queue posts a held reason with REPOST_PLAIN (the header described, lens-free) instead of a garbled header line. - Docs: a held comment also stops holding once edited to hold no open finding. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/fork/reviewRules/findings.ts | 21 +- .../src/fork/reviewRules/lensComment.ts | 8 +- fork-ci/RELEASE-NOTES.md | 13 +- fork-ci/actions/head-check/README.md | 10 +- fork-ci/actions/head-check/head_check.py | 23 ++- fork-ci/actions/head-check/head_check.test.py | 29 +++ fork-ci/actions/head-check/head_gate.py | 2 +- fork-ci/actions/head-check/head_gate.test.py | 8 + fork-ci/actions/pr-queue/README.md | 11 +- fork-ci/actions/pr-queue/lens.py | 33 ++- fork-ci/actions/pr-queue/lens.test.py | 50 ++++- fork-ci/actions/pr-queue/pr_queue.test.py | 13 ++ fork-ci/actions/pr-queue/review.vectors.json | 195 +++++++++++++++++- fork-ci/actions/pr-queue/review_judge.py | 16 +- fork-kit/review/COMMENTS.md | 22 +- 15 files changed, 395 insertions(+), 59 deletions(-) diff --git a/apps/server/src/fork/reviewRules/findings.ts b/apps/server/src/fork/reviewRules/findings.ts index 4811c425b4445..a3672bf15dcc4 100644 --- a/apps/server/src/fork/reviewRules/findings.ts +++ b/apps/server/src/fork/reviewRules/findings.ts @@ -45,6 +45,8 @@ const FINDINGS_NONE_RE = re( `^(?:findings|issues|problems)${S}*:${S}*(?:none|nothing|no|0|n/?a)${S}*\\.?${S}*$`, ); const NOT_SAFE_RE = re(`${B}not${S}+safe${B}`); +/** readFindings(unmarked): `not safe to merge` on any line (review_judge.NOT_SAFE_TO_MERGE_RE). */ +const NOT_SAFE_TO_MERGE_RE = re(`${B}not${S}+safe${S}+to${S}+merge${B}`); const VERDICT_NOT_SAFE_RE = re(`^verdict${S}*[:${EM}${EN}-]?${S}*not${S}+safe${B}`); const RULE_LINE_RE = new RegExp(`^${S}*(?:[-*_]${S}*){3,}$`, "u"); const HEADING_RE = new RegExp(`^ {0,3}#{1,6}(?:${S}|$)`, "u"); @@ -183,11 +185,14 @@ function read(lines: ReadonlyArray, narrow: boolean): Read { } /** - * [the report's blocker and major findings as [kind, line] in line order, whether it has a findings section]. Read - * both ways a lens line is read (narrow or not): a line either way reads as a finding is one. A first line (the header, - * or the title under it) or a `verdict:` line that says NOT SAFE is a blocker whatever the labels say. + * review_judge.read_findings: [[kind, line] of each blocker and major in line order, has a findings section]. A first + * line (the header or its title line) or a `verdict:` line saying NOT SAFE is a blocker. unmarked (no lens marker): the + * first two lines are read as heading and title, and `not safe to merge` outside a fence is a blocker on any line. */ -export function readFindings(body: string): [Array<[FindingKind, string]>, boolean] { +export function readFindings( + body: string, + unmarked = false, +): [Array<[FindingKind, string]>, boolean] { pyUnicodeCheck(body); const lines = splitlines(body); const found = new Map(); @@ -199,14 +204,18 @@ export function readFindings(body: string): [Array<[FindingKind, string]>, boole if (!found.has(i)) found.set(i, [kind, cut(text, SHOW_FINDING)]); } const top = [...lines.keys()].filter((i) => !isBlank(lines[i]!)).slice(0, 2); - const first = new Set(lensHeader(body) ? top : top.slice(0, 1)); + const first = new Set(unmarked || lensHeader(body) ? top : top.slice(0, 1)); let fence: string | null = null; for (const [i, raw] of lines.entries()) { let fenced: boolean; [fence, fenced] = fenceStep(fence, raw); if (fenced || found.has(i)) continue; const line = plain(raw, false); - if ((first.has(i) && NOT_SAFE_RE.test(line)) || VERDICT_NOT_SAFE_RE.test(line)) { + if ( + (first.has(i) && NOT_SAFE_RE.test(line)) || + VERDICT_NOT_SAFE_RE.test(line) || + (unmarked && NOT_SAFE_TO_MERGE_RE.test(line)) + ) { found.set(i, ["blocker", cut(`the report says NOT SAFE: ${line}`, SHOW_FINDING)]); } } diff --git a/apps/server/src/fork/reviewRules/lensComment.ts b/apps/server/src/fork/reviewRules/lensComment.ts index 443348faed01d..53176f9022a41 100644 --- a/apps/server/src/fork/reviewRules/lensComment.ts +++ b/apps/server/src/fork/reviewRules/lensComment.ts @@ -72,6 +72,8 @@ export const NO_MARKER = export const REPOST = "post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the " + "marker into an old comment does not count)"; +/** The one way out of a held comment (lens.HELD_WAY_OUT): delete it or opt it out. */ +const HELD_WAY_OUT = "delete the old one or edit it to start with `not a lens` and a colon"; /** * reportProblem's kinds (lens.BROKEN, HELD, NOT_LENS): a lens report (with the marker) that is not one valid read; a * comment without the marker that holds an open finding (both block); one without either (no report, never blocks). @@ -284,11 +286,11 @@ export function reportProblem( const problem = looksProblem(body, overridePrefix); if (!problem) return null; if (hasMarker(body)) return [problem, "broken"]; - const found = readFindings(body)[0]; + const found = readFindings(body, true)[0]; // no header: the title line and NOT SAFE prose count if (found.length > 0) { return [ - `${NO_MARKER}, but it holds an open ${found[0]![0]}: ${REPOST}, and delete this one or start it with ` + - `\`not a lens:\`; it looks like one: ${problem}`, + `${NO_MARKER}, but it holds an open ${found[0]![0]}: ${REPOST}, and ${HELD_WAY_OUT}; it looks like one: ` + + problem, "held", ]; } diff --git a/fork-ci/RELEASE-NOTES.md b/fork-ci/RELEASE-NOTES.md index 3fe71f6accc90..b5852d483b00f 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -21,11 +21,14 @@ it (Markdown stripped, in code blocks and quotes too). A lens report that is not before. A comment that only looks like one without the marker (a `## Lens A` heading, `safe to merge`, `covered:` and `checks:` lines) and holds no open finding no longer blocks: the run log and the head check's summary name it as `not a lens report` (a `WARN` row) with the reason. One without the marker that holds an open finding (a `blocker:` or -`major:` line that is not `none`, or NOT SAFE, as the findings rules read them) still blocks, as before, whatever an -older or newer read of that lens says: it is most likely a real report with a broken header. Its reason, first in the -head check's, says to post a NEW comment whose first line is `lens: · reviewer: · read at: ` -(editing the marker in does not count) and to delete the old one or start it with `not a lens:`. Comments with the -marker read exactly as before. T3's copy (`apps/server/src/fork/reviewRules`) and the review +`major:` line that is not `none`, NOT SAFE on its first two lines or a `verdict:` line, or `not safe to merge` on any +line outside a fenced code block) still blocks, as before, whatever an older or newer read of that lens says: it is +most likely a real report with a broken header. Its reason, first in the head check's, says to post a NEW comment +whose first line is `lens: · reviewer: · read at: ` (editing the marker in does not count) and to +delete the old one or edit it to start with `not a lens` and a colon; it also stops holding once edited so it holds +no open finding (the same people could delete it). The queue posts that reason with the header described in words, +so its comment never looks like a lens report. The head check's check run on the pull request shows the +`not a lens report` row as `warn` too. Comments with the marker read exactly as before. T3's copy (`apps/server/src/fork/reviewRules`) and the review kit's `check` read the same rule from the shared vectors. **Upgrade:** a lens report written without the marker now counts for nothing, so a lens that posts one has not diff --git a/fork-ci/actions/head-check/README.md b/fork-ci/actions/head-check/README.md index 68b16059f3df3..1b68735b8fa74 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -219,14 +219,18 @@ marker (the pr-queue README, "Lens comments") is no lens report. If it holds no open finding it gets a row `not a lens report ()`, `WARN` (`warn` in the summary: it passes, but is not green), with the reason, and never fails the check on its own. If it holds an open finding (a `blocker:` or `major:` line -that is not `none`, or NOT SAFE) it blocks, as a `fail` row, whether or not a +that is not `none`, NOT SAFE on its first two lines or a `verdict:` line, or +`not safe to merge` on any line outside a fenced code block) it blocks, as a `fail` row, whether or not a lens is required and whatever another read of that lens says. A required lens such a comment was meant to be still fails as missing. In both cases the failure reason starts with the fix: how many comments look like a lens report without the marker, and to post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker in does -not count). The hint to check the names in `required-lenses` appears only when -no such comment exists. +not count), and, for one that holds an open finding, to delete the old one or +edit it to start with `not a lens` and a colon. The rest of the reason names a +held comment only by where it is; its row says why. The hint to check the names +in `required-lenses` appears only when no such comment exists. The gate's check +run on the pull request (`head_gate.py`) shows the same `warn` row. | Exit | Meaning | | ---- | -------------------------------------------------------------------------------- | diff --git a/fork-ci/actions/head-check/head_check.py b/fork-ci/actions/head-check/head_check.py index e3a721e9c8005..e0a9ecef65f39 100644 --- a/fork-ci/actions/head-check/head_check.py +++ b/fork-ci/actions/head-check/head_check.py @@ -214,11 +214,12 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l reads = review.lens_reads(pr) reviewed, read, why = review.reviewed_head(pr) missing = [name for key, name in required.items() if key not in reads] - found = ', '.join(sorted(reads)) or 'none' # comments that look like a lens report but carry no lens marker and hold no open finding: no report, so they pass; # named in a WARN row, never silent. Those that hold an open finding block: NO_HEADER entries of reads (held). notes = [(f'{lens.NOT_LENS} ({where})', WARN, why) for where, why in review.not_lens_reports(pr)] held = review.unmarked_held(pr) + why = short_held(why, held) # the reason names a held comment by where it is: the fix is said once, first + found = short_held(', '.join(sorted(reads)), held) or 'none' if not reads and not required: return True, 'no lens comments and no required lens: nothing to compare', notes ok, how = same_change(checkout, head, read) if reviewed and read else (False, None) @@ -235,20 +236,28 @@ def verdict(pr, review, checkout, required=None, pass_drafts=False, rules_name_l rows += notes if missing: if notes or held: # the fix first: a look-alike is most likely the report, so no config hint - return False, (f'{marker_hint(len(notes) + len(held))}. Required lens without a read: ' + return False, (f'{marker_hint(len(notes) + len(held), held)}. Required lens without a read: ' f'{", ".join(missing)}; lenses found: {found}'), rows where = ' or the review rules of the config' if rules_name_lenses else '' return False, (f'required lens without a read: {", ".join(missing)}. No counted lens comment has that name: ' f'check it in required-lenses (one name per line){where}; lenses found: {found}'), rows if not read: - return False, (f'{marker_hint(len(held))}; each that holds an open finding blocks until it is deleted or ' - f'starts with `not a lens:`. {why}' if held else why), rows + return False, (f'{marker_hint(len(held), held)}. {why}' if held else why), rows return ok, how, rows -def marker_hint(count): - """The fix for comments that look like a lens report but carry no lens marker, first in a failure reason.""" - return f'{count} comment(s) look like a lens report but carry no lens marker: {lens.REPOST}' +def marker_hint(count, held=()): + """The fix for comments that look like a lens report but carry no lens marker, first in a failure reason; with + held ones (unmarked_held), the way out of those too (lens.HELD_WAY_OUT, the one wording).""" + out = f'{count} comment(s) look like a lens report but carry no lens marker: {lens.REPOST}' + return f'{out}, and {lens.HELD_WAY_OUT} (one that holds an open finding blocks until then)' if held else out + + +def short_held(text, held): + """text with each held comment's long reason (its NO_HEADER key) cut to where it is: its row says the rest.""" + for where, why in held: + text = text.replace(f'{where}, {why}', where) + return text def escape(text): diff --git a/fork-ci/actions/head-check/head_check.test.py b/fork-ci/actions/head-check/head_check.test.py index 9f40d0acdd452..8e7c4c68d52c1 100644 --- a/fork-ci/actions/head-check/head_check.test.py +++ b/fork-ci/actions/head-check/head_check.test.py @@ -435,6 +435,35 @@ def test_an_unmarked_look_alike_with_an_open_finding_still_fails(self): # issu self.assertTrue(why.startswith(H.marker_hint(1)), why) self.assertNotIn('required-lenses', why) + def test_not_safe_under_the_heading_or_in_a_sentence_still_fails(self): # issue #865 round 2: main blocked these + for body in (f'## {LENS.title()} merge-path, round 2\n\nNot safe to merge: the gate passes an unread head.', + '## Merge-path review\n\nNOT SAFE TO MERGE\n\ncovered: x\nchecks: y', + f'## {LENS.title()} correctness, round 2\n\n**NOT SAFE to merge**\n\ncovered: x\nchecks: y', + f'## {LENS.title()} correctness, round 2\n\ncovered: x\nchecks: y\n\nNot safe to merge: no.'): + for required in ('correctness', ''): + with self.subTest(body=body, required=required): + comments = [self.p.lens('correctness', A), self.p.post(body)] + ok, why, rows = self.verdict(comments, required=required) + self.assertFalse(ok, 'a clean read of the head never lets it through') + self.assertNotIn(lens.NOT_LENS, ' '.join(name for name, _, _ in rows)) + self.assertEqual(self.verdict(comments, required=required), (ok, why, rows), 'run again') + prose = (f'## {LENS.title()} correctness, round 2\n\ncovered: x\nchecks: y\n\n' + 'The old code was not safe to run twice.') + ok, why, rows = self.verdict([self.p.lens('correctness', A), self.p.post(prose)], required='correctness') + self.assertTrue(ok, why) + self.assertEqual([good for _, good, _ in rows], [True, H.WARN]) + + def test_a_held_reason_says_the_fix_and_the_way_out_once(self): # round 2: "post a NEW comment" was there twice + body = f'## {LENS.title()} correctness, round 2\nblocker: a re-run loses data\nmajor: none' + for required in ('correctness', 'correctness\nsecurity', ''): + with self.subTest(required=required): + ok, why, rows = self.verdict([self.p.lens('correctness', A), self.p.post(body)], required=required) + self.assertFalse(ok) + self.assertTrue(why.startswith(H.marker_hint(1, ['held'])), why) + self.assertEqual((why.count('post a NEW comment'), why.count(lens.HELD_WAY_OUT)), (1, 1), why) + self.assertNotIn(lens.NO_MARKER, why, 'a held comment is named by where it is; its row says why') + self.assertEqual(sum(lens.NO_MARKER in name for name, _, _ in rows), 1, rows) + def test_a_deleted_comment_counts_no_more(self): # deleted: GitHub no longer lists it look_alike = self.p.post(f'read at: {A[:7]}') good = self.p.lens('correctness', A) diff --git a/fork-ci/actions/head-check/head_gate.py b/fork-ci/actions/head-check/head_gate.py index 3d0d289c0fec0..0712427e49715 100644 --- a/fork-ci/actions/head-check/head_gate.py +++ b/fork-ci/actions/head-check/head_gate.py @@ -711,7 +711,7 @@ def verdict_text(ok, reason, results, head, base): lines += [f'#### #{n}: {"pass" if good else "fail"}', '', head_check.cell(why), ''] if rows: lines += ['| lens | | reason |', '| --- | --- | --- |'] - lines += [f'| {head_check.cell(name)} | {"ok" if g else "fail"} | {head_check.cell(text)} |' + lines += [f'| {head_check.cell(name)} | {head_check.mark(g)} | {head_check.cell(text)} |' for name, g, text in rows] lines.append('') text = '\n'.join(lines) diff --git a/fork-ci/actions/head-check/head_gate.test.py b/fork-ci/actions/head-check/head_gate.test.py index ce3fe7a19e56d..7a9be4eb98129 100644 --- a/fork-ci/actions/head-check/head_gate.test.py +++ b/fork-ci/actions/head-check/head_gate.test.py @@ -1284,6 +1284,14 @@ def test_long_texts_are_cut_to_what_github_takes(self): _, _, run = self.start() self.assertNotIn('details_url', self.checks.runs[-1], 'no run id: no link') + def test_a_warn_row_shows_warn_on_the_check_run(self): # round 2: the not-a-lens row read ok on the PR's page + rows = [('correctness', True, 'read'), ('not a lens report (url)', H.WARN, 'no marker'), + ('security', False, 'reads nothing')] + _, text = G.verdict_text(True, 'r', [(7, 1, True, 'r', rows)], self.SHA, self.SHA) + self.assertIn('| correctness | ok | read |', text) + self.assertIn('| not a lens report (url) | warn | no marker |', text) + self.assertIn('| security | fail | reads nothing |', text) + def test_a_verdict_text_is_cut_too(self): rows = [(f'lens{i}', False, 'x' * 100) for i in range(1000)] title, text = G.verdict_text(False, 'r' * 300, [(7, 1, False, 'r', rows)], self.SHA, self.SHA) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 50720af0de02a..8443a22c4f22f 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -579,13 +579,17 @@ names it, and the head check's summary lists it as `not a lens report` (a account, held pull requests with no one seeing why). A lens whose report has no marker has therefore posted nothing: a required lens still has no read, and the head check fails on that. If it holds an open finding (a `blocker:` or `major:` -line that is not `none`, or NOT SAFE, as the findings rules below read them) it +line that is not `none`, or NOT SAFE, as the findings rules below read them, +with its first two lines read as a heading and its title line, and +`not safe to merge` on any line outside a fenced code block read as NOT SAFE) it is most likely a real report with a broken header, so it blocks like a broken lens report, keyed by that comment, whatever an older or newer read of that lens says: an older clean read never wins over it. Its reason says to post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into the old comment does not count: an edited comment -reads nothing) and to delete the old one or start it with `not a lens:`. Lenses check their +reads nothing) and to delete the old one or edit it to start with `not a lens` +and a colon. It also stops holding once edited so it holds no open finding: the +same people could delete it, and the gate keeps no history. Lenses check their comment with the review kit's `check` before posting (fork-kit/review). A comment that is no report but holds a marker says so on its first line, `not a lens: ...`. That clears it unless one of @@ -625,7 +629,8 @@ 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. The ways out: delete it, edit its first line to `not a lens: ...` with no lens header line left in it and any `read at ` quoted with `>`, or post an -override for the head. +override for the head. One without the marker also stops holding once it is +edited so it holds no open finding (the same people could delete it). These shapes were measured on this repository's 677 pull request comments by people (November 2026, before the lens marker rule): 25 are flagged, before and diff --git a/fork-ci/actions/pr-queue/lens.py b/fork-ci/actions/pr-queue/lens.py index 675c05395d7b7..c6585d2ad6200 100644 --- a/fork-ci/actions/pr-queue/lens.py +++ b/fork-ci/actions/pr-queue/lens.py @@ -87,6 +87,15 @@ # How a lens fixes a report without the marker, for the reasons (the queue posts them through no_lens_text). REPOST = ('post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the ' 'marker into an old comment does not count)') +# REPOST as the queue posts it (no_lens_text): the header described, not written, so the queue's comment never looks +# like a lens report, and nothing in it is garbled by the cleaning. +REPOST_PLAIN = ('post a NEW comment whose first line is the lens header as the format doc writes it (`lens`, a colon, ' + 'the lens name, the reviewer and the full sha it read); editing the marker into an old comment does ' + 'not count') +# The one way out of a comment without the marker that holds an open finding (kind HELD), in its reason and in the head +# check's: it holds until then (or until it is edited so it holds no open finding, which is the same as deleting it). +# Lens-free as written (no `lens:`): the queue posts it. +HELD_WAY_OUT = 'delete the old one or edit it to start with `not a lens` and a colon' OK_CONCLUSIONS = ('SUCCESS', 'SKIPPED', 'NEUTRAL') STRANGER_SCAN = 4096 # characters of a post that does not count read to decide whether to log it @@ -299,18 +308,26 @@ def no_lens_text(text, keep_markdown=False): 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 - either way (clean_inline narrow or not), it holds none of these; otherwise it is cleaned like any other text.""" + either way (clean_inline narrow or not), it holds none of these; otherwise it is cleaned like any other text. A + REPOST in the text (a held reason) is posted as REPOST_PLAIN, as written, when the whole stays free of them.""" + if REPOST in text: + out = REPOST_PLAIN.join(no_lens_text(part, keep_markdown) for part in text.split(REPOST)) + if _lens_free(out): + return out + if keep_markdown and _lens_free(text): # the reader cleans the text as written once, either way + return text plain = clean_inline(text) - 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 _lens_free(text): + """No lens form no_lens_text names in the text read without its markdown either way (clean_inline narrow or not).""" + return all(_no_lens_forms(clean_inline(text, narrow)) == clean_inline(text, narrow) for narrow in (False, True)) + + 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) @@ -399,10 +416,10 @@ def report_problem(self, post): if has_marker(body): return problem, BROKEN import review_judge # noqa: PLC0415 - review_judge imports this module - found = review_judge.findings(body) + found = review_judge.findings(body, unmarked=True) # no header: the title line and NOT SAFE prose count if found: - return (f'{NO_MARKER}, but it holds an open {found[0][0]}: {REPOST}, and delete this one or start it with ' - f'`not a lens:`; it looks like one: {problem}'), HELD + return (f'{NO_MARKER}, but it holds an open {found[0][0]}: {REPOST}, and {HELD_WAY_OUT}; it looks like one: ' + f'{problem}'), HELD return f'{NO_MARKER}; it looks like one: {problem}', NOT_LENS def lens_problem(self, post): diff --git a/fork-ci/actions/pr-queue/lens.test.py b/fork-ci/actions/pr-queue/lens.test.py index ffbd8ee83c7ce..92d5b843cd881 100644 --- a/fork-ci/actions/pr-queue/lens.test.py +++ b/fork-ci/actions/pr-queue/lens.test.py @@ -271,12 +271,19 @@ class Marker(unittest.TestCase): READ = f'lens: correctness · reviewer: x · read at: {SHA_B}\nstate: fine\nblocker: none\nmajor: none' NEAR = ('## Lens A\nblocker: none\nmajor: none', '## Lens correctness\nsafe to merge: yes', 'lgtm, safe to merge', 'covered: a.py\nchecks: ran the tests', 'The merge-path lens: nothing found', - '## Lens A, round 2\nblocker: none\nmajor: none\nminor: a typo') + '## Lens A, round 2\nblocker: none\nmajor: none\nminor: a typo', + '## Lens A, round 2\n\ncovered: x\nchecks: y\n\nThe old code was not safe to run twice.', # no "to merge" + '## Lens A, round 2\n\ncovered: x\n\n```\nNot safe to merge: an example\n```') # in a fence HELD = ('## Lens correctness, round 2\nblocker: a re-run loses data\nmajor: none', '**Lens correctness** (round 2)\nverdict: not safe to merge', 'NOT SAFE to merge (code lens, round 2)\nmore below', 'Code lens, round 2\nsafe to merge: no\nmajor: the retry drops a row', '## Lens A\nmajor: x is cut', - 'covered: a.py\nchecks: ran them\nfinding: blocker a.py:3 loses data') + 'covered: a.py\nchecks: ran them\nfinding: blocker a.py:3 loses data', + # round 2: NOT SAFE on the line under the heading (the title line), or in a sentence further down + '## Lens correctness, round 2\n\n**NOT SAFE to merge**\n\ncovered: x\nchecks: y', + '## Merge-path review\n\nNOT SAFE TO MERGE\n\ncovered: x\nchecks: y', + '## Lens merge-path, round 2\n\nNot safe to merge: the gate passes an unread head.', + '## Lens correctness, round 2\n\ncovered: x\nchecks: y\n\nNot safe to merge: the gate passes an unread head.') BROKEN = (f'Here is my review.\n{READ}', # the header not on the first line f'{READ}\nlens: state · reviewer: x · read at: {SHA_B}', # two lenses in one comment 'lens: · reviewer: x · read at: \nmajor: none', # a placeholder name: names no lens @@ -326,7 +333,7 @@ def test_every_problem_with_the_marker_is_the_old_answer(self): # the marker o looks, now = self.r.looks_problem(post(body)), self.r.lens_problem(post(body)) if lens.has_marker(body): self.assertEqual(now, looks) - elif looks and review_judge.findings(body): # an open finding without the marker blocks as before + elif looks and review_judge.findings(body, unmarked=True): # an open finding without the marker blocks self.assertTrue(now.startswith(lens.NO_MARKER) and now.endswith(f'; it looks like one: {looks}')) else: self.assertIsNone(now) @@ -355,6 +362,43 @@ def test_an_unmarked_report_with_an_open_finding_blocks_and_names_the_fix(self): self.assertEqual(self.r.lens_scan(p)[1], [('correctness', SHA_B)], 'no round of its own') self.assertEqual(self.lines, [], 'a blocking entry is in the verdict, not only in the log') + def test_not_safe_under_the_heading_or_in_a_sentence_holds(self): # issue #865 round 2: main blocked these + for body in self.HELD[-4:]: + with self.subTest(body=body): + self.assertEqual(review_judge.findings(body), [], 'read as a marked report, no finding: the old hole') + self.assertEqual(review_judge.findings(body, unmarked=True)[0][0], 'blocker') + self.assertEqual(self.r.report_problem(post(body))[1], lens.HELD) + p = pr(post(self.READ), post(body, url='https://github.test/c2', when='2026-01-02T00:00:00Z')) + self.assertEqual(self.r.reviewed_head(p)[:2], (True, None), 'an older clean read never wins') + self.assertEqual(self.r.reviewed_head(p), self.r.reviewed_head(p), 'run again: the same answer') + self.assertEqual(review_judge.findings(self.NEAR[-2], unmarked=True), [], 'not safe to run twice: no verdict') + self.assertEqual(review_judge.findings(self.NEAR[-1], unmarked=True), [], 'in a code block: an example') + + def test_a_held_comment_edited_to_hold_no_open_finding_stops_holding(self): # the same as deleting it + for body in (self.HELD[0], self.HELD[-1]): + with self.subTest(body=body): + edited = (body.replace('a re-run loses data', 'none') if 'blocker:' in body + else body.replace('Not safe to merge', 'Safe to merge')) + p = pr(post(self.READ), post(edited, url='https://github.test/c2', when='2026-01-02T00:00:00Z', + includesCreatedEdit=True)) + self.assertEqual(self.r.reviewed_head(p), (True, SHA_B, 'every lens read it')) + self.assertEqual([w for w, _ in self.r.not_lens_reports(p)], ['https://github.test/c2']) + + def test_the_queue_posts_a_held_reason_readable_and_lens_free(self): # round 2: it read "lens- · reviewer:" + for text in (lens.REPOST_PLAIN, lens.HELD_WAY_OUT): + self.assertEqual(lens.no_lens_text(text, keep_markdown=True), text) + for body in (self.HELD[0], self.HELD[-1]): + with self.subTest(body=body): + why = self.r.lens_problem(post(body)) + self.assertIn(lens.REPOST, why) + out = lens.no_lens_text(' '.join(why.split())) + self.assertIn(lens.REPOST_PLAIN, out) + self.assertNotIn('lens- ·', out) + self.assertIn(lens.HELD_WAY_OUT.replace('`', ''), out, 'the way out stays readable') + self.assertNotIn('not a lens-', out) + self.assertTrue(lens._lens_free(out), out) + self.assertIsNone(self.r.looks_problem(post(out)), 'the queue comment never looks like a report') + def test_an_unmarked_report_with_an_open_finding_posted_twice_holds_twice(self): p = pr(post(self.READ), post(self.HELD[0], url='https://github.test/c2', when='2026-01-02T00:00:00Z'), post(self.HELD[0], url='https://github.test/c3', when='2026-01-03T00:00:00Z')) diff --git a/fork-ci/actions/pr-queue/pr_queue.test.py b/fork-ci/actions/pr-queue/pr_queue.test.py index 233b088858717..8b567cf49c9c0 100644 --- a/fork-ci/actions/pr-queue/pr_queue.test.py +++ b/fork-ci/actions/pr-queue/pr_queue.test.py @@ -619,6 +619,19 @@ def test_a_multi_line_gh_error_is_quoted_on_one_line(self): # no `covered:`/`c self.assertIn('checks', why) self.assertTrue(needs.startswith('Needs a lens read'), needs) + def test_a_held_reason_is_posted_readable(self): # issue #865 round 2: it read "first line is lens- · reviewer:" + f = self.fake() + self.q.gh = self.q.gh_write = f + r = lens.Review((), 'tool ready --head', 'OWNER', ('OWNER',)) + held = r.lens_problem({'body': '## Lens code, round 2\nblocker: a re-run loses data', 'author': {'login': 'x'}}) + self.assertIn(lens.REPOST, held) + self.assertEqual(run_quiet(self.q.leave_off, 7, f'{lens.NO_HEADER} (url, {held})')[0], 0) + why = f.comments[0].split('\n')[0] + self.assertIn(lens.REPOST_PLAIN, why) + self.assertIn(lens.HELD_WAY_OUT.replace('`', ''), why) + self.assertNotIn('lens- ·', why) + self.assertIsNone(r.looks_problem({'body': f.comments[0]}), 'the queue comment never looks like a report') + 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) diff --git a/fork-ci/actions/pr-queue/review.vectors.json b/fork-ci/actions/pr-queue/review.vectors.json index 89b2b6dc8b381..6d28eb9c60d72 100644 --- a/fork-ci/actions/pr-queue/review.vectors.json +++ b/fork-ci/actions/pr-queue/review.vectors.json @@ -2330,7 +2330,7 @@ "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], "entries": { "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Code lens')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Code lens')": [ null, null ] @@ -2401,7 +2401,7 @@ "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], "entries": { "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ null, null ] @@ -2420,7 +2420,7 @@ "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], "entries": { "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ null, null ] @@ -2435,7 +2435,7 @@ ], "history": [], "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with 'Code lens, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open major: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with 'Code lens, round 2')": [ null, null ] @@ -2453,11 +2453,11 @@ ], "history": [], "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ null, null ], - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ null, null ] @@ -2477,11 +2477,11 @@ ], "history": [], "entries": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ null, null ], - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2', hidden)": [ + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2', hidden)": [ null, null ] @@ -2518,6 +2518,65 @@ ], "history": [], "entries": {} + }, + { + "name": "a clean read then a newer unmarked NOT SAFE on the line under its heading holds the head", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\n**NOT SAFE to merge**\n\ncovered: x\nchecks: y" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ] + } + }, + { + "name": "a clean read then a newer unmarked NOT SAFE to merge in a sentence holds the head", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\ncovered: x\nchecks: y\n\nNot safe to merge: the gate passes an unread head." + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": [ + null, + null + ] + } + }, + { + "name": "an unmarked NOT SAFE to merge in a code block or not safe in prose holds nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\ncovered: x\nchecks: y\n\nThe old code was not safe to run twice; this fixes it.\n\n```\nNot safe to merge: an example\n```" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + }, + "not_lens": [ + [ + "by someone at 2026-01-01T00:00:01Z", + "no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha); it looks like one: starts with '## Lens code, round 2'" + ] + ] } ], "rounds": [ @@ -3596,7 +3655,7 @@ "expect": { "reads": { "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null }, "again": [], "passes": false @@ -3619,7 +3678,7 @@ "expect": { "reads": { "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null }, "again": [], "passes": false @@ -3660,7 +3719,7 @@ "required": [], "expect": { "reads": { - "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete this one or start it with `not a lens:`; it looks like one: starts with '## Lens code, round 2')": null + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null }, "again": [], "passes": false @@ -3682,6 +3741,120 @@ "again": [], "passes": true } + }, + { + "name": "a clean read then a newer unmarked NOT SAFE on the line under its heading fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\n**NOT SAFE to merge**\n\ncovered: x\nchecks: y" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "no required lens: a clean read then a newer unmarked NOT SAFE on the line under its heading fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\n**NOT SAFE to merge**\n\ncovered: x\nchecks: y" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": [], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "a clean read then a newer unmarked NOT SAFE to merge in a sentence fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\ncovered: x\nchecks: y\n\nNot safe to merge: the gate passes an unread head." + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "no required lens: a clean read then a newer unmarked NOT SAFE to merge in a sentence fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\ncovered: x\nchecks: y\n\nNot safe to merge: the gate passes an unread head." + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": [], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, no lens marker (no line starts with `lens:`, and no `read at` or lens field names a sha), but it holds an open blocker: post a NEW comment whose first line is `lens: · reviewer: · read at: ` (editing the marker into an old comment does not count), and delete the old one or edit it to start with `not a lens` and a colon; it looks like one: starts with '## Lens code, round 2')": null + }, + "again": [], + "passes": false + } + }, + { + "name": "a clean read then an unmarked note that says not safe in prose passes", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "## Lens code, round 2\n\ncovered: x\nchecks: y\n\nThe old code was not safe to run twice; this fixes it." + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } } ], "linear": [ diff --git a/fork-ci/actions/pr-queue/review_judge.py b/fork-ci/actions/pr-queue/review_judge.py index 27846c55c69a7..e34f9b2888973 100644 --- a/fork-ci/actions/pr-queue/review_judge.py +++ b/fork-ci/actions/pr-queue/review_judge.py @@ -224,6 +224,7 @@ def judge(review, changes, config_path): FINDING_LINE_RE = re.compile(r'findings?\s*:\s*[\[(]?' + _KW + r'(?![^\W_])', re.I) # `finding: major x` FINDINGS_NONE_RE = re.compile(r'(?:findings|issues|problems)\s*:\s*(?:none|nothing|no|0|n/?a)\s*\.?\s*$', re.I) NOT_SAFE_RE = re.compile(r'\bnot\s+safe\b', re.I) +NOT_SAFE_TO_MERGE_RE = re.compile(r'\bnot\s+safe\s+to\s+merge\b', re.I) # read_findings(unmarked=True), any line VERDICT_NOT_SAFE_RE = re.compile(r'verdict\s*[:—–-]?\s*not\s+safe\b', re.I) RULE_LINE_RE = re.compile(r'\s*(?:[-*_]\s*){3,}') # a thematic break: no content HEADING_RE = re.compile(r' {0,3}#{1,6}(?:\s|$)') @@ -343,13 +344,15 @@ def _under(lines, start, narrow): return None -def read_findings(body): +def read_findings(body, unmarked=False): """(findings, has_section). findings: [(kind, line)] of the report's blocker and major findings in line order, kind 'blocker' or 'major', line as normalised (cut to SHOW_FINDING). Read both ways lens reads a line (clean_inline narrow or not): a line either way reads as a finding is one. has_section: the report has a blocker label and a major label (`blocker: none` and `major: none` too), or `findings: none`, or `finding: ` lines. A first line (the lens header, or the title line under it) or a `verdict:` line that says NOT SAFE is a blocker whatever the labels - say.""" + say. unmarked: a comment without the lens marker (lens.Review.report_problem): its first two lines are read as a + header and its title line are (a heading, then NOT SAFE under it), and `not safe to merge` on any line outside a + fenced code block is a blocker too.""" found = {} seen = set() for narrow in (False, True): @@ -359,14 +362,15 @@ def read_findings(body): found.setdefault(i, (kind, text[:SHOW_FINDING])) lines = (body or '').splitlines() top = [i for i, line in enumerate(lines) if line.strip()][:2] - first = set(top if lens.lens_header(body) else top[:1]) # the line after a lens header is a title too + first = set(top if unmarked or lens.lens_header(body) else top[:1]) # the line after a header is a title too fence = None for i, raw in enumerate(lines): fence, fenced = lens.fence_step(fence, raw) if fenced or i in found: continue line = _plain(raw, False) - if (i in first and NOT_SAFE_RE.search(line)) or VERDICT_NOT_SAFE_RE.match(line): + if (i in first and NOT_SAFE_RE.search(line)) or VERDICT_NOT_SAFE_RE.match(line) \ + or (unmarked and NOT_SAFE_TO_MERGE_RE.search(line)): found[i] = ('blocker', f'the report says NOT SAFE: {line}'[:SHOW_FINDING]) return [found[i] for i in sorted(found)], seen >= set(BLOCKING) @@ -380,9 +384,9 @@ def has_state_line(body): return any(STATE_RE.match(lens.norm_line(fold(raw))) for raw in lens.plain_lines(body)) -def findings(body): +def findings(body, unmarked=False): """[(kind, line)] of the report's blocker and major findings (read_findings).""" - return read_findings(body)[0] + return read_findings(body, unmarked)[0] def round_marker(name): diff --git a/fork-kit/review/COMMENTS.md b/fork-kit/review/COMMENTS.md index 324ccd9e93993..2bc3c28e7c27d 100644 --- a/fork-kit/review/COMMENTS.md +++ b/fork-kit/review/COMMENTS.md @@ -4,9 +4,11 @@ A lens posts its report as one pull request comment. The merge gate (`fork-ci/ac with fixed rules. A comment that carries the lens marker (below) is a lens report, and the gate fails closed on it: one that is not exactly one valid read blocks the head. A comment without the marker that looks like a report is no lens report and never reads. It blocks only when it holds an open finding (a `blocker:` or `major:` line that is not -`none`, or NOT SAFE): then it is most likely a real report with a broken header, so it holds the head whatever an older -or newer read of that lens says, until it is deleted or starts with `not a lens:`. One with no open finding never -blocks, and the gate's summary names it `not a lens report` with the reason. +`none`, NOT SAFE on its first two lines or a `verdict:` line, or `not safe to merge` on any line outside a fenced code +block): then it is most likely a real report with a broken header, so it holds the head whatever an older or newer +read of that lens says, until it is deleted, starts with `not a lens:`, or is edited so it holds no open finding (the +same people could delete it). One with no open finding never blocks, and the gate's summary names it +`not a lens report` with the reason. This page shows the format with examples. The rules themselves are the gate's code and its README (sections [Lens comments](../../fork-ci/actions/pr-queue/README.md#lens-comments) and [Review rules](../../fork-ci/actions/pr-queue/README.md#review-rules)); the gate's test vectors @@ -323,6 +325,20 @@ blocker: a second run loses the saved rows major: none ``` +Without the marker the line under the heading is read as a title line, and `not safe to merge` anywhere outside a +fenced code block is NOT SAFE, so this blocks too. + +The gate reads: `reads nothing, no lens marker` + +```text +## Lens A, round 2 + +**NOT SAFE to merge** + +covered: the retry path +checks: ran the tests +``` + A note between rounds (for example from the orchestrator, after it checked a fix diff) opts out with `not a lens:` on its first line. It must not hold a `read at` sha outside a `>` quote, so a sha goes on its own line.