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 88e36504052a7..53176f9022a41 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 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, 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, @@ -63,6 +66,19 @@ export const HIDDEN = "hidden: post a new comment instead"; const FLAGS_UNREAD = "a review whose edit and hidden flags were not read from GitHub: re-run, or post a new comment"; 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)"; +/** 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). + */ +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"; @@ -203,6 +219,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. */ @@ -246,11 +275,52 @@ 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.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 reportProblem( + body: string, + overridePrefix?: string, +): [why: string, kind: ReportKind] | null { + const problem = looksProblem(body, overridePrefix); + if (!problem) return null; + if (hasMarker(body)) return [problem, "broken"]; + 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 ${HELD_WAY_OUT}; 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 and no open + * finding: reportProblem kind notLens), or null. + */ +export function notLensReport(body: string, overridePrefix?: string): string | null { + const got = reportProblem(body, overridePrefix); + return got && got[1] === "notLens" ? got[0] : 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 { pyUnicodeCheck(body); if ( overridePrefix !== undefined && @@ -316,6 +386,11 @@ 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, has no lens marker and no open finding + * (lens.Review.not_lens_reports). + */ + readonly notLens: Array<[string, string]>; } /** @@ -327,28 +402,37 @@ export function lensEntries( posts: ReadonlyArray, overridePrefix?: string, skip: (post: LensPost) => boolean = () => false, -): { history: Array<[string, string | null]>; entries: Map } { +): { + history: Array<[string, string | null]>; + entries: Map; + notLens: Array<[string, string]>; +} { const history: Array<[string, string | null]> = []; const entries = new Map(); + const notLens: Array<[string, string]> = []; posts.forEach((post, i) => { if (skip(post)) return; const at: PostAt = [post.when, i]; const { body } = post; const hidden = !post.unread && post.hidden; - let problem: string | null; + let got: [string, ReportKind] | null; let header: [string, string | null] | null; let key: string; try { - problem = lensProblem(body, overridePrefix); - 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) { - key = `${NO_HEADER} (${post.where}, ${problem}${hidden ? ", hidden" : ""})`; + if (got?.[1] === "notLens") { + notLens.push([post.where, got[0]]); + return; + } + if (got) { + key = `${NO_HEADER} (${post.where}, ${got[0]}${hidden ? ", hidden" : ""})`; entries.set(key, { at, sha: null, why: null, name: null, body }); return; } @@ -359,13 +443,13 @@ export function lensEntries( const why = post.unread ? FLAGS_UNREAD : hidden ? HIDDEN : post.edited ? EDITED : null; entries.set(key, { at, sha: why ? null : header[1], why, name: header[0], body }); }); - return { history, entries }; + return { history, entries, notLens }; } /** lens.Review.lens_scan on posts that count, with the repository's override prefix. */ export function lensScan(posts: ReadonlyArray, overridePrefix?: string): LensScan { - const { history, entries } = lensEntries(posts, overridePrefix); + const { history, entries, notLens } = lensEntries(posts, overridePrefix); const out: Record = {}; for (const [key, { sha, why }] of entries) out[key] = [sha, why]; - return { history, entries: out }; + return { history, entries: out, notLens }; } 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 78704c48ac98c..984648f7d1ac5 100644 --- a/apps/server/src/fork/reviewRules/reviewRules.test.ts +++ b/apps/server/src/fork/reviewRules/reviewRules.test.ts @@ -11,10 +11,16 @@ import { EMBEDDED, HIDDEN, NO_HEADER, + NO_MARKER, + REPOST, + hasMarker, lensHeader, lensKey, lensProblem, lensScan, + looksProblem, + notLensReport, + reportProblem, } from "./lensComment.ts"; import { ReviewPlanError, globMatches, planReview, type ReviewBlock } from "./plan.ts"; import { PyTextError } from "./pyText.ts"; @@ -47,7 +53,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"], linear: ["name", "fn", "parts", "expect", "ms"], py_unicode: null, unicode: ["name", "body", "findings", "section", "unassigned", "refused"], @@ -145,7 +151,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", () => { @@ -253,7 +263,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"), ); @@ -290,6 +300,61 @@ 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("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 1cfa9a5482f6d..b5852d483b00f 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -13,6 +13,29 @@ 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) 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`, 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 +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. 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) `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..1b68735b8fa74 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -214,7 +214,23 @@ 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. 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`, 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), 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 03adf131c7704..e0a9ecef65f39 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 @@ -212,9 +214,14 @@ 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', [] + 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,15 +233,33 @@ 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: + 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), 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, why, rows + return False, (f'{marker_hint(len(held), held)}. {why}' if held else why), rows return ok, how, rows +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): """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') @@ -244,10 +269,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') @@ -255,7 +285,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 6902dee39ee6f..8e7c4c68d52c1 100644 --- a/fork-ci/actions/head-check/head_check.test.py +++ b/fork-ci/actions/head-check/head_check.test.py @@ -385,15 +385,87 @@ 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, 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, H.WARN)]) + ok, why, rows = self.verdict([self.p.post(body)], required='correctness') # fail closed + self.assertFalse(ok) + 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_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('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 +2257,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 +2314,14 @@ 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} \([^|]*\) \| 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) self.assertEqual(code, 0, out) 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 f097feeba817b..8443a22c4f22f 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -564,12 +564,35 @@ 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 +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, +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 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 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 @@ -600,16 +623,18 @@ 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, 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 -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): 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 @@ -617,6 +642,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 1a1fd5200b69b..c6585d2ad6200 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) 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) 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,26 @@ 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)') +# 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 @@ -265,23 +286,48 @@ def loose_header(line): return bool(m and HEX_RE.search(m.group(1))) +def marker_line(line): + """A normalised line that carries the lens marker: it starts with the lens field (`lens:`, also `lens=`, `lens —`, + `lens –`: FIELD_START_RE), holds a lens field naming a hex sha anywhere (loose_header), or names a read, `read at` + and a hex sha (READ_AT_RE): what says "a lens" or "read this commit".""" + return bool(FIELD_START_RE.match(line) or READ_AT_RE.search(line)) or loose_header(line) + + +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), 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) + + def no_lens_text(text, keep_markdown=False): """Text that can never count as a lens read, name a lens or look like a lens report (lens_problem), for anything the queue quotes into a comment (gh errors): no `read at`, no lens field (`lens:`, `lens=`, `lens —`, `lens –`), no `safe to merge`. keep_markdown: the queue's own advice (a command in backticks, a `` placeholder) stays as written when, read without its markdown - 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) @@ -355,12 +401,47 @@ def override_sha(self, post): m = self.override_re.match(post.get('body') or '') return m.group(1) if m else None + 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) + 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, 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 {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): + """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 (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 - like a lens report). An override comment never counts. Every line is read normalised, in code blocks and - quotes too. Two or more header lines, a first-line header that names no lens, or a header line that is not the - first plain line: flagged, and `not a lens:` cannot clear it (the text holds EMBEDDED). Read both ways - (clean_inline narrow or not): flagged when either way flags it, or when the two read different headers.""" + like a lens report), with or without the lens marker. An override comment never counts. Every line is read + normalised, in code blocks and quotes too. Two or more header lines, a first-line header that names no lens, or + a header line that is not the first plain line: flagged, and `not a lens:` cannot clear it (the text holds + EMBEDDED). Read both ways (clean_inline narrow or not): flagged when either way flags it, or when the two read + different headers.""" body = post.get('body') or '' if self.override_re.match(body): return None @@ -442,30 +523,57 @@ 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 comment that looks like a lens report but 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 lens_author_associations shows in the run. review_judge.judge_rounds reads the newest report's findings from the 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).""" - found, history = {}, [] + 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), 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 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, 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 head = {**post, 'body': (post.get('body') or '')[:STRANGER_SCAN]} - if where not in self.logged and (self.lens_problem(head) or lens_header(head['body'])): + if where not in self.logged and (self.looks_problem(head) or lens_header(head['body'])): self.logged.add(where) association = post.get('authorAssociation') self.log(f'ignored a lens-looking post {where}: ' 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.lens_problem(post) + 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}): {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 '' @@ -479,7 +587,7 @@ def lens_scan(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 + 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 70f46e810af35..92d5b843cd881 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 = [], 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']: @@ -78,21 +79,40 @@ def test_every_recorded_call_gives_the_source_answer(self): if cause and got[:2] == [True, None] and any(w in got[2] for w in CHANGED): changed += 1 continue + if c['fn'] == 'reviewed_head' and got == [False, None, 'no lens comments'] \ + and all(not lens.has_marker(p.get('body') or '') or SOURCE.override_sha(p) for p in posts): + no_marker.append(c['args']) # issue #865: its only look-alike is no lens report, as if never posted + continue if c['fn'] == 'lens_problem' and c['out'] is None and (got or '').startswith(lens.OPT_OUT_READ): opt_out += 1 # issue #77: a hex `read at` below `not a lens:` blocks now continue + body = c['args'][0].get('body') or '' if c['fn'] == 'lens_problem' else '' + if c['fn'] == 'lens_problem' and got is None and not lens.has_marker(body) \ + 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), 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}') class Gaps(unittest.TestCase): """Rules the corpus does not pin (a mutation of each passed it).""" def test_a_lens_heading_counts_only_in_the_first_five_plain_lines(self): top = ['Summary', 'one', 'two', 'three'] - self.assertIsNotNone(SOURCE.lens_problem(post('\n'.join(top + ['## Lens correctness', 'text'])))) - self.assertIsNone(SOURCE.lens_problem(post('\n'.join(top + ['four', '## Lens correctness', 'text'])))) + self.assertIsNotNone(SOURCE.looks_problem(post('\n'.join(top + ['## Lens correctness', 'text'])))) + self.assertIsNone(SOURCE.looks_problem(post('\n'.join(top + ['four', '## Lens correctness', 'text'])))) def test_a_hex_word_without_a_digit_is_no_sha(self): self.assertIsNone(SOURCE.lens_problem(post('Notes\n```\nlens: effaced\n```'))) @@ -118,16 +138,17 @@ def test_plain_lines_follow_githubs_fences(self): # issue #303 point 3: the sa self.assertEqual(lens.plain_lines('a\n````\n```\nb\n````\nc'), ['a', 'c']) self.assertEqual(lens.plain_lines('a\n```\nb'), ['a']) # unclosed: to the end # the rendered `safe to merge` line below the inner fence is plain text, and blocks - self.assertIsNotNone(SOURCE.lens_problem(post('Notes\n```\nx\n```py\ny\n```\nsafe to merge: no\n```'))) + self.assertIsNotNone(SOURCE.looks_problem(post('Notes\n```\nx\n```py\ny\n```\nsafe to merge: no\n```'))) class NotALens(unittest.TestCase): """Issue #77: below a `not a lens:` first line, a lens read written another way (no colon after `lens`, another - field spelling) blocks too; only a `>` 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 +261,219 @@ 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), 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 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', + # 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 + 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.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)) + if lens.has_marker(body): + self.assertEqual(now, looks) + 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) + 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_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')) + 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}', + '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')) + 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') + 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 +617,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 +632,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 +846,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 +884,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..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) @@ -3798,13 +3811,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 5cd0c50ce82a0..6d28eb9c60d72 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). `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": [ @@ -1906,49 +1906,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", @@ -2193,6 +2196,387 @@ 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 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\nblocker: none\nmajor: none", + "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 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 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 + ] + } + }, + { + "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 + ] + } + }, + { + "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 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 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 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 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 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 + ] + } + }, + { + "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 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 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 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 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 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 + ] + } + }, + { + "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": {} + }, + { + "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": [ @@ -3253,6 +3637,224 @@ "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 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 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 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 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 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 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 + } + }, + { + "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-ci/actions/pr-queue/review_judge.test.py b/fork-ci/actions/pr-queue/review_judge.test.py index 95298a994ccaa..ed63b7bdc3de5 100644 --- a/fork-ci/actions/pr-queue/review_judge.test.py +++ b/fork-ci/actions/pr-queue/review_judge.test.py @@ -364,10 +364,10 @@ def test_the_same_comments_give_the_same_verdict(self): # runs again: pure 'reads': {'name', 'posts', 'head', 'same', 'override_authors', 'required', 'expect'}, '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 vector_pr(posts): @@ -391,8 +391,8 @@ def vector_pr(posts): def scan(posts): - found, history = SCAN.lens_scan(vector_pr(posts)) - return [list(h) for h in history], {k: [v[1], v[2]] for k, v in found.items()} + 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] def replay_round(v): @@ -501,7 +501,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_reads_vector(self): # lens_start's copy of lens_reads, review_rounds' UNREAD and verdict self.assertGreaterEqual(len(VECTORS['reads']), 10) diff --git a/fork-kit/review/COMMENTS.md b/fork-kit/review/COMMENTS.md index 56ee904f5813e..2bc3c28e7c27d 100644 --- a/fork-kit/review/COMMENTS.md +++ b/fork-kit/review/COMMENTS.md @@ -1,8 +1,15 @@ # 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 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`, 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 ([review.vectors.json](../../fork-ci/actions/pr-queue/review.vectors.json)) pin how it judges paths and lens counts. @@ -14,6 +21,23 @@ 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). 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 ``` @@ -50,19 +74,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` | looks like a lens report but is not one valid read: the gate counts it as a blocking problem | -| `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 @@ -208,6 +233,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`), 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. The gate reads: `lens code, read, no findings section, no state` @@ -228,7 +256,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 +280,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 +303,42 @@ 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 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 +``` + +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. diff --git a/fork-kit/review/SKILL.md b/fork-kit/review/SKILL.md index e5805f2d1d4f5..d0ced90df6788 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, 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 aa91684c97ebb..d6718de014e1a 100644 --- a/fork-kit/review/lib/review_kit.py +++ b/fork-kit/review/lib/review_kit.py @@ -305,8 +305,13 @@ 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 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: return ['not a lens'] diff --git a/fork-kit/review/tests/comments.test.py b/fork-kit/review/tests/comments.test.py index 8a6b81431ab93..9feea1cd00e54 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,20 @@ 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')) + + 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): @@ -233,8 +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 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')),