diff --git a/.github/fork-owned-paths.txt b/.github/fork-owned-paths.txt index 0802773458c93..10daf4cd81255 100644 --- a/.github/fork-owned-paths.txt +++ b/.github/fork-owned-paths.txt @@ -16,6 +16,10 @@ # The fork's composite actions and host kits: only the `workflows`, `action_tests` and `kit_tests` jobs read them. fork-ci/ fork-kit/ +# The review rules' shared vectors and the gate's lens corpus: the server's review-rules test reads them, so a pull +# request changing the gate and its vectors runs that test too. +!fork-ci/actions/pr-queue/review.vectors.json +!fork-ci/actions/pr-queue/testdata/lens-corpus.jsonl # The fork's scripts and settings under .github; the `workflows` job tests them. .github/scripts/fork-* diff --git a/.github/scripts/fork-owned-paths.test.py b/.github/scripts/fork-owned-paths.test.py index 7738634211386..ebe7a2d9d46b6 100644 --- a/.github/scripts/fork-owned-paths.test.py +++ b/.github/scripts/fork-owned-paths.test.py @@ -135,6 +135,9 @@ def fork_only(out): ("a file an app job reads (fork-test-shards.cjs)", {".github/scripts/fork-test-shards.cjs": "x\n"}, None), ("the runner routing (fork-fleet.py)", {".github/scripts/fork-fleet.py": "x\n"}, None), ("the fleet facts (fork-fleet.json)", {".github/fork-fleet.json": "{}\n"}, None), + ("a gate change with the review vectors the server test reads", + {"fork-ci/actions/pr-queue/review_judge.py": "x\n", "fork-ci/actions/pr-queue/review.vectors.json": "{}\n"}, None), + ("a change to the gate's lens corpus", {"fork-ci/actions/pr-queue/testdata/lens-corpus.jsonl": "{}\n"}, None), ("a package.json inside fork-kit", {"fork-kit/x/package.json": "{}\n"}, None), ("a lock file", {"pnpm-lock.yaml": "x\n"}, None), ("a file moved out of fork-ci/", {"fork-ci/a.ts": None, "packages/shared/src/a.ts": "a\n"}, {"fork-ci/a.ts": "a\n"}), @@ -170,8 +173,10 @@ def fork_only(out): ".github/scripts/fork-fleet.py", ".github/scripts/fork-test-shards.cjs", ".github/scripts/fork-vitest-gc-check.cjs", ".github/fork-fleet.json", "fork-ci/package.json", "fork-kit/x/tsconfig.json", "package.json", "apps/web/src/a.ts", "docs/fork/README.md", "scripts/release-smoke.ts", "fork-ci", "fork-cix/a", + "fork-ci/actions/pr-queue/review.vectors.json", "fork-ci/actions/pr-queue/testdata/lens-corpus.jsonl", ]) -want_owned = {p for p in REAL if p.startswith(("fork-ci/actions", "fork-kit/heavy")) or p in { +want_owned = {p for p in REAL if p.startswith(("fork-ci/actions", "fork-kit/heavy")) and "/review.vectors" not in p + and "/testdata/lens-corpus" not in p or p in { ".github/scripts/fork-fleet-walls.py", ".github/scripts/fork-fleet-walls/linux", ".github/scripts/fork_workflow_expr.py", ".github/fork-ci-tests.txt", ".gitleaks.toml", "FORK_CHANGES.md"}} check("list: the fork's own folders and scripts are fork-owned; the rest, and every NEVER path, are not", diff --git a/apps/server/src/fork/reviewRules/findings.ts b/apps/server/src/fork/reviewRules/findings.ts new file mode 100644 index 0000000000000..07ac6729be330 --- /dev/null +++ b/apps/server/src/fork/reviewRules/findings.ts @@ -0,0 +1,212 @@ +/** + * Port of review_judge.read_findings (fork-ci/actions/pr-queue), held to the shared vectors. A report has a findings + * section only with both a blocker and a major label: with one alone, a major in a form not read would pass as clean. + */ +import { fenceStep, lensHeader, normLine } from "./lensComment.ts"; +import { + ALNUM, + B, + S, + WS, + cut, + htmlUnescape, + isBlank, + pyI, + splitlines, + strip, + stripChars, +} from "./pyText.ts"; + +const CONFUSABLE_FROM = "АВЕКМНОРСТХІЈЅаеорсхуіјѕкԁӏһԛԝΑΒΕΖΗΙΚΜΝΟΡΤΥΧοικναρıℓǀ∶"; +const CONFUSABLE_TO = "ABEKMHOPCTXIJSaeopcxyijskdlhqwABEZHIKMNOPTYXoikvapill:"; + +// The dashes as regex escapes: a pattern needs them, copy must not. +const EM = /\u2014/u.source; +const EN = /\u2013/u.source; +const kw = (group: string) => `(?<${group}>bl[o0]ck(?:ers?|ing)|ma[j][o0]rs?|m[i1]n[o0]rs?|nits?)`; +const label = (group: string) => + `${kw(group)}(?!${ALNUM})(?:${S}+(?:findings?|issues?|problems?|items?|points?|bugs?|ones?)(?!${ALNUM}))?` + + `(?:${S}*#?\\p{Nd}{1,4}(?!${ALNUM}))?(?:${S}*\\([^()\\n]{0,80}\\))?`; +const SEP = `${S}*(?::|[${EM}${EN}=]|-(?=${S}|$))`; +const LABEL = `(?:^|(?<=[,;.!?|/])${S}*|${S}+(?:and|but)${S}+)(?:\\[${label("kw")}\\]|\\(${label("kw2")}\\)|${label("kw3")}${SEP})`; +const re = (source: string, flags = "iu") => new RegExp(pyI(source), flags); +const LABEL_RE = re(LABEL, "giu"); +const LABEL_AT_START = re(`^(?:${LABEL})`); +const BARE_RE = re(`^[\\[(]?${label("kw")}[\\])]?${SEP}?${S}*$`); +const CELL_RE = re(`^${label("kw")}${S}*:?${S}*$`); +const NONE_RE = re( + `^[(\\[]?${S}*(?:none|nothing|nil|no|zero|0|n/?a|-+|${EM}|${EN})(?:${S}+(?:found|open|left|remaining|seen|here|known|` + + `so${S}+far|at${S}+all|this${S}+round|blocking|blockers?|majors?|findings?|issues?|problems?))*${S}*` + + `(?:$|[.,;:!?)(\\[]|[^\\p{L}\\p{N}_${WS}\\x00-\\x7f]|-(?=${S}|$))`, +); +const FINDING_LINE_RE = re(`^findings?${S}*:${S}*[\\[(]?${kw("kw")}(?!${ALNUM})`); +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}`); +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"); +const TABLE_RE = new RegExp(`^${S}*\\|`, "u"); +const TABLE_RULE_RE = new RegExp(`^\\|?${S}*:?-+:?${S}*(?:\\|${S}*:?-+:?${S}*)*\\|?$`, "u"); +const LEAD_PLAIN = /^[^\p{L}\p{N}_[(]+/u; +const LEAD_NONE = /^[^\p{L}\p{N}_\-\u2014\u2013([]+/u; +const WS_RUN = new RegExp(`${S}+`, "gu"); +const SHOW_FINDING = 120; + +export type FindingKind = "blocker" | "major"; +type Kind = FindingKind | "minor"; +const blocking = (kind: Kind): kind is FindingKind => kind !== "minor"; + +/** The text as the findings rules read it. */ +export function fold(text: string | null | undefined): string { + const t = htmlUnescape((text ?? "").normalize("NFKC")) + .replace(/\\([!-/:-@[-`{-~])/gu, "$1") + .replace(/\p{Cf}/gu, ""); + return Array.from(t, (ch) => { + const k = CONFUSABLE_FROM.indexOf(ch); + return k < 0 ? ch : CONFUSABLE_TO[k]!; + }).join(""); +} + +function kindOf(m: RegExpExecArray | RegExpMatchArray): Kind { + const word = (m.groups!.kw ?? m.groups!.kw2 ?? m.groups!.kw3)! + .toLowerCase() + .replaceAll("0", "o") + .replaceAll("1", "i"); + return word.startsWith("block") ? "blocker" : word.startsWith("major") ? "major" : "minor"; +} + +const plain = (line: string, narrow: boolean) => + strip(normLine(fold(line), narrow).replace(LEAD_PLAIN, "").replace(WS_RUN, " ")); +const saysNothing = (text: string) => NONE_RE.test(strip(text).replace(LEAD_NONE, "")); + +/** The first content line under a bare label, or null when a heading, another label or the end comes first. */ +function under(lines: ReadonlyArray, start: number, narrow: boolean): string | null { + for (let i = start; i < lines.length; i++) { + const raw = lines[i]!; + if (isBlank(raw) || RULE_LINE_RE.test(raw)) continue; + if (HEADING_RE.test(raw)) return null; + const line = plain(raw, narrow); + if (BARE_RE.test(line) || LABEL_AT_START.test(line)) return null; + return line || strip(raw); + } + return null; +} + +type Read = { out: Array<[number, FindingKind, string]>; seen: Set }; + +function read(lines: ReadonlyArray, narrow: boolean): Read { + const out: Read["out"] = []; + const seen = new Set(); + let fence: string | null = null; + let columns: Map | null = null; + for (const [i, raw] of lines.entries()) { + let fenced: boolean; + [fence, fenced] = fenceStep(fence, raw); + if (fenced) { + columns = null; + continue; + } + if (TABLE_RE.test(raw)) { + const cells = stripChars(strip(fold(raw)), "|") + .split("|") + .map((c) => plain(strip(c), narrow)); + if (i + 1 < lines.length && TABLE_RULE_RE.test(strip(lines[i + 1]!))) { + columns = new Map(); + for (const [j, c] of cells.entries()) { + const m = CELL_RE.exec(c); + if (m) seen.add(columns.set(j, kindOf(m)).get(j)!); + } + continue; + } + if (TABLE_RULE_RE.test(strip(raw))) continue; + // Once per row: per cell, a wide row took minutes. after[j]: the first non-empty cell after cell j. + const row = plain(raw, narrow); + const after: string[] = Array.from({ length: cells.length }); + let said = ""; + for (let j = cells.length - 1; j >= 0; j--) { + after[j] = said; + said = cells[j] || said; + } + for (const [j, c] of cells.entries()) { + const m = CELL_RE.exec(c); + const kind = m && kindOf(m); + if (kind && blocking(kind)) { + seen.add(kind); + if (!saysNothing(after[j]!)) out.push([i, kind, row]); + } + } + for (const [j, kind] of columns ?? []) { + if (blocking(kind) && j < cells.length && !saysNothing(cells[j]!)) out.push([i, kind, row]); + } + continue; + } + columns = null; + const line = plain(raw, narrow); + if (FINDINGS_NONE_RE.test(line)) { + seen.add("blocker").add("major"); + continue; + } + const finding = FINDING_LINE_RE.exec(line); + if (finding) { + seen.add("blocker").add("major"); + const kind = kindOf(finding); + if (blocking(kind)) out.push([i, kind, line]); + continue; + } + const bare = BARE_RE.exec(line); + if (bare) { + const kind = kindOf(bare); + if (!blocking(kind)) continue; + seen.add(kind); + const said = under(lines, i + 1, narrow); + if (said === null || !saysNothing(said)) { + out.push([i, kind, said === null ? `${line} (nothing under it)` : `${line} ${said}`]); + } + continue; + } + const marks = [...line.matchAll(LABEL_RE)]; + for (const [n, m] of marks.entries()) { + const kind = kindOf(m); + if (!blocking(kind)) continue; + seen.add(kind); + if (!saysNothing(line.slice(m.index + m[0].length, marks[n + 1]?.index ?? line.length))) { + out.push([i, kind, line]); + break; + } + } + } + return { out, seen }; +} + +/** + * [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. + */ +export function readFindings(body: string): [Array<[FindingKind, string]>, boolean] { + const lines = splitlines(body); + const found = new Map(); + const seen = new Set(); + for (const narrow of [false, true]) { + const r = read(lines, narrow); + r.seen.forEach((k) => seen.add(k)); + for (const [i, kind, text] of r.out) + 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)); + 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)) { + found.set(i, ["blocker", cut(`the report says NOT SAFE: ${line}`, SHOW_FINDING)]); + } + } + const said = [...found.keys()].sort((a, b) => a - b).map((i) => found.get(i)!); + return [said, seen.has("blocker") && seen.has("major")]; +} diff --git a/apps/server/src/fork/reviewRules/lensComment.ts b/apps/server/src/fork/reviewRules/lensComment.ts new file mode 100644 index 0000000000000..0931983458621 --- /dev/null +++ b/apps/server/src/fork/reviewRules/lensComment.ts @@ -0,0 +1,299 @@ +/** + * 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. + */ +import { + ALNUM, + B, + S, + WS, + cut, + isBlank, + pyI, + repr, + split, + splitlines, + strip, + stripChars, +} from "./pyText.ts"; + +const TAG_OPEN = /<\/?[A-Za-z]/gu; +const TAG_NARROW = /<\/?[A-Za-z][^<>]*>/gu; +const LINK_NARROW = /!?\[([^[\]]*)\]\([^()]*\)/gu; +const EDGE_UNDERSCORES = new RegExp(`(?|[-+•](?=${S}|$)|\\p{Nd}{1,9}[.)](?=${S}|$)|#{1,6}(?=${S}|$)|~{3,}|\\[[ xX]\\](?=${S}|$))${S}*)*`, + "u", +); +const LENS_RE = new RegExp(`^lens${S}*:${S}*([\\s\\S]*)`, "iu"); +const FIELD_RE = new RegExp( + pyI( + `(?` quote"; + +/** Each tag to the first `>` after its start, in linear time; no `>` left: no later tag closes either. */ +function stripTags(text: string): string { + let out = ""; + let pos = 0; + for (const m of text.matchAll(TAG_OPEN)) { + if (m.index < pos) continue; + const end = text.indexOf(">", m.index + m[0].length); + if (end < 0) break; + out += text.slice(pos, m.index); + pos = end + 1; + } + return out + text.slice(pos); +} + +/** `[x](y)` -> x in linear time; no `]` or `)` left: no later link closes either. */ +function stripLinks(text: string): string { + let out = ""; + let pos = 0; + let i = text.indexOf("["); + while (i >= 0) { + const close = text.indexOf("]", i + 1); + if (close < 0) break; + if (text[close + 1] !== "(") { + i = text.indexOf("[", close + 1); + continue; + } + const end = text.indexOf(")", close + 2); + if (end < 0) break; + const start = i > pos && text[i - 1] === "!" ? i - 1 : i; + out += text.slice(pos, start) + text.slice(i + 1, close); + pos = end + 1; + i = text.indexOf("[", pos); + } + return out + text.slice(pos); +} + +/** Markdown that can hide a word, gone: tags, links, `*`, backticks, `|`, `_` at a word edge. */ +function cleanInline(text: string, narrow = false): string { + const t = narrow + ? text.replace(TAG_NARROW, "").replace(LINK_NARROW, "$1") + : stripLinks(stripTags(text)); + return t.replace(/[*`]/gu, "").replaceAll("|", " ").replace(EDGE_UNDERSCORES, ""); +} + +/** One line cleaned, its leading quote, list, heading and fence markers gone. */ +export const normLine = (line: string, narrow = false): string => + strip(cleanInline(line, narrow).replace(LEADING_MARKERS, "")); + +const opensPlain = (line: string) => !/^(?: {4}|\t| {0,3}(?:>|`{3}|~{3}))/u.test(line); + +/** One key per lens across rounds: the name lower-case, without a trailing round marker or emphasis. */ +export function lensKey(name: string): string { + const words = split(name.toLowerCase()); + let lo = 0; + let hi = words.length; + for (;;) { + while (lo < hi && !words[lo]) lo++; + while (lo < hi && !words[hi - 1]) hi--; + if (lo === hi) return "unnamed"; + const before = [words[lo], words[hi - 1], hi]; + words[lo] = stripChars(words[lo]!, "*_`", true, false); + words[hi - 1] = stripChars(words[hi - 1]!, "*_`", false, true); + if (hi - lo >= 2 && words[hi - 1] && MARKER.test(words[hi - 1]!)) hi--; + if (words[lo] === before[0] && words[hi - 1] === before[1] && hi === before[2]) { + return words.slice(lo, hi).filter(Boolean).join(" ") || "unnamed"; + } + } +} + +/** The name has a letter or digit, is no `<...>` placeholder and is more than a round marker. */ +function namesALens(name: string): boolean { + const key = lensKey(name); + return ( + new RegExp(ALNUM, "u").test(key) && + !/<[^<>]*>/u.test(name) && + !/^unnamed$/u.test(key) && + !MARKER.test(key) + ); +} + +/** [name, sha or null] of a comment's first-line lens header, or null. */ +export function lensHeader(body: string, narrow = false): [string, string | null] | null { + const first = splitlines(body).find((line) => !isBlank(line)) ?? ""; + if (!opensPlain(first)) return null; + const line = normLine(first, narrow); + const rest = LENS_RE.exec(line)?.[1]; + if (rest === undefined) return null; + const name = rest.slice(0, FIELD_RE.exec(rest)?.index ?? rest.length); + if (!namesALens(name)) return null; + return [name, READ_AT_RE.exec(line)?.[1]?.toLowerCase() ?? null]; +} + +/** [the fence open after this line or null, whether the line belongs to a fence], given the one open before it. */ +export function fenceStep(fence: string | null, line: string): [string | null, boolean] { + if (fence) { + const m = /^ {0,3}(`{3,}|~{3,})[ \t]*$/u.exec(line); + return [m && m[1]![0] === fence[0] && m[1]!.length >= fence.length ? null : fence, true]; + } + const m = /^ {0,3}(?:(`{3,})[^`]*|(~{3,})[\s\S]*)$/u.exec(line); + return m ? [m[1] ?? m[2]!, true] : [null, false]; +} + +/** The lines outside fences, 4-space/tab indented blocks and quotes (lens.plain_lines). */ +function plainLines(body: string): string[] { + const out: string[] = []; + let fence: string | null = null; + for (const line of splitlines(body)) { + let fenced: boolean; + [fence, fenced] = fenceStep(fence, line); + if (!fenced && !isBlank(line) && !/^(?: {4}|\t| {0,3}>)/u.test(line)) out.push(line); + } + return out; +} + +/** The lines except those of a `>` quote outside a fence (lens.unquoted_lines). */ +function unquotedLines(body: string): string[] { + const out: string[] = []; + let fence: string | null = null; + for (const line of splitlines(body)) { + let fenced: boolean; + [fence, fenced] = fenceStep(fence, line); + if (!fenced && /^ {0,3}>/u.test(line)) continue; + out.push(line); + } + return out; +} + +const headerLine = (line: string) => LENS_RE.test(line) && READ_AT_RE.test(line); + +/** A lens field anywhere in the line naming a hex sha after it (lens.loose_header). */ +function looseHeader(line: string): boolean { + const m = LOOSE_RE.exec(line.replace(NOT_A_LENS_SUB, " ")); + return !!m && HEX_RE.test(m[1]!); +} + +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. */ +function readProblem(body: string, narrow: boolean): string | null { + const norm = (line: string) => normLine(line, narrow); + const lines = splitlines(body); + const at = Math.max( + 0, + lines.findIndex((line) => !isBlank(line)), + ); + const first = lines.find((line) => !isBlank(line)) ?? ""; + const normed = lines.map(norm); + const start = starts(first); + let headers = 0; + for (const [i, line] of normed.entries()) { + const m = i > at ? FIELD_START_RE.exec(line) : null; + if (headerLine(line) || (m && HEX_RE.test(m[1]!))) headers++; + } + if (headers > 1) return `${EMBEDDED} ${headers} times (post one comment per lens), ${start}`; + if (lensHeader(body, narrow)) return null; + if (opensPlain(first) && LENS_RE.test(norm(first))) + return `its first-line header names no lens (a placeholder, a round or nothing), ${start}`; + if (headers) + return `${EMBEDDED} that is not its first plain line (a later line, a code block, quote or table), ${start}`; + if (normed.some(looseHeader)) + return `${EMBEDDED} (a lens line with a sha not written \`read at: \`), ${start}`; + if (opensPlain(first) && NOT_A_LENS_RE.test(norm(first))) { + return unquotedLines(body).some((line) => READ_AT_RE.test(norm(line))) + ? `${OPT_OUT_READ}, ${start}` + : null; + } + const plain = plainLines(body); + if (plain.filter((line) => FIELD_LINE_RE.test(norm(line))).length >= 2) return start; + if ( + normed.some((line) => READ_AT_RE.test(line)) || + plain.some((line) => LOOKS_RE.test(norm(line))) || + plain.slice(0, TOP_LINES).some((line) => LOOKS_HEADING_RE.test(line)) + ) + return start; + return 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. + */ +export function lensProblem(body: string, overridePrefix?: string): string | null { + if ( + overridePrefix !== undefined && + body.startsWith(`${overridePrefix} `) && + /^[0-9a-f]{40}:/u.test(body.slice(overridePrefix.length + 1)) + ) + return null; + const problem = readProblem(body, false) ?? readProblem(body, true); + if ( + problem === null && + JSON.stringify(lensHeader(body)) !== JSON.stringify(lensHeader(body, true)) + ) { + return ( + "its first line reads as a different lens header, or as one and as none, depending on how its HTML " + + `tags and links are read; ${starts(splitlines(body).find((line) => !isBlank(line)) ?? "")}` + ); + } + return problem; +} + +/** A pull request comment or review whose author counts (a lens author association, no bot), in posting order. */ +export interface LensPost { + readonly body: string; + /** GitHub's includesCreatedEdit: anything but a recorded false is an edit. */ + readonly edited: boolean; + /** GitHub's isMinimized. */ + readonly hidden: boolean; + /** How the gate names the post in a NO_HEADER key: its url, else `by at `. Default `post `. */ + readonly where?: string; +} + +export interface LensScan { + /** [lens name, sha or null] of every post with a lens header, old, edited and hidden ones too: the rounds. */ + readonly history: Array<[string, string | null]>; + /** Each lens key's newest [sha or null, why it reads nothing or null]. */ + readonly entries: Record; +} + +/** lens.Review.lens_scan on posts that count, with the repository's override prefix. */ +export function lensScan(posts: ReadonlyArray, overridePrefix?: string): LensScan { + const history: Array<[string, string | null]> = []; + const entries: Record = {}; + posts.forEach((post, i) => { + const problem = lensProblem(post.body, overridePrefix); + if (problem) { + const where = post.where ?? `post ${i + 1}`; + entries[`${NO_HEADER} (${where}, ${problem}${post.hidden ? ", hidden" : ""})`] = [null, null]; + return; + } + const header = lensHeader(post.body); + if (!header) return; + history.push(header); + const why = post.hidden ? HIDDEN : post.edited ? EDITED : null; + entries[lensKey(header[0])] = why ? [null, why] : [header[1], null]; + }); + return { history, entries }; +} diff --git a/apps/server/src/fork/reviewRules/plan.ts b/apps/server/src/fork/reviewRules/plan.ts new file mode 100644 index 0000000000000..aa10d657bcdd1 --- /dev/null +++ b/apps/server/src/fork/reviewRules/plan.ts @@ -0,0 +1,170 @@ +/** + * Port of review_glob.py and review_judge.judge (fork-ci/actions/pr-queue), held to the shared vectors. Input it + * cannot read, or a path no rule matches, throws ReviewPlanError: never "no lens needed". + */ +import * as Schema from "effect/Schema"; + +import { strip } from "./pyText.ts"; + +export type ReviewWeight = "critical" | "normal" | "light"; +const WEIGHTS: ReadonlyArray = ["critical", "normal", "light"]; + +/** A `review` block of the repo's pr-queue config, as the gate's parser accepts it. */ +export interface ReviewBlock { + readonly rules: ReadonlyArray<{ + readonly name: string; + readonly weight: ReviewWeight; + readonly paths: ReadonlyArray; + readonly lenses: ReadonlyArray; + }>; + readonly lenses: Readonly>; + readonly rounds: { + readonly approach_at: number; + readonly max: number; + readonly approach_lens: string; + }; + readonly findings: boolean; + readonly override_authors?: ReadonlyArray; +} + +export class ReviewPlanError extends Schema.TaggedError()("ReviewPlanError", { + reason: Schema.String, +}) { + override get message(): string { + return this.reason; + } +} + +function refuse(reason: string): never { + throw new ReviewPlanError({ reason }); +} + +/** One glob segment (no `**`) against one path segment, by code point: the wildcard walk, never exponential. */ +function segmentMatches(glob: ReadonlyArray, seg: ReadonlyArray): boolean { + let i = 0; + let j = 0; + let star = -1; + let mark = 0; + while (j < seg.length) { + if (i < glob.length && glob[i] === "*") { + star = i++; + mark = j; + } else if (i < glob.length && (glob[i] === "?" || glob[i] === seg[j])) { + i++; + j++; + } else if (star >= 0) { + i = star + 1; + j = ++mark; + } else return false; + } + while (i < glob.length && glob[i] === "*") i++; + return i === glob.length; +} + +/** The glob matches the whole repo-relative path: `**` takes any number of whole segments, `*` and `?` stay in one. */ +export function globMatches(glob: string, path: string): boolean { + const p = path.split("/").map((s) => Array.from(s)); + let reach = [true, ...p.map(() => false)]; + for (const seg of glob.split("/")) { + if (seg === "**") { + let seen = false; + reach = reach.map((r) => (seen ||= r)); + } else { + const g = Array.from(seg); + reach = [false, ...p.map((s, j) => reach[j]! && segmentMatches(g, s))]; + } + if (!reach.includes(true)) return false; + } + return reach[p.length]!; +} + +const WORKFLOWS = ".github/workflows/**"; + +/** review_config.matches_every_path: a `**` segment and at most one other, which matches any segment. */ +function matchesEveryPath(glob: string): boolean { + const segs = glob.split("/"); + const rest = segs.filter((s) => s !== "**"); + const any = (s: string) => /^[*?]*$/u.test(s) && s.includes("*") && s.split("?").length <= 2; + return rest.length < segs.length && rest.length <= 1 && rest.every(any); +} + +const catchAll = (review: ReviewBlock) => review.rules.find((r) => r.paths.some(matchesEveryPath)); + +export interface ReviewPlan { + readonly weight: ReviewWeight; + /** The required lens names, in rule order, each once. */ + readonly lenses: ReadonlyArray; + /** Every rule a changed path counted for, in rule order, with those paths in change order. */ + readonly hits: ReadonlyArray<{ + readonly rule: string; + readonly weight: ReviewWeight; + readonly paths: string[]; + }>; + /** The changed paths that are built-in protected: the config file, a lens prompt, a workflow. */ + readonly protected: ReadonlyArray; +} + +/** + * The plan for `changes` as `git diff --name-status -M` names them ([status, path] or [R|C, old, new]) under a + * valid `review` block; `configPath` is the config file (repo-relative). A rename or copy counts under both paths; a + * protected path also counts for the first critical rule; the heaviest weight hit decides; no change at all counts as + * the catch-all rule. + */ +export function planReview( + review: ReviewBlock, + changes: ReadonlyArray>, + configPath: string, +): ReviewPlan { + const paths: string[] = []; + const seen = new Set(); + for (const [status = "", ...named] of changes) { + const two = /^[CR][0-9]{1,3}$/u.test(status); + if (!two && !/^[ADMT]$/u.test(status)) + refuse(`unknown change status ${JSON.stringify(status)}`); + if (named.length !== (two ? 2 : 1) || named.includes("")) { + refuse(`the status ${status} without its paths`); + } + for (const p of named) if (!seen.has(p) && seen.add(p)) paths.push(p); + } + const rel = configPath.startsWith("./") ? configPath.slice(2) : configPath; + const segs = rel.split("/"); + if ( + !rel || + strip(rel) !== rel || + /[\n\r]/u.test(rel) || + rel.startsWith("/") || + segs.some((s) => /^\.{0,2}$/u.test(s)) + ) { + refuse(`the config path ${JSON.stringify(configPath)} is not written as git names the file`); + } + const exact = new Set([rel, ...Object.values(review.lenses).map((l) => l.prompt)]); + const firstCritical = review.rules.find((r) => r.weight === "critical"); + const counted = new Map(review.rules.map((r) => [r.name, []])); + const isProtected: string[] = []; + if (paths.length === 0) { + const rule = catchAll(review); + if (!rule) refuse("no changed path, and no catch-all rule to judge an empty change by"); + counted.set(rule.name, null); + } + for (const p of paths) { + const rule = review.rules.find((r) => r.paths.some((g) => globMatches(g, p))); + if (!rule) refuse(`no rule matches the changed path ${JSON.stringify(p)}`); + counted.get(rule.name)!.push(p); + if (exact.has(p) || globMatches(WORKFLOWS, p)) { + if (!firstCritical) refuse(`${JSON.stringify(p)} is protected, but no rule is critical`); + isProtected.push(p); + if (firstCritical !== rule) counted.get(firstCritical.name)!.push(p); + } + } + const hits = review.rules.flatMap((r) => { + const got = counted.get(r.name); + return got === null || got!.length + ? [{ rule: r.name, weight: r.weight, paths: got ?? [] }] + : []; + }); + const weight = WEIGHTS.find((w) => hits.some((h) => h.weight === w))!; + const lenses = review.rules + .filter((r) => r.weight === weight && hits.some((h) => h.rule === r.name)) + .flatMap((r) => r.lenses); + return { weight, lenses: [...new Set(lenses)], hits, protected: isProtected }; +} diff --git a/apps/server/src/fork/reviewRules/pyText.ts b/apps/server/src/fork/reviewRules/pyText.ts new file mode 100644 index 0000000000000..98eacf0ccad79 --- /dev/null +++ b/apps/server/src/fork/reviewRules/pyText.ts @@ -0,0 +1,144 @@ +/** + * Python's text rules for the review-rules port: JavaScript's `\s`, `\w`, `\b`, `trim`, `split`, case folding and + * string indexing differ from Python's, and the gate is Python, so patterns here are spelled as Python reads them. + */ +import { characterEntities } from "character-entities"; + +/** Python's whitespace (str.isspace, re `\s`), as the body of a character class. */ +export const WS = + "\\t-\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000"; +export const S = `[${WS}]`; +/** Python re `\w` and `[^\W_]` (letters and numbers; marks are neither). */ +const W = "[\\p{L}\\p{N}_]"; +export const ALNUM = "[\\p{L}\\p{N}]"; +/** Python re `\b`. */ +export const B = `(?:(?<=${W})(?!${W})|(? a && SPACE.test(text[b - 1]!)) b--; + return text.slice(a, b); +} +export const isBlank = (text: string): boolean => strip(text) === ""; +export const split = (text: string): string[] => + text.split(new RegExp(`${S}+`, "u")).filter(Boolean); + +/** str.strip(chars). */ +export function stripChars(text: string, chars: string, left = true, right = true): string { + let a = 0; + let b = text.length; + if (left) while (a < b && chars.includes(text[a]!)) a++; + if (right) while (b > a && chars.includes(text[b - 1]!)) b--; + return text.slice(a, b); +} + +/** str.splitlines(). */ +export function splitlines(text: string): string[] { + const lines = text.split(/\r\n|[\n\r\v\f\x1c-\x1e\x85\u2028\u2029]/u); + if (lines[lines.length - 1] === "") lines.pop(); + return lines; +} + +/** text[:n], by code point. */ +export const cut = (text: string, n: number): string => Array.from(text).slice(0, n).join(""); + +/** The value of one decimal digit of any script (Python's int() reads them all): its place in its run of digits. */ +export function digitValue(ch: string): number { + let cp = ch.codePointAt(0)!; + let n = 0; + while (n < 64 && /\p{Nd}/u.test(String.fromCodePoint(cp - 1))) { + cp--; + n++; + } + return n % 10; +} + +/** repr(text) of a Python str. */ +export function repr(text: string): string { + const quote = text.includes("'") && !text.includes('"') ? '"' : "'"; + let out = ""; + for (const ch of text) { + const cp = ch.codePointAt(0)!; + if (ch === "\\" || ch === quote) out += "\\" + ch; + else if (ch === "\t" || ch === "\n" || ch === "\r") + out += { "\t": "\\t", "\n": "\\n", "\r": "\\r" }[ch]; + else if (ch !== " " && /[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Z}]/u.test(ch)) { + const [p, w] = cp < 0x100 ? ["\\x", 2] : cp < 0x10000 ? ["\\u", 4] : ["\\U", 8]; + out += p + cp.toString(16).padStart(w as number, "0"); + } else out += ch; + } + return quote + out + quote; +} + +// html.unescape: the entity names Python reads without a `;` (html.entities.html5), and its numeric replacements. +const LEGACY = new Set( + ( + "AElig AMP Aacute Acirc Agrave Aring Atilde Auml COPY Ccedil ETH Eacute Ecirc Egrave Euml GT Iacute Icirc Igrave " + + "Iuml LT Ntilde Oacute Ocirc Ograve Oslash Otilde Ouml QUOT REG THORN Uacute Ucirc Ugrave Uuml Yacute aacute acirc " + + "acute aelig agrave amp aring atilde auml brvbar ccedil cedil cent copy curren deg divide eacute ecirc egrave eth " + + "euml frac12 frac14 frac34 gt iacute icirc iexcl igrave iquest iuml laquo lt macr micro middot nbsp not ntilde " + + "oacute ocirc ograve ordf ordm oslash otilde ouml para plusmn pound quot raquo reg sect shy sup1 sup2 sup3 szlig " + + "thorn times uacute ucirc ugrave uml uuml yacute yen yuml" + ).split(" "), +); +// oxlint-disable-next-line t3code/no-em-dash-copy -- Windows-1252 bytes 0x80-0x9f, as html.unescape maps them. +const CP1252 = "€\x81‚ƒ„…†‡ˆ‰Š‹Œ\x8dŽ\x8f\x90‘’“”•\u2013\u2014˜™š›œ\x9džŸ"; +const ENTITY_RE = /&(#[0-9]+;?|#[xX][0-9a-fA-F]+;?|[^\t\n\f <&#;]{1,32};?)/gu; +const entities = characterEntities as Record; + +function charref(s: string): string { + if (s[0] === "#") { + const hex = s[1] === "x" || s[1] === "X"; + const num = Number.parseInt(s.slice(hex ? 2 : 1).replace(/;$/u, ""), hex ? 16 : 10); + if (num === 0) return "�"; + if (num === 13) return "\r"; + if (num >= 0x80 && num <= 0x9f) return CP1252[num - 0x80]!; + if ((num >= 0xd800 && num <= 0xdfff) || num > 0x10ffff) return "�"; + const invalid = + (num >= 1 && num <= 8) || + num === 11 || + (num >= 14 && num <= 31) || + (num >= 0x7f && num <= 0x9f); + if (invalid || (num >= 0xfdd0 && num <= 0xfdef) || (num & 0xfffe) === 0xfffe) return ""; + return String.fromCodePoint(num); + } + if (s.endsWith(";") && Object.hasOwn(entities, s.slice(0, -1))) return entities[s.slice(0, -1)]!; + if (LEGACY.has(s)) return entities[s]!; + const cps = Array.from(s); + for (let x = cps.length - 1; x > 1; x--) { + const name = cps.slice(0, x).join(""); + if (LEGACY.has(name)) return entities[name]! + cps.slice(x).join(""); + } + return "&" + s; +} + +/** Python's html.unescape: GitHub renders entities, so `major` is a label. */ +export const htmlUnescape = (text: string): string => + text.includes("&") ? text.replace(ENTITY_RE, (_m, s: string) => charref(s)) : text; diff --git a/apps/server/src/fork/reviewRules/reviewRules.test.ts b/apps/server/src/fork/reviewRules/reviewRules.test.ts new file mode 100644 index 0000000000000..ccba74f148b5c --- /dev/null +++ b/apps/server/src/fork/reviewRules/reviewRules.test.ts @@ -0,0 +1,401 @@ +// @effect-diagnostics nodeBuiltinImport:off +// Fork: the T3 side of the review rules replays the CI gate's own vectors (one source, never copied): +// fork-ci/actions/pr-queue/review.vectors.json and the gate's lens corpus. A section or field this side does not run +// fails here, so a vector added for the Python gate cannot be skipped by T3. +import * as NodeFS from "node:fs"; +import { assert, describe, it } from "@effect/vitest"; + +import { fold, readFindings } from "./findings.ts"; +import { + EDITED, + EMBEDDED, + HIDDEN, + NO_HEADER, + lensHeader, + lensKey, + lensProblem, + lensScan, +} from "./lensComment.ts"; +import { ReviewPlanError, globMatches, planReview, type ReviewBlock } from "./plan.ts"; +import { repr, splitlines } from "./pyText.ts"; +import { + CLEARED, + LOOSE, + REPORT, + judgeRounds, + requiredLenses, + roundMarker, + roundsText, + type EntryHow, +} from "./rounds.ts"; + +// Each read names its whole path: both files are `!` lines of .github/fork-owned-paths.txt, the rest of the folder is not. +const gate = (path: string) => + NodeFS.readFileSync(new URL(`../../../../../${path}`, import.meta.url), "utf8"); +const V = JSON.parse(gate("fork-ci/actions/pr-queue/review.vectors.json")); +const CORPUS = gate("fork-ci/actions/pr-queue/testdata/lens-corpus.jsonl") + .split("\n") + .filter(Boolean) + .map((line) => JSON.parse(line)); + +// The fields each section's vectors may carry; the Python side checks the same list (review_judge.test.py). +const FIELDS: Record | null> = { + about: null, + config_path: null, + override_prefix: null, + configs: null, + globs: null, + cases: ["name", "config", "changes", "weight", "lenses", "hits", "protected"], + findings: ["name", "group", "body", "findings", "section"], + scans: ["name", "posts", "history", "entries"], + rounds: [ + "name", + "config", + "history", + "reports", + "decided", + "changes", + "override_authors", + "findings", + "expect", + ], +}; +const configs = V.configs as Record; +const HEAD = `lens: code · reviewer: x · read at: ${"a".repeat(40)}\n`; + +function replayRound(v: any) { + const review: ReviewBlock = { + ...configs[v.config]!, + override_authors: v.override_authors ?? [], + findings: v.findings ?? true, + }; + const changes = v.changes as Record | undefined; + const got = judgeRounds( + review, + v.history, + v.reports as Record, + v.decided ?? false, + changes && ((sha: string) => changes[sha] ?? sha), + ); + return { + round: got.round, + approach: got.approach, + over_cap: got.overCap, + findings: got.findings, + problems: got.problems, + text: roundsText(review, got), + }; +} + +// Each post as the Python side's scan() posts it: by `someone`, one second apart, so the gate names it the same way. +const at = (i: number) => + `2026-01-01T00:${String(Math.floor(i / 60)).padStart(2, "0")}:${String(i % 60).padStart(2, "0")}Z`; +const posts = (v: any) => + (v.posts as Array<{ body: string; edited?: boolean; hidden?: boolean }>).map((p, i) => ({ + body: p.body, + edited: p.edited ?? false, + hidden: p.hidden ?? false, + where: `by someone at ${at(i)}`, + })); +const scan = (v: any) => lensScan(posts(v), V.override_prefix); + +describe("the shared vectors", () => { + it("runs every section and every field, each vector name once", () => { + assert.deepStrictEqual(Object.keys(V).toSorted(), Object.keys(FIELDS).toSorted()); + for (const [section, fields] of Object.entries(FIELDS)) { + if (!fields) continue; + const names = (V[section] as Array<{ name: string }>).map((v) => v.name); + assert.strictEqual(new Set(names).size, names.length, `${section}: a name twice`); + for (const v of V[section]) { + for (const k of Object.keys(v)) + assert.include(fields, k, `${section} ${v.name}: field ${k}`); + } + } + }); + + it("every glob", () => { + assert.isAtLeast(V.globs.length, 1); + for (const [glob, path, want] of V.globs) + assert.strictEqual(globMatches(glob, path), want, `${glob} ${path}`); + }); + + it("every case", () => { + assert.isAtLeast(V.cases.length, 28); + for (const c of V.cases) { + const plan = planReview(configs[c.config]!, c.changes, V.config_path); + assert.deepStrictEqual( + { + weight: plan.weight, + lenses: plan.lenses, + hits: plan.hits.map((h) => h.rule), + protected: plan.protected, + }, + { weight: c.weight, lenses: c.lenses, hits: c.hits, protected: c.protected }, + c.name, + ); + } + }); + + it("every findings vector", () => { + assert.isAtLeast(V.findings.length, 133); + for (const f of V.findings) { + assert.deepStrictEqual( + readFindings(f.body), + [f.findings, f.section], + `${f.group}: ${f.name}`, + ); + } + }); + + 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); + }); + + it("every round", () => { + assert.isAtLeast(V.rounds.length, 28); + for (const r of V.rounds) assert.deepStrictEqual(replayRound(r), r.expect, r.name); + }); + + it("every recorded lens_header and lens_key call of the gate's corpus", () => { + const fns: Record unknown> = { + lens_header: (body: string) => lensHeader(body), + lens_key: lensKey, + }; + const cases = CORPUS.filter((c) => c.fn in fns); + assert.strictEqual(cases.length, 528 + 46); + for (const c of cases) + assert.deepStrictEqual(fns[c.fn]!(...c.args), c.out, JSON.stringify(c.args)); + }); +}); + +// The state question, by name: each is a shared vector, so both sides answer it alike. +describe("rounds meet old, repeated, edited, deleted and empty state", () => { + const named = (section: string, name: string) => { + const v = (V[section] as Array<{ name: string }>).find((x) => x.name === name); + assert.isDefined(v, `${section}: ${name}`); + return v as any; + }; + it("the same comment read twice is one entry and one round", () => { + const s = named("scans", "the same comment read twice"); + assert.deepStrictEqual(Object.keys(scan(s).entries), ["code"]); + assert.strictEqual( + replayRound(named("rounds", "the same comment read twice is one round")).round, + 1, + ); + }); + it("an edited or hidden comment reads nothing but stays a round", () => { + const edited = scan( + named("scans", "an edited comment reads nothing and still counts in the history"), + ); + assert.deepStrictEqual(edited.entries.code, [null, EDITED]); + assert.strictEqual(edited.history.length, 2); + const hidden = scan( + named("scans", "a hidden comment reads nothing and still counts in the history"), + ); + assert.deepStrictEqual(hidden.entries.code, [null, HIDDEN]); + }); + it("a deleted older round counts only by a later round marker", () => { + assert.strictEqual( + replayRound(named("rounds", "a deleted older round no longer counts")).round, + 1, + ); + assert.strictEqual( + replayRound(named("rounds", "a deleted older round still counts by a later round marker")) + .round, + 3, + ); + }); + it("a pull request with no lens comments is round 0 and passes", () => { + assert.deepStrictEqual(lensScan([]), { history: [], entries: {} }); + const r = replayRound( + named("rounds", "a pull request with no lens comments is round 0 and passes"), + ); + assert.deepStrictEqual([r.round, r.problems], [0, []]); + }); + it("an old report from before findings were read (#740) has no section and blocks", () => { + const r = replayRound( + named("rounds", "an old report from before findings were read has no findings section"), + ); + assert.lengthOf(r.problems, 1); + assert.include(r.problems[0], "no findings section"); + }); + it("judging the same input again gives the same answer", () => { + for (const r of V.rounds) assert.deepStrictEqual(replayRound(r), replayRound(r), r.name); + }); + it("a post whose first line reads two ways reads nothing", () => { + const got = scan(named("scans", "a first line that reads two ways reads nothing")); + assert.deepStrictEqual(got.history, []); + assert.deepStrictEqual(Object.values(got.entries), [[null, null]]); + assert.isTrue(Object.keys(got.entries)[0]!.startsWith(NO_HEADER)); + }); + it("a second header under a valid one reads nothing, keeps the older read, and a new post does not clear it", () => { + const quoted = scan( + named( + "scans", + "a second lens header quoted under a valid one reads nothing; the older read stays", + ), + ); + assert.deepStrictEqual(quoted.history, [["code", "b".repeat(40)]]); + assert.deepStrictEqual(quoted.entries.code, ["b".repeat(40), null]); + const reposted = scan( + named("scans", "a correct new post does not clear a post that reads nothing"), + ); + assert.lengthOf(Object.keys(reposted.entries), 2); + assert.include(Object.keys(reposted.entries)[0], EMBEDDED); + }); + 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; + assert.isNull(lensProblem(body, V.override_prefix)); + assert.isNotNull(lensProblem(body)); + assert.isNotNull(lensProblem(body, "another prefix")); + }); +}); + +describe("the T3 side's own edges", () => { + const basic = configs.basic!; + it("refuses what it cannot read rather than needing no lens", () => { + for (const [changes, path] of [ + [[["X", "a"]], V.config_path], + [[["R100", "a"]], V.config_path], + [[["M", ""]], V.config_path], + [[["M", "a"]], "/abs/path.json"], + [[["M", "a"]], "a/../b.json"], + ] as const) { + assert.throws(() => planReview(basic, changes as any, path), ReviewPlanError); + } + const noCatchAll = { ...basic, rules: basic.rules.filter((r) => r.name !== "code") }; + assert.throws( + () => planReview(noCatchAll, [["M", "src/x.ts"]], V.config_path), + ReviewPlanError, + ); + assert.throws(() => planReview(noCatchAll, [], V.config_path), ReviewPlanError); + }); + + it("adds the approach lens by key, once", () => { + const review: ReviewBlock = { ...basic, override_authors: [] }; + const plan = planReview(review, [["M", "src/x.ts"]], V.config_path); + const late = judgeRounds( + review, + [ + ["code", "a"], + ["code", "b"], + ["code", "c"], + ], + { + code: [REPORT, `${HEAD}blocker: none\nmajor: none`], + }, + ); + assert.deepStrictEqual([...requiredLenses(review, plan, late).values()], ["code", "approach"]); + const decided = judgeRounds( + review, + [ + ["code", "a"], + ["code", "b"], + ["code", "c"], + ], + { code: [CLEARED, ""] }, + true, + ); + assert.deepStrictEqual([...requiredLenses(review, plan, decided).values()], ["code"]); + }); + + // Each answer below is the gate's (review_judge.py), where JavaScript's own rules would differ. + it("reads as Python's regex and int rules do", () => { + const none = `${HEAD}blocker: none\nmajor: none\n`; + assert.deepStrictEqual(readFindings(`${none}block\u0130ng: x`), [ + [["blocker", "block\u0130ng: x"]], + true, + ]); + assert.deepStrictEqual(readFindings(`${none}verdict: not safe\u00e9`), [[], true]); + assert.deepStrictEqual(readFindings(`${none}verdict: not safe!`), [ + [["blocker", "the report says NOT SAFE: verdict: not safe!"]], + true, + ]); + assert.deepStrictEqual(readFindings(`${HEAD}blocker: none\n### Major\n## Next section\nnone`), [ + [["major", "Major (nothing under it)"]], + true, + ]); + assert.strictEqual(roundMarker("code r\u0663"), 3); + assert.strictEqual(roundMarker("code r\u0661\u0662"), 12); + const review: ReviewBlock = { ...basic, override_authors: [] }; + const keys = judgeRounds(review, [], { + "\u{1F600}": [LOOSE, "major: x"], + "\uff42": [LOOSE, "major: y"], + }); + assert.deepStrictEqual( + keys.findings.map(([key]) => key), + ["\uff42", "\u{1F600}"], + ); + }); + + it("reads Python's text rules", () => { + assert.strictEqual(roundMarker("code r3"), 3); + assert.strictEqual(roundMarker("code **r12**"), 12); + assert.strictEqual(fold("major\\: x"), "major: x"); + assert.strictEqual(fold("majоr"), "major"); + assert.deepStrictEqual(splitlines("a\r\nb\u2028c\n"), ["a", "b", "c"]); + assert.strictEqual(repr('it\'s "x" \\'), `'it\\'s "x" \\\\'`); + assert.deepStrictEqual(readFindings(`${HEAD}blocker: none\nMAJOR: x`)[0], [ + ["major", "MAJOR: x"], + ]); + assert.deepStrictEqual(readFindings(`${HEAD}blocker: none\nmajor: x`)[0], [ + ["major", "major: x"], + ]); + assert.deepStrictEqual(readFindings(`${HEAD}blocker: none\nmajor: İx`)[0], [ + ["major", "major: İx"], + ]); + }); + + // The gate's linear-time lines and its answers (review_judge.test.py), each with its own time bound: the server's + // test timeout is 120 s, so a slow but not hanging path would pass without one. + const timed = (f: () => unknown, ms: number) => { + // oxlint-disable-next-line t3code/no-wall-clock-in-tests -- a linear-time bound, as the gate's own test has + const t = performance.now(); + f(); + // oxlint-disable-next-line t3code/no-wall-clock-in-tests -- the same bound + return assert.isBelow(performance.now() - t, ms); + }; + it("reads a long run of spaces in linear time, as the gate does", () => { + const n = 200_000; + const sp = " ".repeat(n); + const cases: Array<[string, Array<[string, string]>]> = [ + [`major${sp}x`, []], + [`blocker: none${sp}x`, [["blocker", "blocker: none x"]]], + [`| a | b |\n${sp}x`, []], + [`| a | b |\n|${sp}x`, []], + [`| a | b |\n|-${sp}x`, []], + [`not${sp}safe`, [["blocker", "the report says NOT SAFE: not safe"]]], + [`finding:${sp}x`, []], + [`major: none${" \t".repeat(n / 2)}x`, [["major", "major: none x"]]], + ]; + for (const [line, want] of cases) + timed(() => assert.deepStrictEqual(readFindings(HEAD + line), [want, false]), 2000); + }); + + it("reads a wide table row in linear time, as the gate does", () => { + // The old per-cell read took 39.5 s at 4,000 cells. Each about one full-size comment (65,536 characters). + const rows = [ + "| " + "major | ".repeat(8000), + "| " + "major | ".repeat(4000) + "x | ".repeat(4000), + "| " + "major | ".repeat(3000) + "\n|" + "---|".repeat(3000) + "\n| " + "x | ".repeat(3000), + "| major |" + " |".repeat(30_000) + " x |", + "|" + "---|".repeat(16_000) + "x", + ]; + for (const row of rows) timed(() => readFindings(HEAD + row), 2000); + assert.deepStrictEqual(readFindings(HEAD + rows[0]!)[0], [["major", "major ".repeat(20)]]); + }); + + it("reads a full-size comment's lens problem in linear time", () => { + const n = 16_000; + for (const body of [ + `${HEAD}${"lens: x read at 1234567\n".repeat(n / 8)}`, + `${HEAD}${"> ".repeat(n)}lens: code · read at: ${"a".repeat(40)}`, + `x\n${" ".repeat(n * 4)}read at 1234567`, + `not a lens: x\n${"> read at: 1234567\n".repeat(n / 8)}`, + ]) + timed(() => lensProblem(body), 2000); + }); +}); diff --git a/apps/server/src/fork/reviewRules/rounds.ts b/apps/server/src/fork/reviewRules/rounds.ts new file mode 100644 index 0000000000000..2cd40418dbfdf --- /dev/null +++ b/apps/server/src/fork/reviewRules/rounds.ts @@ -0,0 +1,167 @@ +/** + * Port of review_judge.judge_rounds (fork-ci/actions/pr-queue), held to the shared vectors. The problem texts match + * the gate's word for word, so T3 and the check summary say the same thing. + */ +import { lensKey } from "./lensComment.ts"; +import { fold, readFindings, type FindingKind } from "./findings.ts"; +import type { ReviewBlock, ReviewPlan } from "./plan.ts"; +import { digitValue, repr, split, stripChars } from "./pyText.ts"; + +const ROUND_RE = /^r(\p{Nd}{1,9})$/u; + +/** How each lens's newest entry is read (the gate's head_check.review_rounds says which one it is). */ +export const REPORT = "report"; +export const LOOSE = "loose"; +const UNREAD = "unread"; +export const CLEARED = "cleared"; +const NOT_JUDGED = "skip"; +export type EntryHow = + | typeof REPORT + | typeof LOOSE + | typeof UNREAD + | typeof CLEARED + | typeof NOT_JUDGED; + +/** Python's sorted() on strings: by code point, not by UTF-16 unit. */ +function byCodePoint(a: string, b: string): number { + const x = Array.from(a, (c) => c.codePointAt(0)!); + const y = Array.from(b, (c) => c.codePointAt(0)!); + for (let i = 0; i < Math.min(x.length, y.length); i++) if (x[i] !== y[i]) return x[i]! - y[i]!; + return x.length - y.length; +} + +/** The highest round marker (`r3`, also `**r3**` or `r3`) among a lens name's words after its first, or 0. */ +export function roundMarker(name: string): number { + let most = 0; + for (const word of split(fold(name).toLowerCase()).slice(1)) { + const m = ROUND_RE.exec(stripChars(word, "*_`")); + if (m) most = Math.max(most, Number(Array.from(m[1]!, digitValue).join(""))); + } + return most; +} + +/** + * The round the lens headers say. history: [lens name, sha or null] of every lens header that counts; changeOf(sha): + * what the pull request changes at that commit (without it each different sha is one change). + */ +function reviewRound( + history: ReadonlyArray, + changeOf: (sha: string) => string = (sha) => sha, +): number { + const changes = new Set(history.flatMap(([, sha]) => (sha ? [changeOf(sha.toLowerCase())] : []))); + return history.reduce((most, [name]) => Math.max(most, roundMarker(name)), changes.size); +} + +export interface Rounds { + readonly round: number; + /** The approach lens is required (round >= rounds.approach_at and no person decided). */ + readonly approach: boolean; + /** round > rounds.max and no person decided. */ + readonly overCap: boolean; + /** [lens key, kind, line] of every blocker or major no later round or person cleared. */ + readonly findings: ReadonlyArray<[string, FindingKind, string]>; + /** Why the head fails, plain text; empty: findings and rounds pass. */ + readonly problems: ReadonlyArray; +} + +/** How a person lets a head through, as the reasons say it. */ +function personWay(review: ReviewBlock, prefix = "override for head"): string { + const who = review.override_authors ?? []; + if (who.length === 0) { + return ( + "a person's override comment, but no one is listed in review.override_authors yet, so no override is accepted " + + "(issue #78: until agents no longer post as the person's login, an override is not proof of a person)" + ); + } + return `an override comment \`${prefix} : \` for this head by ${who.join(" or ")}, newer than every lens comment`; +} + +/** + * The rounds of a pull request's lens comments. reports: each lens key's newest entry [how, body]; decided: a person's + * override for this head is newer than every lens comment. + */ +export function judgeRounds( + review: ReviewBlock, + history: ReadonlyArray, + reports: Readonly>, + decided = false, + changeOf?: (sha: string) => string, + prefix = "override for head", +): Rounds { + const n = reviewRound(history, changeOf); + const cap = review.rounds.max; + const overCap = n > cap && !decided; + const way = personWay(review, prefix); + const problems: string[] = []; + if (overCap) { + problems.push( + `review round ${n} is past the cap of ${cap} rounds (issue #100): no more rounds; a person decides: close the ` + + `pull request, or ${way}. A person's override alone is enough, also for a required approach lens that never posted`, + ); + } + const found: Array<[string, FindingKind, string]> = []; + if (review.findings) { + for (const key of Object.keys(reports).sort(byCodePoint)) { + const [how, body] = reports[key]!; + if (how === CLEARED || how === NOT_JUDGED) continue; + if (how === UNREAD) { + problems.push( + `lens ${key}: its newest report reads nothing and only an override that is no person's covers it, so its ` + + `findings cannot be read (issue #99): that lens posts a new report, or ${way}`, + ); + continue; + } + const [said, section] = readFindings(body); + for (const [kind, line] of said) found.push([key, kind, line]); + if (how === REPORT && said.length === 0 && !section) { + problems.push( + `lens ${key}: its newest report has no findings section, so it cannot be judged (issue #99): write ` + + "`blocker: none` and `major: none`, or the findings, as lines of the report body (findings in inline " + + "review comments are not read)", + ); + } + } + for (const [key, kind, line] of found) { + const again = + n >= cap + ? `this is round ${n} of ${cap}: no more rounds; a person decides: close the pull request, or ${way}` + : `fix it, and lens ${key} posts a new report on the fixed head with no blocker or major (\`major: none\`); or ${way}`; + problems.push( + `lens ${key} reported a ${kind} that no later round cleared (issue #99): ${repr(line)}; ${again}`, + ); + } + } + return { + round: n, + approach: n >= review.rounds.approach_at && !decided, + overCap, + findings: found, + problems, + }; +} + +/** One line for the check summary. */ +export function roundsText(review: ReviewBlock, rounds: Rounds): string { + let said = `round ${rounds.round} of ${review.rounds.max}`; + if (rounds.approach) { + said += `, approach lens ${review.rounds.approach_lens} required from round ${review.rounds.approach_at}`; + } + if (!review.findings) said += "; findings are not judged (findings: false)"; + return ( + said + + (rounds.problems.length ? `; ${rounds.problems.join("; ")}` : "; no blocker or major open") + ); +} + +/** The lenses an enforced head needs, by lens key: the plan's, and the approach lens when the rounds require it. */ +export function requiredLenses( + review: ReviewBlock, + plan: ReviewPlan, + rounds: Rounds, +): Map { + const required = new Map(); + const add = (name: string) => required.has(lensKey(name)) || required.set(lensKey(name), name); + plan.lenses.forEach(add); + if (rounds.approach) add(review.rounds.approach_lens); + return required; +} diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 7ff83d13675d4..1dc8e28344e6f 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -148,8 +148,20 @@ whole). Then (`review_judge.py`, `review_glob.py`): each one count together: more paths, never fewer. `review.vectors.json` holds the shared cases (globs, rule sets, changed paths with -their status, and the expected weight and lenses); the Python tests read it, and -T3 tests its own matcher on the same file. +their status, and the expected weight and lenses; lens report bodies and the +findings read in them; lens comment scans; review rounds). The Python tests and +T3's pure copy of these rules (`apps/server/src/fork/reviewRules/`) both replay +every vector, and each side fails on a section or field it does not run. A rule +change updates both sides and the vectors in one pull request. + +How a vector is made: write its input (name, body or posts, config) by hand, +run the gate's own function on it (`review_judge.judge`, `read_findings`, +`judge_rounds`, or `lens.Review.lens_scan` the way `review_judge.test.py`'s +`scan()` posts it, with `override_prefix`), and paste the gate's answer as the +expected value. Check that the answer is the one the rule means: a vector +copied from a broken gate holds both sides to the broken answer. The Python +test checks each expected value against the gate, so a stale one fails there. +The file is formatted with `vp fmt`. Notes for T3's matcher and its GitHub reader (no change in the gate): diff --git a/fork-ci/actions/pr-queue/review.vectors.json b/fork-ci/actions/pr-queue/review.vectors.json index 078732e6f5743..236e275ced02c 100644 --- a/fork-ci/actions/pr-queue/review.vectors.json +++ b/fork-ci/actions/pr-queue/review.vectors.json @@ -1,6 +1,7 @@ { - "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`.", + "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a post that only looks like a report is a `comment without a first-line lens header` entry that reads nothing). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", "config_path": ".github/pr-queue.json", + "override_prefix": "override for head", "globs": [ ["**", "a", true], ["**", "a/b/c.py", true], @@ -50,7 +51,10 @@ ["a.b+c(d)$^|x", "aXb+c(d)$^|x", false], ["*.txt", "a\nb.txt", true], ["*", "a b", true], - ["src/**", "src/a b/c d.py", true] + ["src/**", "src/a b/c d.py", true], + ["?.py", "😀.py", true], + ["??.py", "😀.py", false], + ["a/*/b", "a/😀😀/b", true] ], "configs": { "basic": { @@ -63,17 +67,43 @@ "paths": ["src/storage/**", "migrations/**"], "lenses": ["data-1", "data-2"] }, - { "name": "docs", "weight": "light", "paths": ["docs/**", "**/*.md"], "lenses": [] }, - { "name": "code", "weight": "normal", "paths": ["**"], "lenses": ["code"] } + { + "name": "docs", + "weight": "light", + "paths": ["docs/**", "**/*.md"], + "lenses": [] + }, + { + "name": "code", + "weight": "normal", + "paths": ["**"], + "lenses": ["code"] + } ], "lenses": { - "data-1": { "prompt": ".github/lenses/data.md" }, - "data-2": { "prompt": ".github/lenses/data.md" }, - "code": { "prompt": ".github/lenses/code.md" }, - "approach": { "prompt": ".github/lenses/approach.md" } + "data-1": { + "prompt": ".github/lenses/data.md" + }, + "data-2": { + "prompt": ".github/lenses/data.md" + }, + "code": { + "prompt": ".github/lenses/code.md" + }, + "approach": { + "prompt": ".github/lenses/approach.md" + } + }, + "min_lenses": { + "critical": 2, + "normal": 1, + "light": 0 + }, + "rounds": { + "approach_at": 3, + "max": 4, + "approach_lens": "approach" }, - "min_lenses": { "critical": 2, "normal": 1, "light": 0 }, - "rounds": { "approach_at": 3, "max": 4, "approach_lens": "approach" }, "findings": true, "state_line": true }, @@ -93,21 +123,58 @@ "paths": ["src/**/schema.sql", "db/**"], "lenses": ["data-1", "data-2"] }, - { "name": "api", "weight": "normal", "paths": ["src/api/*.py"], "lenses": ["api", "code"] }, - { "name": "notes", "weight": "light", "paths": ["notes/*.txt", "config/*"], "lenses": [] }, - { "name": "rest", "weight": "normal", "paths": ["*/**"], "lenses": ["code"] } + { + "name": "api", + "weight": "normal", + "paths": ["src/api/*.py"], + "lenses": ["api", "code"] + }, + { + "name": "notes", + "weight": "light", + "paths": ["notes/*.txt", "config/*"], + "lenses": [] + }, + { + "name": "rest", + "weight": "normal", + "paths": ["*/**"], + "lenses": ["code"] + } ], "lenses": { - "security-1": { "prompt": "review/security.md" }, - "security-2": { "prompt": "review/security.md" }, - "data-1": { "prompt": "review/data.md" }, - "data-2": { "prompt": "review/data-second.md" }, - "api": { "prompt": "review/api.md" }, - "code": { "prompt": "review/code.md" }, - "approach": { "prompt": "review/approach.md" } - }, - "min_lenses": { "critical": 2, "normal": 1, "light": 0 }, - "rounds": { "approach_at": 3, "max": 4, "approach_lens": "approach" }, + "security-1": { + "prompt": "review/security.md" + }, + "security-2": { + "prompt": "review/security.md" + }, + "data-1": { + "prompt": "review/data.md" + }, + "data-2": { + "prompt": "review/data-second.md" + }, + "api": { + "prompt": "review/api.md" + }, + "code": { + "prompt": "review/code.md" + }, + "approach": { + "prompt": "review/approach.md" + } + }, + "min_lenses": { + "critical": 2, + "normal": 1, + "light": 0 + }, + "rounds": { + "approach_at": 3, + "max": 4, + "approach_lens": "approach" + }, "findings": true, "state_line": true }, @@ -115,8 +182,18 @@ "version": 1, "mode": "enforce", "rules": [ - { "name": "light", "weight": "light", "paths": ["docs/**"], "lenses": [] }, - { "name": "code", "weight": "normal", "paths": ["src/**"], "lenses": ["code"] }, + { + "name": "light", + "weight": "light", + "paths": ["docs/**"], + "lenses": [] + }, + { + "name": "code", + "weight": "normal", + "paths": ["src/**"], + "lenses": ["code"] + }, { "name": "everything", "weight": "critical", @@ -125,13 +202,29 @@ } ], "lenses": { - "code": { "prompt": "docs/lenses/code.md" }, - "deep-1": { "prompt": "docs/lenses/deep.md" }, - "deep-2": { "prompt": "docs/lenses/deep.md" }, - "approach": { "prompt": "docs/lenses/approach.md" } + "code": { + "prompt": "docs/lenses/code.md" + }, + "deep-1": { + "prompt": "docs/lenses/deep.md" + }, + "deep-2": { + "prompt": "docs/lenses/deep.md" + }, + "approach": { + "prompt": "docs/lenses/approach.md" + } + }, + "min_lenses": { + "critical": 2, + "normal": 1, + "light": 0 + }, + "rounds": { + "approach_at": 3, + "max": 4, + "approach_lens": "approach" }, - "min_lenses": { "critical": 2, "normal": 1, "light": 0 }, - "rounds": { "approach_at": 3, "max": 4, "approach_lens": "approach" }, "findings": false, "state_line": false } @@ -439,5 +532,2023 @@ "hits": ["light", "code"], "protected": [] } + ], + "findings": [ + { + "name": "heading, numbered item", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Blocking\n\n1. **The lock is gone.** Two writers race on the row.", + "findings": [["blocker", "Blocking The lock is gone. Two writers race on the row."]], + "section": false + }, + { + "name": "heading, bold item", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Major\n**B1. The retry loops forever.**", + "findings": [["major", "Major B1. The retry loops forever."]], + "section": false + }, + { + "name": "heading with a note", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Blocking (merge, not safety)\n1. The queue merges an unread head.", + "findings": [["blocker", "Blocking (merge, not safety) The queue merges an unread head."]], + "section": false + }, + { + "name": "heading with a long note", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Major (older than this PR; a follow-up issue is fine)\n- the cache never expires", + "findings": [ + ["major", "Major (older than this PR; a follow-up issue is fine) the cache never expires"] + ], + "section": false + }, + { + "name": "bold inline", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n**Blocking:** the lock is gone.", + "findings": [["blocker", "Blocking: the lock is gone."]], + "section": false + }, + { + "name": "bold bare, item under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n**Major**\n- two writers race", + "findings": [["major", "Major two writers race"]], + "section": false + }, + { + "name": "plain", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nBlocking: x", + "findings": [["blocker", "Blocking: x"]], + "section": false + }, + { + "name": "findings word", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nMajor findings: x", + "findings": [["major", "Major findings: x"]], + "section": false + }, + { + "name": "findings word, list under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nMajor findings:\n1. x", + "findings": [["major", "Major findings: x"]], + "section": false + }, + { + "name": "dash list", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n- major — x", + "findings": [["major", "major — x"]], + "section": false + }, + { + "name": "en dash", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor – x", + "findings": [["major", "major – x"]], + "section": false + }, + { + "name": "hyphen", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor - x", + "findings": [["major", "major - x"]], + "section": false + }, + { + "name": "emoji", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n🔴 Major: x", + "findings": [["major", "Major: x"]], + "section": false + }, + { + "name": "emoji, bold", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n⚠️ **Blocker**: x", + "findings": [["blocker", "Blocker: x"]], + "section": false + }, + { + "name": "numbered label", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor 2: a retry loops", + "findings": [["major", "major 2: a retry loops"]], + "section": false + }, + { + "name": "plural with a note", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nMajors (state): stopped half-way leaves a row", + "findings": [["major", "Majors (state): stopped half-way leaves a row"]], + "section": false + }, + { + "name": "brackets", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n[major] x", + "findings": [["major", "[major] x"]], + "section": false + }, + { + "name": "second label of a line", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nBlocker: none, major: two writers race", + "findings": [["major", "Blocker: none, major: two writers race"]], + "section": true + }, + { + "name": "after a semicolon", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none; major: x", + "findings": [["major", "blocker: none; major: x"]], + "section": true + }, + { + "name": "after and", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none and major: x", + "findings": [["major", "blocker: none and major: x"]], + "section": true + }, + { + "name": "table row", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| severity | finding |\n|---|---|\n| major | x |", + "findings": [["major", "major x"]], + "section": false + }, + { + "name": "table row, bold", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| **Blocker** | the lock is gone |", + "findings": [["blocker", "Blocker the lock is gone"]], + "section": false + }, + { + "name": "table column", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| blocker | major |\n| --- | --- |\n| none | two writers race |", + "findings": [["major", "none two writers race"]], + "section": true + }, + { + "name": "fullwidth M (NFKC)", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nMajor: x", + "findings": [["major", "Major: x"]], + "section": false + }, + { + "name": "zero-width space", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmaj​or: x", + "findings": [["major", "major: x"]], + "section": false + }, + { + "name": "zero-width joiner in heading", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Bl‍ocking\n1. x", + "findings": [["blocker", "Blocking x"]], + "section": false + }, + { + "name": "soft hyphen", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nma­jor: x", + "findings": [["major", "major: x"]], + "section": false + }, + { + "name": "Cyrillic o", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajоr: x", + "findings": [["major", "major: x"]], + "section": false + }, + { + "name": "Cyrillic M", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nМajor: x", + "findings": [["major", "Major: x"]], + "section": false + }, + { + "name": "Greek omicron", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblοcker: x", + "findings": [["blocker", "blocker: x"]], + "section": false + }, + { + "name": "digit zero for o", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmaj0r: x", + "findings": [["major", "maj0r: x"]], + "section": false + }, + { + "name": "heading, code under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Major\n```\nthe race is in x\n```", + "findings": [["major", "Major ```"]], + "section": false + }, + { + "name": "heading, nothing under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Major", + "findings": [["major", "Major (nothing under it)"]], + "section": false + }, + { + "name": "heading, next heading under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n### Major\n### Minor\n- a typo", + "findings": [["major", "Major (nothing under it)"]], + "section": false + }, + { + "name": "bare label, nothing under it", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor:", + "findings": [["major", "major: (nothing under it)"]], + "section": false + }, + { + "name": "a none that is not one", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: none of the retries stop", + "findings": [["major", "major: none of the retries stop"]], + "section": false + }, + { + "name": "a no that is not one", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: no lock on the write path", + "findings": [["major", "major: no lock on the write path"]], + "section": false + }, + { + "name": "a dash that is not one", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: - x", + "findings": [["major", "major: - x"]], + "section": false + }, + { + "name": "see below", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: see below", + "findings": [["blocker", "blocker: see below"]], + "section": false + }, + { + "name": "quoted (read: fail closed)", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n> major: quoted from round 1", + "findings": [["major", "major: quoted from round 1"]], + "section": false + }, + { + "name": "indented (read: fail closed)", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n major: in an indented block", + "findings": [["major", "major: in an indented block"]], + "section": false + }, + { + "name": "HTML tag", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: x", + "findings": [["major", "major: x"]], + "section": false + }, + { + "name": "link", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n[major](http://e/x): y", + "findings": [["major", "major: y"]], + "section": false + }, + { + "name": "summary tag", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
major: x", + "findings": [["major", "major: x"]], + "section": false + }, + { + "name": "narrow read only", + "group": "finding", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor (see ", + "findings": [["major", "major (see