diff --git a/apps/server/src/fork/reviewRules/findings.ts b/apps/server/src/fork/reviewRules/findings.ts index 07ac6729be330..4811c425b4445 100644 --- a/apps/server/src/fork/reviewRules/findings.ts +++ b/apps/server/src/fork/reviewRules/findings.ts @@ -12,6 +12,7 @@ import { htmlUnescape, isBlank, pyI, + pyUnicodeCheck, splitlines, strip, stripChars, @@ -60,6 +61,7 @@ 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 { + pyUnicodeCheck(text ?? ""); const t = htmlUnescape((text ?? "").normalize("NFKC")) .replace(/\\([!-/:-@[-`{-~])/gu, "$1") .replace(/\p{Cf}/gu, ""); @@ -186,6 +188,7 @@ function read(lines: ReadonlyArray, narrow: boolean): Read { * 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] { + pyUnicodeCheck(body); const lines = splitlines(body); const found = new Map(); const seen = new Set(); diff --git a/apps/server/src/fork/reviewRules/lensComment.ts b/apps/server/src/fork/reviewRules/lensComment.ts index 8f246736b9011..88e36504052a7 100644 --- a/apps/server/src/fork/reviewRules/lensComment.ts +++ b/apps/server/src/fork/reviewRules/lensComment.ts @@ -3,14 +3,19 @@ * 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 * as Schema from "effect/Schema"; + import { ALNUM, B, S, WS, + byCodePoint, cut, isBlank, + PyTextError, pyI, + pyUnicodeCheck, repr, split, splitlines, @@ -18,6 +23,7 @@ import { stripChars, } from "./pyText.ts"; +const isPyTextError = Schema.is(PyTextError); const TAG_OPEN = /<\/?[A-Za-z]/gu; const TAG_NARROW = /<\/?[A-Za-z][^<>]*>/gu; const LINK_NARROW = /!?\[([^[\]]*)\]\([^()]*\)/gu; @@ -54,6 +60,8 @@ const TOP_LINES = 5; export const NO_HEADER = "comment without a first-line lens header"; export const EDITED = "edited after posting: post a new comment instead"; export const HIDDEN = "hidden: post a new comment instead"; +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"; 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"; @@ -110,6 +118,7 @@ const opensPlain = (line: string) => !/^(?: {4}|\t| {0,3}(?:>|`{3}|~{3}))/u.test /** One key per lens across rounds: the name lower-case, without a trailing round marker or emphasis. */ export function lensKey(name: string): string { + pyUnicodeCheck(name); const words = split(name.toLowerCase()); let lo = 0; let hi = words.length; @@ -140,6 +149,7 @@ export function namesALens(name: string): boolean { /** [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 { + pyUnicodeCheck(body); const first = splitlines(body).find((line) => !isBlank(line)) ?? ""; if (!opensPlain(first)) return null; const line = normLine(first, narrow); @@ -241,6 +251,7 @@ function readProblem(body: string, narrow: boolean): string | null { * never counts. */ export function lensProblem(body: string, overridePrefix?: string): string | null { + pyUnicodeCheck(body); if ( overridePrefix !== undefined && body.startsWith(`${overridePrefix} `) && @@ -260,15 +271,44 @@ export function lensProblem(body: string, overridePrefix?: string): string | nul return problem; } -/** A pull request comment or review whose author counts (a lens author association, no bot), in posting order. */ +/** + * A pull request comment, review or inline review comment whose author counts (a lens author association, no bot), + * in the gate's list order (lens.Review.lens_posts): the comments, then the reviews, then the inline comments. + */ 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; + /** + * How the gate names the post in a NO_HEADER key: its url, else `by at `. A key holds the post's + * text, so a caller never matches on a key's text: it reads `NO_HEADER` entries by their prefix only. + */ + readonly where: string; + /** createdAt of a comment or inline comment, submittedAt of a review, or "": with the list index, the post's age. */ + readonly when: string; + /** A review whose edit and hidden flags were not read (lens.UNREAD): it reads nothing (FLAGS_UNREAD). */ + readonly unread?: boolean; +} + +/** A post's age as the gate orders it: [when, list index], `when` by code point first. */ +export type PostAt = readonly [when: string, index: number]; + +/** a is older than b (Python's tuple `<`). */ +export const olderThan = (a: PostAt, b: PostAt): boolean => { + const by = byCodePoint(a[0], b[0]); + return by < 0 || (by === 0 && a[1] < b[1]); +}; + +export interface LensEntry { + readonly at: PostAt; + readonly sha: string | null; + readonly why: string | null; + /** The lens name of its newest header; null for a NO_HEADER entry. */ + readonly name: string | null; + /** The post's body: review_judge reads the newest report's findings from it. */ + readonly body: string; } export interface LensScan { @@ -278,22 +318,54 @@ export interface LensScan { 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 { +/** + * lens.Review.lens_scan with each entry's age: the newest post per lens key by [when, index], `index` the post's place + * in `posts`. `skip` leaves a post out (an override) but keeps its index. History stays in list order. A post the + * rules cannot read as Python does throws PyTextError naming that post (`where`). + */ +export function lensEntries( + posts: ReadonlyArray, + overridePrefix?: string, + skip: (post: LensPost) => boolean = () => false, +): { history: Array<[string, string | null]>; entries: Map } { const history: Array<[string, string | null]> = []; - const entries: Record = {}; + const entries = new Map(); posts.forEach((post, i) => { - const problem = lensProblem(post.body, overridePrefix); + if (skip(post)) return; + const at: PostAt = [post.when, i]; + const { body } = post; + const hidden = !post.unread && post.hidden; + let problem: string | null; + let header: [string, string | null] | null; + let key: string; + try { + problem = lensProblem(body, overridePrefix); + header = problem ? 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) { - const where = post.where ?? `post ${i + 1}`; - entries[`${NO_HEADER} (${where}, ${problem}${post.hidden ? ", hidden" : ""})`] = [null, null]; + key = `${NO_HEADER} (${post.where}, ${problem}${hidden ? ", hidden" : ""})`; + entries.set(key, { at, sha: null, why: null, name: null, body }); 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]; + const was = entries.get(key); + if (was && olderThan(at, was.at)) return; + 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 }; } + +/** 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 out: Record = {}; + for (const [key, { sha, why }] of entries) out[key] = [sha, why]; + return { history, entries: out }; +} diff --git a/apps/server/src/fork/reviewRules/lensStart.test.ts b/apps/server/src/fork/reviewRules/lensStart.test.ts index 04da03622eef9..b5cfda8e716a9 100644 --- a/apps/server/src/fork/reviewRules/lensStart.test.ts +++ b/apps/server/src/fork/reviewRules/lensStart.test.ts @@ -6,15 +6,22 @@ import * as NodeFS from "node:fs"; import { effectiveReviewRules } from "@t3tools/contracts"; import { assert, describe, it } from "@effect/vitest"; -import { lensKey, lensScan } from "./lensComment.ts"; +import { NO_HEADER, lensKey, lensScan } from "./lensComment.ts"; +import { readFindings } from "./findings.ts"; +import { byCodePoint } from "./pyText.ts"; +import { vectorPosts, type VectorPost } from "./vectors.testkit.ts"; import { FALLBACK_REVIEW, + LENS_START_MAX_ATTEMPTS, LENS_START_MAX_PRS, confirmLensStart, + earlierChild, gateReads, + gateReadsPass, lensRequestId, planLensStart, startRounds, + postAgainKeys, type LensStartBase, type LensStartInput, type LensStartPlan, @@ -48,6 +55,8 @@ const report = (lens: string, sha: string): LensStartPost => ({ body: `lens: ${lens} · reviewer: x · read at: ${sha}\nstate: fine\nblocker: none\nmajor: none`, edited: false, hidden: false, + where: `report ${lens} ${sha}`, + when: "", }); /** Every lens prompt of a config, read at the base. */ const promptsOf = (review: ReviewBlock) => @@ -57,6 +66,8 @@ const override = (sha: string): LensStartPost => ({ body: `${V.override_prefix} ${sha}: a person looked`, edited: false, hidden: false, + where: `override ${sha}`, + when: "", override: sha, }); @@ -100,10 +111,9 @@ function input( } /** - * The gate's lens verdict, written from its own code, not from lensStart.ts: head_check.decide's required lenses (the - * input; in enforce also the path lenses, as the shared case vector names them, and the approach lens from its - * round), lens.Review.lens_reads (each lens's newest entry; a newer override covers it) and head_check.verdict (every - * required key read, every entry one full sha, the head or the same change). + * The gate's lens verdict, written from its own code (not lensStart.ts): head_check.decide's required lenses, + * lens_reads (newest entry by [when, index]; a newer override covers it), head_check.verdict (one full sha: the head or + * `sameChange`) and, in enforce, review_rounds' UNREAD. `changeOf` (the own diff) counts rounds only. */ function gatePasses( review: ReviewBlock, @@ -112,21 +122,35 @@ function gatePasses( posts: ReadonlyArray, head: string, changeOf: (sha: string) => string = (sha) => sha, + sameChange: (read: string) => boolean = () => false, ): boolean { - const lensPosts = posts.flatMap((p, i) => (p.override === undefined ? [{ p, i }] : [])); - const newest = posts.findLastIndex((p) => p.override !== undefined); - const entries: Record = {}; + // Each post's age as a rank: the posts sorted by their time, ties by list place (lens_posts' [when, index]). + const rank: number[] = []; + posts + .map((p, i) => ({ p, i })) + .toSorted((x, y) => byCodePoint(x.p.when, y.p.when) || x.i - y.i) + .forEach(({ i }, r) => (rank[i] = r)); + const byAge = posts.map((p, i) => ({ p, i: rank[i]! })).toSorted((x, y) => x.i - y.i); + const lensPosts = byAge.filter(({ p }) => p.override === undefined); + const newest = byAge.findLast(({ p }) => p.override !== undefined)?.i ?? -1; + const people = (review.override_authors ?? []).map((a) => a.toLowerCase()); + const person = + byAge.findLast( + ({ p }) => + p.override !== undefined && + people.includes((p.author ?? "").toLowerCase()) && + (p.override === head || sameChange(p.override)), + )?.i ?? -1; + const entries: Record = {}; for (const { p, i } of lensPosts) { - for (const [key, [sha]] of Object.entries( - lensScan([{ ...p, where: `post ${i + 1}` }], V.override_prefix).entries, - )) { - entries[key] = { at: i, sha }; + for (const [key, [sha]] of Object.entries(lensScan([p], V.override_prefix).entries)) { + entries[key] = { at: i, sha, body: p.body }; } } const reads = Object.entries(entries).map(([key, { at, sha }]) => [ key, newest >= 0 && at < newest - ? posts[newest]!.override! + ? byAge[newest]!.p.override! : sha && /^[0-9a-f]{40}$/u.test(sha) ? sha : null, @@ -135,21 +159,32 @@ function gatePasses( if (review.mode === "enforce") { pathLenses.forEach((name) => required.add(lensKey(name))); const history = lensScan( - lensPosts.map(({ p }) => p), + posts.filter((p) => p.override === undefined), V.override_prefix, ).history; if (judgeRounds(review, history, {}, false, changeOf).approach) required.add(lensKey(review.rounds.approach_lens)); + // review_rounds: UNREAD (no full sha, a newer override) or a REPORT with no findings section fails the head. + const failed = Object.entries(entries).some(([key, { at, sha, body }]) => { + if (!review.findings || at < person || key.startsWith(NO_HEADER)) return false; + if (sha && /^[0-9a-f]{40}$/u.test(sha)) { + const [said, section] = readFindings(body); + return said.length === 0 && !section; + } + return at < newest; + }); + if (failed) return false; } if (reads.length === 0) return required.size === 0; if ([...required].some((key) => !(key in entries))) return false; const shas = new Set(reads.map(([, sha]) => sha)); const [sha] = shas; - return ( - shas.size === 1 && typeof sha === "string" && (sha === head || changeOf(sha) === changeOf(head)) - ); + return shas.size === 1 && typeof sha === "string" && (sha === head || sameChange(sha as string)); } +/** A time after every vector post's: the reads a carried-out plan adds come last. */ +const LATER = "2026-12-31T00:00:00Z"; + const lensesOf = (plan: ReturnType) => plan.starts.map((s) => s.lens); describe("lens_start on the shared vectors", () => { @@ -208,19 +243,10 @@ describe("lens_start on the shared vectors", () => { it("every shared vector state: after the plan is carried out the gate passes, or a person must act", () => { // States: each scan's posts, each round's history as reports, and mixed heads the vectors do not hold. const states: Array<[string, LensStartPost[]]> = [ - ...V.scans.map( - (v: { - name: string; - posts: Array<{ body: string; edited?: boolean; hidden?: boolean }>; - }) => [ - `scan ${v.name}`, - v.posts.map((p) => ({ - body: p.body, - edited: p.edited ?? false, - hidden: p.hidden ?? false, - })), - ], - ), + ...V.scans.map((v: { name: string; posts: VectorPost[] }) => [ + `scan ${v.name}`, + vectorPosts(v.posts), + ]), ...V.rounds.map((r: { name: string; history: Array<[string, string | null]> }) => [ `round ${r.name}`, r.history.flatMap(([name, sha]) => (sha ? [report(name, sha)] : [])), @@ -230,14 +256,25 @@ describe("lens_start on the shared vectors", () => { ["an override covers an older read", [report("code", B), override(A)]], [ "an override covers a comment that reads nothing", - [ - { body: `Review done.\n${report("code", B).body}`, edited: false, hidden: false }, - override(A), - ], + [{ ...report("code", B), body: `Review done.\n${report("code", B).body}` }, override(A)], ], ["a read newer than an override", [override(A), report("code", B)]], + // The gate (enforce) cannot read the findings of an edited report that only a non-person override covers. + [ + "an override covers an edited report", + [{ ...report("code", A), edited: true }, override(A)], + ], + ["an override covers a short read", [report("code", A.slice(0, 7)), override(A)]], + ]; + // How a read relates to the head: the commit itself only; the same own diff but another commit (an amended + // message, a rebase, a force-push: the gate fails it); the same diff and the head merges it with the base. + const ways: Array< + [string, ((sha: string) => string) | undefined, ((sha: string) => boolean) | undefined] + > = [ + ["own", undefined, undefined], + ["amended", () => "one change", undefined], + ["merged", () => "one change", () => true], ]; - const sameChange = () => "one change"; let plans = 0; let carried = 0; let mixed = 0; @@ -248,8 +285,8 @@ describe("lens_start on the shared vectors", () => { for (const required of enforce ? [[], ["code"]] : [["code"], ["code", "data-1"]]) { for (const [name, posts] of states) { for (const head of [A, F]) { - for (const changeOf of [undefined, sameChange]) { - const at = `${c.name} / ${name} / ${required.join(",")} / ${head.slice(0, 1)} / ${changeOf ? "same" : "own"}`; + for (const [way, changeOf, sameChange] of ways) { + const at = `${c.name} / ${name} / ${required.join(",")} / ${head.slice(0, 1)} / ${way}`; const one = (list: LensStartPost[]) => planLensStart( input({ @@ -261,6 +298,7 @@ describe("lens_start on the shared vectors", () => { posts: list, changes: c.changes, ...(changeOf ? { changeOf } : {}), + ...(sameChange ? { sameChange } : {}), }), ], }), @@ -276,7 +314,9 @@ describe("lens_start on the shared vectors", () => { } const after = [ ...posts, - ...plan.starts.flatMap((s) => s.prs.map((r) => report(s.lens, r.head))), + ...plan.starts.flatMap((s) => + s.prs.map((r) => ({ ...report(s.lens, r.head), when: LATER })), + ), ]; if (plan.starts.length > 0) carried++; if ( @@ -284,7 +324,10 @@ describe("lens_start on the shared vectors", () => { 1 ) mixed++; - assert.isTrue(gatePasses(review, required, c.lenses, after, head, changeOf), at); + assert.isTrue( + gatePasses(review, required, c.lenses, after, head, changeOf, sameChange), + at, + ); // Runs again: the carried-out plan starts nothing more. assert.deepStrictEqual(one(after).starts, [], `${at}: again`); } @@ -292,13 +335,42 @@ describe("lens_start on the shared vectors", () => { } } } - assert.isAtLeast(plans, V.cases.length * (V.scans.length + V.rounds.length) * 8); + assert.isAtLeast(plans, V.cases.length * (V.scans.length + V.rounds.length) * 12); assert.isAtLeast(carried, 1000); assert.isAtLeast(mixed, 100); assert.isAtLeast(refusedByPerson, 100); }); }); +describe("lens_start reads the posts as the gate does (the shared `reads` vectors)", () => { + it("every reads vector: each lens's read, the lenses that must post again, and whether the gate passes", () => { + assert.isAtLeast(V.reads.length, 10); + for (const v of V.reads) { + const posts = vectorPosts(v.posts as VectorPost[], V.override_prefix); + const review: ReviewBlock = { + ...basic, + mode: "enforce", + findings: true, + override_authors: v.override_authors, + }; + const sameChange = (read: string) => (v.same as string[]).includes(read); + const reads = gateReads(posts, V.override_prefix); + const again = postAgainKeys(posts, review, v.head, sameChange, V.override_prefix); + assert.deepStrictEqual( + { + reads: Object.fromEntries([...reads].map(([key, r]) => [key, r.sha])), + again: [...again.keys()].toSorted(byCodePoint), + passes: + again.size === 0 && + gateReadsPass(reads, (v.required as string[]).map(lensKey), v.head, sameChange), + }, + v.expect, + v.name, + ); + } + }); +}); + describe("lens_start answers the state question", () => { it("runs again: the same call twice is the same plan, the same ids, the same prompts", () => { const make = () => @@ -346,6 +418,92 @@ describe("lens_start answers the state question", () => { ); }); + it("the newest post by time counts, not the last one listed (the gate lists reviews after comments)", () => { + const t = (second: number) => `2026-01-01T00:00:0${second}Z`; + const plan = (posts: LensStartPost[]) => + lensesOf(planLensStart(input({ pullList: [pull(1, { posts })] }))); + // The comment reading the head is newer than the review listed after it. + assert.deepStrictEqual( + plan([ + { ...report("code", A), when: t(9) }, + { ...report("code", B), when: t(1) }, + ]), + [], + ); + assert.deepStrictEqual( + plan([ + { ...report("code", A), when: t(1) }, + { ...report("code", B), when: t(9) }, + ]), + ["code"], + ); + // An override listed last but older than the read covers nothing. + const late = [ + { ...report("code", B), when: t(9) }, + { ...override(A), when: t(5) }, + ]; + assert.strictEqual(gateReads(late, V.override_prefix).get("code")?.sha, B); + assert.deepStrictEqual(plan(late), ["code"]); + // Of two overrides the newest by time covers, not the last listed (an override posted as a review is listed last). + const two = [ + { ...report("code", C), when: t(1) }, + { ...override(A), when: t(5) }, + { ...override(B), when: t(3) }, + ]; + assert.strictEqual(gateReads(two, V.override_prefix).get("code")?.sha, A); + assert.deepStrictEqual( + lensesOf( + planLensStart( + input({ review: null, required: ["code"], pullList: [pull(1, { posts: two })] }), + ), + ), + [], + ); + // Nor does it make a newer short read UNREAD in enforce. + const short = [ + { ...report("code", A.slice(0, 7)), when: t(5) }, + { ...override(B), when: t(1) }, + ]; + const again = (posts: LensStartPost[]) => [ + ...postAgainKeys(posts, { ...basic, findings: true }, A).keys(), + ]; + assert.deepStrictEqual(again(short), []); + assert.deepStrictEqual(again(short.toReversed()), []); + assert.deepStrictEqual(again([short[0]!, { ...short[1]!, when: t(9) }]), ["code"]); + }); + + it("a comment the gate's Unicode reads otherwise refuses that pull request only, naming the post and the way out", () => { + // U+1C89 is unassigned in the gate's Python (Unicode 15.0) and a letter in this runtime's. + const drift = { ...report("code", B), body: `${report("code", B).body}\n\u1c89major: x` }; + const plan = planLensStart( + input({ + pullList: [pull(1, { posts: [drift] }), pull(2)], + }), + ); + assert.deepStrictEqual(plan.refused, [ + { + pr: 1, + reason: + `its lens comments cannot be read as the gate reads them: the post report code ${B} holds U+1C89, ` + + "which the gate's Python (Unicode 15.0.0) and this runtime assign differently, so the two would read it " + + "differently. The gate reads that post; lens_start does not, so it starts nothing here until someone " + + "edits the post to drop U+1C89 or deletes it (hiding it is not enough), then calls lens_start again", + }, + ]); + // A symbol new after Unicode 15.0 (U+1FAE9, an emoji) is read alike by both, as no letter, digit or space: in a + // chat comment or a report it refuses nothing. + const chat = { ...report("x", A), body: "thanks \u{1fae9}", where: "chat" }; + const emoji = { ...report("code", A), body: `${report("code", A).body} \u{1fae9}` }; + for (const posts of [[chat], [emoji]]) { + const read = planLensStart(input({ pullList: [pull(1, { posts })] })); + assert.deepStrictEqual(read.refused, []); + } + assert.deepStrictEqual( + plan.starts.map((s) => [s.lens, s.prs.map((p) => p.number)]), + [["code", [2]]], + ); + }); + it("a short read-at sha never counts as reading the head, even of the same change", () => { const short = report("code", A.slice(0, 7)); const plan = planLensStart( @@ -365,16 +523,45 @@ describe("lens_start answers the state question", () => { ); }); - it("a read before a clean base merge still read the head when the change is the same", () => { + it("a read before a clean base merge still read the head: the gate's same-change check says so", () => { const plan = planLensStart( input({ - pullList: [pull(1, { head: B, posts: [report("code", A)], changeOf: () => "same" })], + pullList: [ + pull(1, { + head: B, + posts: [report("code", A)], + changeOf: () => "same", + sameChange: (read) => read === A, + }), + ], }), ); assert.deepStrictEqual(lensesOf(plan), []); assert.deepStrictEqual(plan.alreadyRead, [{ pr: 1, lens: "code" }]); }); + it("the same diff in other commits (an amend, a rebase, a force-push) is not read: every lens starts again", () => { + // The own diff matches, so it is no new round, but the gate fails a head that is not the read commit merged + // with the base: lens_start must start the lens, never count it as read. + for (const over of [{}, { sameChange: () => false }]) { + const plan = planLensStart( + input({ + pullList: [ + pull(1, { + head: B, + posts: [report("code", A)], + changeOf: () => "same", + ...over, + }), + ], + }), + ); + assert.deepStrictEqual(lensesOf(plan), ["code"]); + assert.deepStrictEqual(plan.alreadyRead, []); + assert.deepStrictEqual(plan.starts[0]!.prs, [{ number: 1, head: B, round: 1 }]); + } + }); + it("the head moved since the plan: the child is refused, call again plans the new head", () => { const plan = planLensStart(input({ pullList: [pull(1), pull(2, { head: B })] })); assert.lengthOf(plan.starts, 1); @@ -387,7 +574,16 @@ describe("lens_start answers the state question", () => { ); assert.deepStrictEqual(moved.starts, []); assert.include(moved.refused.find((r) => r.pr === 1)!.reason, `moved from ${A} to ${C}`); - assert.isTrue(moved.refused.some((r) => r.pr === null && r.reason.includes("#1 #2"))); + assert.deepStrictEqual( + moved.refused.filter((r) => r.pr === null), + [ + { + pr: null, + reason: + "lens code for #1 #2 is not started: a pull request of its batch moved; call lens_start again", + }, + ], + ); const kept = confirmLensStart( plan, new Map([ @@ -580,7 +776,7 @@ describe("lens_start's plan, prompt and refusals", () => { ], [ { prs: Array.from({ length: LENS_START_MAX_PRS + 1 }, (_, i) => ({ number: i + 1 })) }, - `at most ${LENS_START_MAX_PRS}`, + `at most ${LENS_START_MAX_PRS} pull requests per call, not ${LENS_START_MAX_PRS + 1}`, ], ] as const) { const plan = planLensStart({ ...input({}), ...over }); @@ -592,6 +788,14 @@ describe("lens_start's plan, prompt and refusals", () => { assert.include(plan.refused[0]!.reason, words); } assert.lengthOf(planLensStart({ ...input({}), prs: [{ number: 1 }, { number: 1 }] }).starts, 1); + // Exactly the cap is one call. + const ten = Array.from({ length: LENS_START_MAX_PRS }, (_, i) => pull(i + 1)); + const full = planLensStart(input({ pullList: ten })); + assert.deepStrictEqual(full.refused, []); + assert.deepStrictEqual( + full.starts.flatMap((s) => s.prs.map((r) => r.number)), + ten.map((p) => p.number), + ); assert.include( planLensStart(input({ pullList: [pull(1, { head: "abc" })] })).refused[0]!.reason, "not a full sha", @@ -666,11 +870,20 @@ describe("lens_start's plan, prompt and refusals", () => { ).refused[0]!.reason, "past the cap of 4", ); - // Old or empty state: no block and no input fails every head at the gate; a person must name the lenses. + // Old or empty state: no block and no input, the gate requires no lens; lens_start starts none and says why. for (const required of [[], ["", " "]]) { const none = planLensStart(input({ review: null, required })); assert.deepStrictEqual(none.starts, []); - assert.include(none.refused[0]!.reason, "a person names the lenses"); + assert.deepStrictEqual(none.refused, [ + { + pr: 1, + reason: + "the gate's required-lenses input names no lens and the config has no `review` block in mode " + + "enforce, so the gate requires no lens here (it fails a head only when the lens comments there do " + + "not all read it); lens_start starts only lenses the gate requires, so none: a person names the " + + "lenses in the caller workflow or the config", + }, + ]); } }); @@ -804,11 +1017,7 @@ describe("lens_start plans what the gate reads (fix round A+B)", () => { }); it("an entry lens_start cannot start again: refused, and a person is told the way out", () => { - const noHeader = { - body: `Looks fine.\n${report("code", A).body}`, - edited: false, - hidden: false, - }; + const noHeader = { ...report("code", A), body: `Looks fine.\n${report("code", A).body}` }; const stuck = planLensStart(input({ pullList: [pull(1, { posts: [noHeader] })] })); assert.deepStrictEqual(stuck.starts, []); assert.include(stuck.refused[0]!.reason, "a comment that reads nothing"); @@ -903,13 +1112,29 @@ describe("lens_start plans what the gate reads (fix round A+B)", () => { assert.strictEqual(second.starts[0]!.attempt, 2); assert.strictEqual(second.starts[0]!.requestId, `${child!.requestId}/again-2`); assert.deepStrictEqual(second.starts[0]!.replaces, [child!.requestId]); - assert.isTrue( - second.notes.some((n) => n.includes("ended without the read") && n.includes("attempt 2")), + assert.include( + second.notes, + `lens code for #1: 1 earlier child of it ended at this head with no read the gate counts (the last: ` + + `${child!.requestId}), so it starts again as attempt 2`, ); const third = planLensStart( input({ children: earlier(false, child!.requestId, second.starts[0]!.requestId) }), ); assert.strictEqual(third.starts[0]!.attempt, 3); + // Stops half-way again and again: after the cap of attempts a person looks, nothing restarts forever. + const ids = [child!.requestId, second.starts[0]!.requestId, third.starts[0]!.requestId]; + assert.strictEqual(LENS_START_MAX_ATTEMPTS, 3); + const capped = planLensStart(input({ children: earlier(false, ...ids) })); + assert.deepStrictEqual(capped.starts, []); + assert.deepStrictEqual(capped.refused, [ + { + pr: 1, + reason: + "lens code is not started: 3 of its children ended with no read the gate counts at this head (no " + + `report, or one edited, hidden or unread since; the last: ${ids[2]}); a person looks at why before it ` + + "starts again, and a new head starts it afresh", + }, + ]); // A second call while the child still runs: that child, never a duplicate. const busy = planLensStart(input({ children: earlier(true, child!.requestId) })); assert.deepStrictEqual(busy.starts, []); @@ -935,6 +1160,261 @@ describe("lens_start plans what the gate reads (fix round A+B)", () => { assert.deepStrictEqual(lensesOf(moved), ["code"]); }); + it("the attempt cap counts per lens, pull request and head: no other batch starts a capped lens again", () => { + const dead = (reads: Array<[number, string]>, attempt: number) => { + const prs = reads.map(([number, head]) => ({ number, head })); + return { + requestId: lensRequestId(REPO, "code", prs, attempt), + key: "code", + prs, + running: false, + }; + }; + const shape = (plan: LensStartPlan) => ({ + starts: plan.starts.map((s) => [s.prs.map((r) => r.number), s.attempt]), + refused: plan.refused.map((r) => r.pr), + }); + const alone = [1, 2, 3].map((n) => dead([[1, A]], n)); + // #1 capped alone, then named with #2: #1 is refused, #2 starts on its own. + const withTwo = planLensStart( + input({ pullList: [pull(1), pull(2, { head: B })], children: alone }), + ); + assert.deepStrictEqual(shape(withTwo), { starts: [[[2], 1]], refused: [1] }); + // #1 capped in [#1, #2] batches, then named with #3. + const pair = [1, 2, 3].map((n) => + dead( + [ + [1, A], + [2, B], + ], + n, + ), + ); + const withThree = planLensStart( + input({ pullList: [pull(1), pull(3, { head: C })], children: pair }), + ); + assert.deepStrictEqual(shape(withThree), { starts: [[[3], 1]], refused: [1] }); + // The batch shrinks after a partial post: #2 was read, so #1 is planned alone, and it is capped all the same. + const shrunk = planLensStart( + input({ + pullList: [pull(1), pull(2, { head: B, posts: [report("code", B)] })], + children: pair, + }), + ); + assert.deepStrictEqual(shape(shrunk), { starts: [], refused: [1] }); + assert.deepStrictEqual(shrunk.alreadyRead, [{ pr: 2, lens: "code" }]); + // One dead batch child counts for each of its pull requests: #1 alone is attempt 2 and replaces it. + const once = planLensStart(input({ children: [pair[0]!] })); + assert.deepStrictEqual(shape(once), { starts: [[[1], 2]], refused: [] }); + assert.deepStrictEqual(once.starts[0]!.replaces, [pair[0]!.requestId]); + assert.strictEqual( + once.starts[0]!.requestId, + lensRequestId(REPO, "code", [{ number: 1, head: A }], 2), + ); + // A new head starts afresh; another lens has its own count. + assert.deepStrictEqual( + shape(planLensStart(input({ pullList: [pull(1, { head: D })], children: alone }))), + { + starts: [[[1], 1]], + refused: [], + }, + ); + // A lost record (attempt 1's) never plans an id that already ended: attempts 2 and 3 are known, so 4 starts. + const lost = planLensStart(input({ children: alone.slice(1) })); + assert.deepStrictEqual(shape(lost), { starts: [[[1], 4]], refused: [] }); + assert.notInclude( + alone.map((c) => c.requestId), + lost.starts[0]!.requestId, + ); + }); + + it("the caller stores each child's lens and pull requests: a hashed long id is still found again", () => { + const long = `code-${"x".repeat(240)}`; + const first = planLensStart(input({ review: null, required: [long] })); + const [child] = first.starts; + assert.match(child!.requestId, /^lens\/[0-9a-f]{64}$/u); + assert.deepStrictEqual(earlierChild(child!, true), { + requestId: child!.requestId, + key: lensKey(long), + prs: [{ number: 1, head: A }], + running: true, + }); + const busy = planLensStart( + input({ review: null, required: [long], children: [earlierChild(child!, true)] }), + ); + assert.deepStrictEqual(busy.starts, []); + assert.lengthOf(busy.running, 1); + const again = planLensStart( + input({ review: null, required: [long], children: [earlierChild(child!, false)] }), + ); + assert.strictEqual(again.starts[0]!.attempt, 2); + assert.deepStrictEqual(again.starts[0]!.replaces, [child!.requestId]); + }); + + it("past the round cap a head the gate already passes needs no person, unless the gate judges rounds", () => { + // Round 5 by its marker, and every lens already read this head. + const posts = [report("code r5", A)]; + const fallback = planLensStart( + input({ review: null, required: ["code"], pullList: [pull(1, { posts })] }), + ); + assert.deepStrictEqual(fallback.refused, []); + assert.deepStrictEqual(fallback.starts, []); + assert.deepStrictEqual(fallback.alreadyRead, [{ pr: 1, lens: "code" }]); + assert.deepStrictEqual(fallback.notes, [ + "#1: a read of this head would be review round 5, past T3's cap of 4; the gate already passes it and " + + "judges no rounds here, so nothing starts", + ]); + const shadow = planLensStart( + input({ + review: configs["two-critical"]!, + required: ["code"], + pullList: [pull(1, { posts })], + }), + ); + assert.deepStrictEqual(shadow.refused, []); + assert.deepStrictEqual(shadow.starts, []); + // In enforce the gate fails the head past the cap: a person decides. + const enforce = planLensStart(input({ pullList: [pull(1, { posts })] })); + assert.deepStrictEqual(enforce.starts, []); + assert.include(enforce.refused[0]!.reason, "review round 5, past the cap of 4"); + // Past the cap and not yet passing: refused everywhere. + const fresh = planLensStart( + input({ review: null, required: ["code"], pullList: [pull(1, { head: B, posts })] }), + ); + assert.include(fresh.refused[0]!.reason, "past the cap of 4"); + }); + + it("enforce: a report that reads nothing and only a non-person override covers is read again", () => { + const edited = { ...report("code", A), edited: true }; + for (const posts of [ + [edited, override(A)], + [report("code", A.slice(0, 7)), override(A)], + ]) { + const plan = planLensStart(input({ pullList: [pull(1, { posts })] })); + assert.deepStrictEqual(plan.refused, []); + assert.deepStrictEqual(lensesOf(plan), ["code"]); + assert.deepStrictEqual(plan.alreadyRead, []); + // Shadow judges no findings: the override's read stands there. + const shadow = planLensStart( + input({ + review: configs["two-critical"]!, + required: ["code"], + pullList: [pull(1, { posts })], + }), + ); + assert.deepStrictEqual(shadow.starts, []); + } + // A person's override for this head clears it: nothing starts. + const people = { ...basic, override_authors: ["Someone"] }; + const person = planLensStart( + input({ + review: people, + pullList: [pull(1, { posts: [edited, { ...override(A), author: "someone" }] })], + }), + ); + assert.deepStrictEqual(person.starts, []); + assert.deepStrictEqual(person.alreadyRead, [{ pr: 1, lens: "code" }]); + // A listed login's override for another change clears nothing: the agent's newer override still leaves it UNREAD. + const other = planLensStart( + input({ + review: people, + pullList: [ + pull(1, { + head: B, + posts: [ + { ...report("code", B), edited: true }, + { ...override(A), author: "someone" }, + override(B), + ], + }), + ], + }), + ); + assert.deepStrictEqual(lensesOf(other), ["code"]); + // One for the same change (the head is it merged with the base) clears it like one for the head. + const same = planLensStart( + input({ + review: people, + pullList: [ + pull(1, { + head: B, + sameChange: (read) => read === A, + posts: [ + { ...report("code", B), edited: true }, + { ...override(A), author: "someone" }, + ], + }), + ], + }), + ); + assert.deepStrictEqual(lensesOf(same), []); + // Findings not judged (findings: false): the gate fails no UNREAD entry, so the override's read stands. + const unjudged = planLensStart( + input({ + review: { ...basic, findings: false }, + pullList: [pull(1, { posts: [edited, override(A)] })], + }), + ); + assert.deepStrictEqual(unjudged.starts, []); + assert.deepStrictEqual(unjudged.alreadyRead, [{ pr: 1, lens: "code" }]); + }); + + it("enforce: a report of the head with no findings section is read again; the gate fails it until it posts again", () => { + const bare = { + ...report("code", A), + body: `lens: code · reviewer: x · read at: ${A}\nstate: fine`, + }; + const plan = planLensStart(input({ pullList: [pull(1, { posts: [bare] })] })); + assert.deepStrictEqual(lensesOf(plan), ["code"]); + assert.deepStrictEqual(plan.alreadyRead, []); + assert.include( + plan.notes, + "#1: lens code has a newest report with no findings section, so the gate fails this head until it posts " + + "again: it reads the head again", + ); + // Not in shadow or with findings off (the gate judges no findings there), and not once a person cleared it. + for (const review of [ + { ...basic, findings: false }, + { ...basic, mode: "shadow" as const }, + ]) { + const off = planLensStart( + input({ review, required: ["code"], pullList: [pull(1, { posts: [bare] })] }), + ); + assert.deepStrictEqual(off.starts, [], review.mode); + } + const cleared = planLensStart( + input({ + review: { ...basic, override_authors: ["someone"] }, + pullList: [pull(1, { posts: [bare, { ...override(A), author: "someone" }] })], + }), + ); + assert.deepStrictEqual(cleared.starts, []); + }); + + it("shadow says it starts the path lenses the gate does not require, on purpose", () => { + const plan = planLensStart( + input({ + review: configs["two-critical"]!, + required: ["code"], + pullList: [ + pull(1, { + changes: V.cases.find( + (c: { config: string; lenses: string[] }) => + c.config === "two-critical" && c.lenses.some((l) => l !== "code"), + )!.changes, + }), + ], + }), + ); + const extra = lensesOf(plan).filter((l) => l !== "code"); + assert.isAbove(extra.length, 0); + assert.deepStrictEqual(plan.notes, [ + `#1: in shadow the gate requires only its required-lenses input; lens_start also starts ${extra.join(", ")} ` + + "of the path rules on purpose (the trial shadow is for); each costs a child slot and its runner's usage, " + + "Fable usage for a lens that runs on Fable", + ]); + }); + it("heads and repo in any case: one pull request, one id", () => { const twice = planLensStart({ ...input({}), diff --git a/apps/server/src/fork/reviewRules/lensStart.ts b/apps/server/src/fork/reviewRules/lensStart.ts index 60d5eb261251f..9e8322b3d056d 100644 --- a/apps/server/src/fork/reviewRules/lensStart.ts +++ b/apps/server/src/fork/reviewRules/lensStart.ts @@ -9,16 +9,32 @@ import * as Schema from "effect/Schema"; import { type EffectiveReviewRules, type ReviewRunner, reviewLensRunner } from "@t3tools/contracts"; -import { NO_HEADER, lensKey, lensScan, namesALens, type LensPost } from "./lensComment.ts"; +import { + NO_HEADER, + lensEntries, + lensKey, + namesALens, + olderThan, + type LensPost, + type PostAt, +} from "./lensComment.ts"; +import { readFindings } from "./findings.ts"; import { ReviewPlanError, planReview, type ReviewBlock, type ReviewPlan } from "./plan.ts"; +import { PyTextError } from "./pyText.ts"; import { judgeRounds, type Rounds } from "./rounds.ts"; const isPlanError = Schema.is(ReviewPlanError); +const isPyTextError = Schema.is(PyTextError); type OnRules = Extract; /** The most pull requests one call reads. */ export const LENS_START_MAX_PRS = 10; +/** + * The most children one lens gets on one pull request's head, in whatever batches they ran: after this many ended with + * no read the gate counts there, a person looks. + */ +export const LENS_START_MAX_ATTEMPTS = 3; /** The longest request id `delegate_task` takes. */ const REQUEST_ID_MAX = 256; const SHA = /^[0-9a-f]{40}$/u; @@ -63,6 +79,12 @@ export interface LensStartPost extends LensPost { * it in the gate (lens_reads), a person's or not. */ readonly override?: string; + /** + * The login of an override comment's author. An override by a login in the base's `review.override_authors` that + * vouches for this head (`sameChange`) is a person's: it clears the findings of every older entry (head_check + * review_rounds); any other override covers an entry's read but clears nothing. Absent: no person's override. + */ + readonly author?: string; } /** One pull request as the caller read it from GitHub, its head first. */ @@ -79,8 +101,17 @@ export interface LensStartPullRequest { readonly posts: ReadonlyArray; /** A person's override for this head is newer than every lens comment (the gate's `decided`). */ readonly decided?: boolean; - /** What the pull request itself changes at a commit, so a read before a clean base merge still read the head. */ + /** + * For round counting only: what the pull request itself changes at a commit (head_check.own_change), so a read of + * the same change is no new round. Never used for "this lens read the head": an amended or rebased commit has the + * same change but is not the commit read, and the gate fails it. + */ readonly changeOf?: (sha: string) => string; + /** + * The gate's own check that a lens read of `read` reads this head (head_check.same_change): the head is `read`, or + * `read` merged with the base and nothing else (pr_queue.holds). Absent: only the head itself counts. + */ + readonly sameChange?: (read: string) => boolean; } /** What the gate reads at one base branch's tip. */ @@ -93,12 +124,20 @@ export interface LensStartBase { readonly requiredLenses: ReadonlyArray | null; } -/** A lens child started earlier for this repo (T3b reads them by their `lens/` request ids). */ +/** + * A lens child started earlier (`earlierChild`; a long request id is a digest, so it cannot be read back). The caller + * passes every one it stored, as `delegate_task` returned it (a reused id returns a task that may have ended), never + * as planned; the attempt cap counts them per lens, pull request and head, so a lost one allows one more start there. + */ export interface LensStartEarlierChild { readonly requestId: string; readonly key: string; readonly prs: ReadonlyArray<{ readonly number: number; readonly head: string }>; - /** true: still running, so what it reads is returned, not started twice; false: it ended. */ + /** + * true: still running, so what it reads is returned, not started twice; false: it ended. Read from the task's own + * state at each call, not kept from its start: a child that stopped without the caller seeing it is then ended, not + * running for ever (there is no clock here to time one out). + */ readonly running: boolean; } @@ -114,7 +153,10 @@ export interface LensStartInput { readonly prs: ReadonlyArray<{ readonly number: number; readonly head?: string }>; /** What the caller read, by number; a pull request GitHub does not know is absent. */ readonly pulls: ReadonlyMap; - /** The lens children started earlier; absent: none known. */ + /** + * The lens children started earlier; absent: none known. Read them before `pulls`: a child that posts its read and + * ends between the two reads is then seen running (returned) or its read is seen, never neither (a second child). + */ readonly children?: ReadonlyArray; } @@ -129,9 +171,12 @@ export interface LensStartRead { export interface LensStartChild { /** The same lens on the same heads and attempt gives the same id: a second call returns the same task. */ readonly requestId: string; - /** 1, or one more than the newest attempt whose child ended without the read (`replaces`). */ + /** + * 1, or one more than the most children of this lens that ended at one of its heads with no read the gate counts + * (`replaces`), in whatever batches they ran. + */ readonly attempt: number; - /** The ids of earlier attempts that ended without the read; empty on a first attempt. */ + /** The ids of the earlier children of this lens at these heads that ended; empty on a first attempt. */ readonly replaces: ReadonlyArray; /** The lens's name as the config (or the required-lenses input) writes it. */ readonly lens: string; @@ -143,7 +188,7 @@ export interface LensStartChild { } export interface LensStartRefusal { - /** null: the whole call. */ + /** null: the whole call, or a batch child of several pull requests (the reason names them). */ readonly pr: number | null; readonly reason: string; } @@ -187,37 +232,41 @@ export function gateReads( posts: ReadonlyArray, overridePrefix?: string, ): Map { - const entries = new Map(); - let newest: { at: number; sha: string } | null = null; - posts.forEach((post, i) => { - if (post.override !== undefined) { - if (SHA.test(post.override)) newest = { at: i, sha: post.override }; - return; - } - const one = lensScan([{ ...post, where: post.where ?? `post ${i + 1}` }], overridePrefix); - const name = one.history[0]?.[0] ?? null; - for (const [key, [sha]] of Object.entries(one.entries)) { - entries.set(key, { at: i, sha, name: key.startsWith(NO_HEADER) ? null : name }); - } - }); - const over = newest as { at: number; sha: string } | null; + const { entries } = lensEntries(posts, overridePrefix, isOverride); + const over = newestOverride(posts); const reads = new Map(); for (const [key, { at, sha, name }] of entries) { - if (over !== null && at < over.at) reads.set(key, { sha: over.sha, name }); + if (over !== null && olderThan(at, over.at)) reads.set(key, { sha: over.sha, name }); else reads.set(key, { sha: sha !== null && SHA.test(sha) ? sha : null, name }); } return reads; } +const isOverride = (post: LensStartPost) => post.override !== undefined; + +/** The newest override with a full sha (lens_reads: max over [when, index]), and its post; null: none. */ +function newestOverride( + posts: ReadonlyArray, + only: (post: LensStartPost) => boolean = () => true, +): { at: PostAt; sha: string } | null { + let newest: { at: PostAt; sha: string } | null = null; + posts.forEach((post, i) => { + if (post.override === undefined || !SHA.test(post.override) || !only(post)) return; + const at: PostAt = [post.when, i]; + if (newest === null || !olderThan(at, newest.at)) newest = { at, sha: post.override }; + }); + return newest; +} + /** * The lens part of the gate's verdict (head_check.verdict): every required key has an entry, every entry reads one - * full sha, and that sha is the head or the same change. + * full sha, and that sha is the head or holds its change (head_check.same_change, never the own-change hash). */ -function gateReadsPass( +export function gateReadsPass( reads: ReadonlyMap, required: Iterable, head: string, - changeOf: (sha: string) => string = (sha) => sha, + sameChange: (read: string) => boolean = () => false, ): boolean { const keys = [...required]; if (reads.size === 0) return keys.length === 0; @@ -225,7 +274,43 @@ function gateReadsPass( const shas = new Set([...reads.values()].map((r) => r.sha)); if (shas.size !== 1) return false; const [sha] = shas; - return sha !== null && sha !== undefined && (sha === head || changeOf(sha) === changeOf(head)); + return sha !== null && sha !== undefined && (sha === head || sameChange(sha)); +} + +/** What the gate says of a lens whose newest entry fails it until that lens posts again. */ +const UNREAD_SAID = "reads nothing (only an override that is no person's covers it)"; +const NO_SECTION_SAID = "has a newest report with no findings section"; + +/** + * The lens keys whose newest entry the gate fails in enforce with findings on until that lens posts again (or a person + * overrides), however the reads look (head_check.review_rounds, review_judge.judge_rounds), each with what it says: + * UNREAD (no full sha of its own, and an override newer than it covers it), or a REPORT (a full sha) with no finding + * and no findings section. A person's override for this head newer than an entry clears it (CLEARED). + */ +export function postAgainKeys( + posts: ReadonlyArray, + review: ReviewBlock, + head: string, + sameChange: (read: string) => boolean = () => false, + overridePrefix?: string, +): Map { + const people = new Set((review.override_authors ?? []).map((a) => a.toLowerCase())); + const newest = newestOverride(posts); + const person = newestOverride( + posts, + (post) => + people.has((post.author ?? "").toLowerCase()) && + (post.override === head || sameChange(post.override!)), + ); + const again = new Map(); + for (const [key, { at, sha, body }] of lensEntries(posts, overridePrefix, isOverride).entries) { + if ((person !== null && olderThan(at, person.at)) || key.startsWith(NO_HEADER)) continue; + if (sha !== null && SHA.test(sha)) { + const [said, section] = readFindings(body); + if (said.length === 0 && !section) again.set(key, NO_SECTION_SAID); + } else if (newest !== null && olderThan(at, newest.at)) again.set(key, UNREAD_SAID); + } + return again; } /** One lens a base knows how to start: its name, and its prompt (a config path, or a built-in one). */ @@ -295,7 +380,9 @@ function readPull( return { refused: "the gate's required-lenses input names no lens and the config has no `review` block in mode " + - "enforce, so the gate fails every head: a person names the lenses in the caller workflow or the config", + "enforce, so the gate requires no lens here (it fails a head only when the lens comments there do not " + + "all read it); lens_start starts only lenses the gate requires, so none: a person names the lenses in " + + "the caller workflow or the config", }; } const block = review ?? FALLBACK_REVIEW; @@ -310,10 +397,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 } = lensScan( - pull.posts.flatMap((p) => (p.override === undefined ? [p] : [])), - overridePrefix, - ); + const { history } = 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); @@ -372,9 +456,28 @@ function readPull( }; } if (rounds.approach) add(block.rounds.approach_lens); - const changeOf = pull.changeOf ?? ((sha: string) => sha); - const passes = gateReadsPass(reads, required.keys(), head, changeOf); + const sameChange = pull.sameChange ?? (() => false); + // In enforce, with findings judged, the gate fails these until that lens posts again. + const again = + enforce && block.findings + ? postAgainKeys(pull.posts, block, head, sameChange, overridePrefix) + : new Map(); + const passes = again.size === 0 && gateReadsPass(reads, required.keys(), head, sameChange); if (rounds.round > block.rounds.max) { + // The gate judges rounds only in enforce. Elsewhere T3 holds its own cap, and a head the gate already passes + // (its own required lenses: the input) needs no person: nothing more starts. + if (!enforce && gateReadsPass(reads, named.keys(), head, sameChange)) { + return { + read: { number: pull.number, head, round: rounds.round }, + need: [], + done: [...named.values()], + earlier: new Map(), + notes: [ + `#${pull.number}: a read of this head would be review round ${rounds.round}, past T3's cap of ` + + `${block.rounds.max}; the gate already passes it and judges no rounds here, so nothing starts`, + ], + }; + } return { refused: `a read of this head would be review round ${rounds.round}, past the cap of ${block.rounds.max} ` + @@ -389,18 +492,30 @@ function readPull( // Something starts at the head, so every entry that does not name the head itself starts again too. const stuck: string[] = []; for (const [key, name] of required) { - if (reads.get(key)?.sha === head) done.push(name); - else need.push({ key, ...(known.get(key) ?? { ...NO_ENTRY, name }) }); + if (reads.get(key)?.sha === head && !again.has(key)) { + done.push(name); + continue; + } + need.push({ key, ...(known.get(key) ?? { ...NO_ENTRY, name }) }); + if (again.has(key)) { + notes.push( + `#${pull.number}: lens ${name} ${again.get(key)}, so the gate fails this head until it posts again: ` + + "it reads the head again", + ); + } } for (const [key, read] of reads) { - if (required.has(key) || read.sha === head) continue; + if (required.has(key) || (read.sha === head && !again.has(key))) continue; const lens = known.get(key); - const said = read.sha === null ? "reads nothing" : `read ${read.sha}`; + const said = again.get(key) ?? (read.sha === null ? "reads nothing" : `read ${read.sha}`); if (lens !== undefined) { need.push({ key, ...lens }); notes.push( - `#${pull.number}: lens ${lens.name} is no longer required but ${said}, not this head; the gate ` + - "needs every lens comment to name one head, so it reads the head again", + `#${pull.number}: lens ${lens.name} is no longer required but ${said}` + + (again.has(key) + ? ", so the gate fails this head until it posts again" + : ", not this head; the gate needs every lens comment to name one head") + + ", so it reads the head again", ); } else if (read.name === null) { stuck.push(`a comment that reads nothing (${key}): ${NO_HEADER_WAY_OUT}`); @@ -419,6 +534,16 @@ function readPull( }; } } + if (review?.mode === "shadow") { + const extra = need.filter((lens) => !named.has(lens.key)).map((lens) => lens.name); + if (extra.length > 0) { + notes.push( + `#${pull.number}: in shadow the gate requires only its required-lenses input; lens_start also starts ` + + `${extra.join(", ")} of the path rules on purpose (the trial shadow is for); each costs a child slot ` + + "and its runner's usage, Fable usage for a lens that runs on Fable", + ); + } + } const earlier = new Map(); for (const [name, sha] of history) { // A read of this very head that does not count (edited or hidden) is no earlier round. @@ -591,7 +716,21 @@ export function planLensStart(input: LensStartInput): LensStartPlan { }); continue; } - const got = readPull(rules, base, input.overridePrefix, pull); + let got: PullNeed; + try { + got = readPull(rules, base, input.overridePrefix, pull); + } catch (error) { + if (!isPyTextError(error)) throw error; + got = { + refused: + error.where === undefined + ? `the config or the gate's required-lenses input at ${pull.base} cannot be read as the gate reads ` + + `it: ${error.message}; a person changes that text` + : `its lens comments cannot be read as the gate reads them: ${error.message}. The gate reads that ` + + `post; lens_start does not, so it starts nothing here until someone edits the post to drop ` + + `${error.codePoints.join(", ")} or deletes it (hiding it is not enough), then calls lens_start again`, + }; + } if ("refused" in got) { refused.push({ pr: number, reason: got.refused }); continue; @@ -630,36 +769,67 @@ export function planLensStart(input: LensStartInput): LensStartPlan { groups.set(id, group); } } - const ended = new Set(children.filter((c) => !c.running).map((c) => c.requestId)); - const starts = [...groups.values()].map(({ key, lens, text, runner, reads }): LensStartChild => { + const ended = children.filter((c) => !c.running); + const endedIds = new Set(ended.map((c) => c.requestId)); + /** The ids of this lens's ended children that read this pull request at this head, each once, in input order. */ + const endedAt = (key: string, number: number, head: string) => [ + ...new Set( + ended + .filter( + (c) => + c.key === key && + c.prs.some((r) => r.number === number && r.head.toLowerCase() === head), + ) + .map((c) => c.requestId), + ), + ]; + const starts: LensStartChild[] = []; + for (const { key, lens, text, runner, reads: all } of groups.values()) { + // The cap is per lens, pull request and head, whatever batch each child ran in: a new batch is no new start. + const reads: typeof all = []; + const replaces = new Set(); + let most = 0; + for (const read of all) { + const ids = endedAt(key, read.number, read.head); + if (ids.length >= LENS_START_MAX_ATTEMPTS) { + refused.push({ + pr: read.number, + reason: + `lens ${lens.name} is not started: ${ids.length} of its children ended with no read the gate counts ` + + `at this head (no report, or one edited, hidden or unread since; the last: ${ids.at(-1)}); a person ` + + "looks at why before it starts again, and a new head starts it afresh", + }); + continue; + } + reads.push(read); + ids.forEach((id) => replaces.add(id)); + most = Math.max(most, ids.length); + } + if (reads.length === 0) continue; const prs = reads.map(({ number, head, round }) => ({ number, head, round })); const which = prs.map((r) => `#${r.number}`).join(" "); - const replaces: string[] = []; - let attempt = 1; - for (;;) { - const id = lensRequestId(input.repo, key, prs, attempt); - if (!ended.has(id)) break; - replaces.push(id); - attempt++; - } + let attempt = most + 1; + // A record the caller lost can leave this attempt's id ended already: a new start never reuses an ended id. + while (endedIds.has(lensRequestId(input.repo, key, prs, attempt))) attempt++; if (attempt > 1) { notes.push( - `lens ${lens.name} for ${which}: the child ${replaces.at(-1)} ended without the read, so it ` + - `starts again as attempt ${attempt}`, + `lens ${lens.name} for ${which}: ${most} earlier ${most === 1 ? "child" : "children"} of it ended at ` + + `${prs.length === 1 ? "this head" : "one of these heads"} with no read the gate counts (the last: ` + + `${[...replaces].at(-1)}), so it starts again as attempt ${attempt}`, ); } - return { + starts.push({ requestId: lensRequestId(input.repo, key, prs, attempt), attempt, - replaces, + replaces: [...replaces], lens: lens.name, key, runner, title: `lens ${lens.name} ${which}`, prompt: lensPrompt(rules, input.repo, lens.name, text, reads), prs, - }; - }); + }); + } return { starts, running: [...running.values()].map(({ requestId, key, prs }) => ({ requestId, key, prs })), @@ -669,6 +839,20 @@ export function planLensStart(input: LensStartInput): LensStartPlan { }; } +/** + * What the caller stores for a child it starts, to pass in again as `LensStartInput.children`: its id, lens key and + * the pull requests it reads (the id alone cannot be read back: a long one is a digest). `running`: false once the + * child ended. + */ +export function earlierChild(child: LensStartChild, running: boolean): LensStartEarlierChild { + return { + requestId: child.requestId, + key: child.key, + prs: child.prs.map(({ number, head }) => ({ number, head })), + running, + }; +} + /** * Just before the children start: the heads GitHub names now (null: the pull request is gone or no * longer open). A child whose pull request moved or closed since the plan is refused whole, as its diff --git a/apps/server/src/fork/reviewRules/plan.ts b/apps/server/src/fork/reviewRules/plan.ts index 24287b7d339cf..100eed068e678 100644 --- a/apps/server/src/fork/reviewRules/plan.ts +++ b/apps/server/src/fork/reviewRules/plan.ts @@ -120,6 +120,8 @@ export function planReview( const paths: string[] = []; const seen = new Set(); for (const [status = "", ...named] of changes) { + // review_judge.parse_name_status takes `status[1:].isdigit()`, which also holds `²` or `٣`; git writes a score in + // ASCII digits only, so this reads every status git writes alike, and refuses (no plan, no lens) the rest. const two = /^[CR][0-9]{1,3}$/u.test(status); if (!two && !/^[ADMT]$/u.test(status)) refuse(`unknown change status ${JSON.stringify(status)}`); diff --git a/apps/server/src/fork/reviewRules/pyText.ts b/apps/server/src/fork/reviewRules/pyText.ts index 98eacf0ccad79..dc52bb96ac3d7 100644 --- a/apps/server/src/fork/reviewRules/pyText.ts +++ b/apps/server/src/fork/reviewRules/pyText.ts @@ -3,6 +3,9 @@ * 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"; +import * as Schema from "effect/Schema"; + +import { PY_ASSIGNED, PY_UNICODE } from "./pyUnicode.ts"; /** Python's whitespace (str.isspace, re `\s`), as the body of a character class. */ export const WS = @@ -14,6 +17,80 @@ export const ALNUM = "[\\p{L}\\p{N}]"; /** Python re `\b`. */ export const B = `(?:(?<=${W})(?!${W})|(? + range + .split("-") + .map((h) => `\\u{${h}}`) + .join("-"), + ) + .join(""); +const PY_UNASSIGNED = new RegExp(`[^${PY_CLASS}]`, "gu"); +const IS_PY_UNASSIGNED = new RegExp(`^[^${PY_CLASS}]$`, "u"); +const UNASSIGNED = /\p{Cn}/gu; +const IS_UNASSIGNED = /^\p{Cn}$/u; +/** U+0000 to U+036F have been assigned since Unicode 1.1 (U+0370 to U+0377 since 5.1): no drift below them. */ +const PAST_SAFE = /[\u0370-\u{10ffff}]/u; +/** + * What a rule reads of a code point: a letter or number (`\w`, digits), a mark (it can join the one before it in + * NFKC), a format character (`repr`, the findings' invisible-character rule) or a space. + */ +const READ_CLASS = /^[\p{L}\p{N}\p{M}\p{Cf}\p{Z}]$/u; + +/** + * A code point this runtime assigns and the gate's Python does not reads the same on both sides only when no rule reads + * it: Python reads every unassigned code point as no letter, number, mark, format character or space, with no case or + * NFKC mapping, and `repr` escapes it (pyText's `repr` does too). A new symbol, such as an emoji, reads alike. + */ +const readsOtherwise = (ch: string): boolean => + READ_CLASS.test(ch) || + ch.normalize("NFKC") !== ch || + ch.toLowerCase() !== ch || + ch.toUpperCase() !== ch; + +/** Text one of the rules cannot read as Python does: Python's Unicode and this runtime's assign a code point of it differently. */ +export class PyTextError extends Schema.TaggedError()("PyTextError", { + codePoints: Schema.Array(Schema.String), + /** The post that holds them (LensPost.where), when the text is a post's. */ + where: Schema.optional(Schema.String), +}) { + override get message(): string { + return ( + `${this.where === undefined ? "the text" : `the post ${this.where}`} holds ${this.codePoints.join(", ")}, ` + + `which the gate's Python (Unicode ${PY_UNICODE}) and this runtime assign differently, so the two would read ` + + "it differently" + ); + } +} + +/** + * Throws PyTextError when the text holds a code point only one of Python's Unicode (PY_UNICODE) and this runtime's + * assigns, and a rule reads it (readsOtherwise; always when only Python assigns it): `Ᲊ` (Unicode 16) before `major:` + * is a finding in the gate and none here. Code points both assign read alike, except upper case, which no rule reads. + */ +export function pyUnicodeCheck(text: string): void { + if (!PAST_SAFE.test(text)) return; + const drift = new Set(); + for (const [ch] of text.matchAll(PY_UNASSIGNED)) + if (!IS_UNASSIGNED.test(ch) && readsOtherwise(ch)) drift.add(ch.codePointAt(0)!); + for (const [ch] of text.matchAll(UNASSIGNED)) + if (!IS_PY_UNASSIGNED.test(ch)) drift.add(ch.codePointAt(0)!); + if (drift.size === 0) return; + throw new PyTextError({ + codePoints: [...drift] + .toSorted((a, b) => a - b) + .map((u) => `U+${u.toString(16).toUpperCase().padStart(4, "0")}`), + }); +} + +/** Python's sorted() on strings: by code point, not by UTF-16 unit. */ +export 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; +} + /** * A Python pattern source for re.I: Python's case-insensitive `i` also matches `İ` and `ı`, JavaScript's does not * (its `s` and `k` already match `ſ` and the Kelvin sign). @@ -80,7 +157,7 @@ export function digitValue(ch: string): number { return n % 10; } -/** repr(text) of a Python str. */ +/** repr(text) of a Python str: what the gate's Python leaves unassigned is not printable there, so it is escaped. */ export function repr(text: string): string { const quote = text.includes("'") && !text.includes('"') ? '"' : "'"; let out = ""; @@ -89,7 +166,10 @@ export function repr(text: string): string { 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)) { + else if ( + ch !== " " && + (/[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Z}]/u.test(ch) || IS_PY_UNASSIGNED.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; diff --git a/apps/server/src/fork/reviewRules/pyUnicode.ts b/apps/server/src/fork/reviewRules/pyUnicode.ts new file mode 100644 index 0000000000000..41d9b70a609b0 --- /dev/null +++ b/apps/server/src/fork/reviewRules/pyUnicode.ts @@ -0,0 +1,85 @@ +/** + * The Unicode version of the gate's Python (3.12; `unicodedata.unidata_version`) and the code points it assigns + * (every general category but Cn), as hex ranges `start-end` or single code points, in order. The shared vectors hold + * the same table (`unicode`): the Python side checks it against its unicodedata, this side against this file. + */ +export const PY_UNICODE = "15.0.0"; + +export const PY_ASSIGNED = + "0-377 37a-37f 384-38a 38c 38e-3a1 3a3-52f 531-556 559-58a 58d-58f 591-5c7 5d0-5ea 5ef-5f4 " + + "600-70d 70f-74a 74d-7b1 7c0-7fa 7fd-82d 830-83e 840-85b 85e 860-86a 870-88e 890-891 898-983 " + + "985-98c 98f-990 993-9a8 9aa-9b0 9b2 9b6-9b9 9bc-9c4 9c7-9c8 9cb-9ce 9d7 9dc-9dd 9df-9e3 9e6-9fe " + + "a01-a03 a05-a0a a0f-a10 a13-a28 a2a-a30 a32-a33 a35-a36 a38-a39 a3c a3e-a42 a47-a48 a4b-a4d a51 " + + "a59-a5c a5e a66-a76 a81-a83 a85-a8d a8f-a91 a93-aa8 aaa-ab0 ab2-ab3 ab5-ab9 abc-ac5 ac7-ac9 " + + "acb-acd ad0 ae0-ae3 ae6-af1 af9-aff b01-b03 b05-b0c b0f-b10 b13-b28 b2a-b30 b32-b33 b35-b39 " + + "b3c-b44 b47-b48 b4b-b4d b55-b57 b5c-b5d b5f-b63 b66-b77 b82-b83 b85-b8a b8e-b90 b92-b95 b99-b9a " + + "b9c b9e-b9f ba3-ba4 ba8-baa bae-bb9 bbe-bc2 bc6-bc8 bca-bcd bd0 bd7 be6-bfa c00-c0c c0e-c10 " + + "c12-c28 c2a-c39 c3c-c44 c46-c48 c4a-c4d c55-c56 c58-c5a c5d c60-c63 c66-c6f c77-c8c c8e-c90 " + + "c92-ca8 caa-cb3 cb5-cb9 cbc-cc4 cc6-cc8 cca-ccd cd5-cd6 cdd-cde ce0-ce3 ce6-cef cf1-cf3 d00-d0c " + + "d0e-d10 d12-d44 d46-d48 d4a-d4f d54-d63 d66-d7f d81-d83 d85-d96 d9a-db1 db3-dbb dbd dc0-dc6 dca " + + "dcf-dd4 dd6 dd8-ddf de6-def df2-df4 e01-e3a e3f-e5b e81-e82 e84 e86-e8a e8c-ea3 ea5 ea7-ebd " + + "ec0-ec4 ec6 ec8-ece ed0-ed9 edc-edf f00-f47 f49-f6c f71-f97 f99-fbc fbe-fcc fce-fda 1000-10c5 " + + "10c7 10cd 10d0-1248 124a-124d 1250-1256 1258 125a-125d 1260-1288 128a-128d 1290-12b0 12b2-12b5 " + + "12b8-12be 12c0 12c2-12c5 12c8-12d6 12d8-1310 1312-1315 1318-135a 135d-137c 1380-1399 13a0-13f5 " + + "13f8-13fd 1400-169c 16a0-16f8 1700-1715 171f-1736 1740-1753 1760-176c 176e-1770 1772-1773 " + + "1780-17dd 17e0-17e9 17f0-17f9 1800-1819 1820-1878 1880-18aa 18b0-18f5 1900-191e 1920-192b " + + "1930-193b 1940 1944-196d 1970-1974 1980-19ab 19b0-19c9 19d0-19da 19de-1a1b 1a1e-1a5e 1a60-1a7c " + + "1a7f-1a89 1a90-1a99 1aa0-1aad 1ab0-1ace 1b00-1b4c 1b50-1b7e 1b80-1bf3 1bfc-1c37 1c3b-1c49 " + + "1c4d-1c88 1c90-1cba 1cbd-1cc7 1cd0-1cfa 1d00-1f15 1f18-1f1d 1f20-1f45 1f48-1f4d 1f50-1f57 1f59 " + + "1f5b 1f5d 1f5f-1f7d 1f80-1fb4 1fb6-1fc4 1fc6-1fd3 1fd6-1fdb 1fdd-1fef 1ff2-1ff4 1ff6-1ffe " + + "2000-2064 2066-2071 2074-208e 2090-209c 20a0-20c0 20d0-20f0 2100-218b 2190-2426 2440-244a " + + "2460-2b73 2b76-2b95 2b97-2cf3 2cf9-2d25 2d27 2d2d 2d30-2d67 2d6f-2d70 2d7f-2d96 2da0-2da6 " + + "2da8-2dae 2db0-2db6 2db8-2dbe 2dc0-2dc6 2dc8-2dce 2dd0-2dd6 2dd8-2dde 2de0-2e5d 2e80-2e99 " + + "2e9b-2ef3 2f00-2fd5 2ff0-2ffb 3000-303f 3041-3096 3099-30ff 3105-312f 3131-318e 3190-31e3 " + + "31f0-321e 3220-a48c a490-a4c6 a4d0-a62b a640-a6f7 a700-a7ca a7d0-a7d1 a7d3 a7d5-a7d9 a7f2-a82c " + + "a830-a839 a840-a877 a880-a8c5 a8ce-a8d9 a8e0-a953 a95f-a97c a980-a9cd a9cf-a9d9 a9de-a9fe " + + "aa00-aa36 aa40-aa4d aa50-aa59 aa5c-aac2 aadb-aaf6 ab01-ab06 ab09-ab0e ab11-ab16 ab20-ab26 " + + "ab28-ab2e ab30-ab6b ab70-abed abf0-abf9 ac00-d7a3 d7b0-d7c6 d7cb-d7fb d800-fa6d fa70-fad9 " + + "fb00-fb06 fb13-fb17 fb1d-fb36 fb38-fb3c fb3e fb40-fb41 fb43-fb44 fb46-fbc2 fbd3-fd8f fd92-fdc7 " + + "fdcf fdf0-fe19 fe20-fe52 fe54-fe66 fe68-fe6b fe70-fe74 fe76-fefc feff ff01-ffbe ffc2-ffc7 " + + "ffca-ffcf ffd2-ffd7 ffda-ffdc ffe0-ffe6 ffe8-ffee fff9-fffd 10000-1000b 1000d-10026 10028-1003a " + + "1003c-1003d 1003f-1004d 10050-1005d 10080-100fa 10100-10102 10107-10133 10137-1018e 10190-1019c " + + "101a0 101d0-101fd 10280-1029c 102a0-102d0 102e0-102fb 10300-10323 1032d-1034a 10350-1037a " + + "10380-1039d 1039f-103c3 103c8-103d5 10400-1049d 104a0-104a9 104b0-104d3 104d8-104fb 10500-10527 " + + "10530-10563 1056f-1057a 1057c-1058a 1058c-10592 10594-10595 10597-105a1 105a3-105b1 105b3-105b9 " + + "105bb-105bc 10600-10736 10740-10755 10760-10767 10780-10785 10787-107b0 107b2-107ba 10800-10805 " + + "10808 1080a-10835 10837-10838 1083c 1083f-10855 10857-1089e 108a7-108af 108e0-108f2 108f4-108f5 " + + "108fb-1091b 1091f-10939 1093f 10980-109b7 109bc-109cf 109d2-10a03 10a05-10a06 10a0c-10a13 " + + "10a15-10a17 10a19-10a35 10a38-10a3a 10a3f-10a48 10a50-10a58 10a60-10a9f 10ac0-10ae6 10aeb-10af6 " + + "10b00-10b35 10b39-10b55 10b58-10b72 10b78-10b91 10b99-10b9c 10ba9-10baf 10c00-10c48 10c80-10cb2 " + + "10cc0-10cf2 10cfa-10d27 10d30-10d39 10e60-10e7e 10e80-10ea9 10eab-10ead 10eb0-10eb1 10efd-10f27 " + + "10f30-10f59 10f70-10f89 10fb0-10fcb 10fe0-10ff6 11000-1104d 11052-11075 1107f-110c2 110cd " + + "110d0-110e8 110f0-110f9 11100-11134 11136-11147 11150-11176 11180-111df 111e1-111f4 11200-11211 " + + "11213-11241 11280-11286 11288 1128a-1128d 1128f-1129d 1129f-112a9 112b0-112ea 112f0-112f9 " + + "11300-11303 11305-1130c 1130f-11310 11313-11328 1132a-11330 11332-11333 11335-11339 1133b-11344 " + + "11347-11348 1134b-1134d 11350 11357 1135d-11363 11366-1136c 11370-11374 11400-1145b 1145d-11461 " + + "11480-114c7 114d0-114d9 11580-115b5 115b8-115dd 11600-11644 11650-11659 11660-1166c 11680-116b9 " + + "116c0-116c9 11700-1171a 1171d-1172b 11730-11746 11800-1183b 118a0-118f2 118ff-11906 11909 " + + "1190c-11913 11915-11916 11918-11935 11937-11938 1193b-11946 11950-11959 119a0-119a7 119aa-119d7 " + + "119da-119e4 11a00-11a47 11a50-11aa2 11ab0-11af8 11b00-11b09 11c00-11c08 11c0a-11c36 11c38-11c45 " + + "11c50-11c6c 11c70-11c8f 11c92-11ca7 11ca9-11cb6 11d00-11d06 11d08-11d09 11d0b-11d36 11d3a " + + "11d3c-11d3d 11d3f-11d47 11d50-11d59 11d60-11d65 11d67-11d68 11d6a-11d8e 11d90-11d91 11d93-11d98 " + + "11da0-11da9 11ee0-11ef8 11f00-11f10 11f12-11f3a 11f3e-11f59 11fb0 11fc0-11ff1 11fff-12399 " + + "12400-1246e 12470-12474 12480-12543 12f90-12ff2 13000-13455 14400-14646 16800-16a38 16a40-16a5e " + + "16a60-16a69 16a6e-16abe 16ac0-16ac9 16ad0-16aed 16af0-16af5 16b00-16b45 16b50-16b59 16b5b-16b61 " + + "16b63-16b77 16b7d-16b8f 16e40-16e9a 16f00-16f4a 16f4f-16f87 16f8f-16f9f 16fe0-16fe4 16ff0-16ff1 " + + "17000-187f7 18800-18cd5 18d00-18d08 1aff0-1aff3 1aff5-1affb 1affd-1affe 1b000-1b122 1b132 " + + "1b150-1b152 1b155 1b164-1b167 1b170-1b2fb 1bc00-1bc6a 1bc70-1bc7c 1bc80-1bc88 1bc90-1bc99 " + + "1bc9c-1bca3 1cf00-1cf2d 1cf30-1cf46 1cf50-1cfc3 1d000-1d0f5 1d100-1d126 1d129-1d1ea 1d200-1d245 " + + "1d2c0-1d2d3 1d2e0-1d2f3 1d300-1d356 1d360-1d378 1d400-1d454 1d456-1d49c 1d49e-1d49f 1d4a2 " + + "1d4a5-1d4a6 1d4a9-1d4ac 1d4ae-1d4b9 1d4bb 1d4bd-1d4c3 1d4c5-1d505 1d507-1d50a 1d50d-1d514 " + + "1d516-1d51c 1d51e-1d539 1d53b-1d53e 1d540-1d544 1d546 1d54a-1d550 1d552-1d6a5 1d6a8-1d7cb " + + "1d7ce-1da8b 1da9b-1da9f 1daa1-1daaf 1df00-1df1e 1df25-1df2a 1e000-1e006 1e008-1e018 1e01b-1e021 " + + "1e023-1e024 1e026-1e02a 1e030-1e06d 1e08f 1e100-1e12c 1e130-1e13d 1e140-1e149 1e14e-1e14f " + + "1e290-1e2ae 1e2c0-1e2f9 1e2ff 1e4d0-1e4f9 1e7e0-1e7e6 1e7e8-1e7eb 1e7ed-1e7ee 1e7f0-1e7fe " + + "1e800-1e8c4 1e8c7-1e8d6 1e900-1e94b 1e950-1e959 1e95e-1e95f 1ec71-1ecb4 1ed01-1ed3d 1ee00-1ee03 " + + "1ee05-1ee1f 1ee21-1ee22 1ee24 1ee27 1ee29-1ee32 1ee34-1ee37 1ee39 1ee3b 1ee42 1ee47 1ee49 1ee4b " + + "1ee4d-1ee4f 1ee51-1ee52 1ee54 1ee57 1ee59 1ee5b 1ee5d 1ee5f 1ee61-1ee62 1ee64 1ee67-1ee6a " + + "1ee6c-1ee72 1ee74-1ee77 1ee79-1ee7c 1ee7e 1ee80-1ee89 1ee8b-1ee9b 1eea1-1eea3 1eea5-1eea9 " + + "1eeab-1eebb 1eef0-1eef1 1f000-1f02b 1f030-1f093 1f0a0-1f0ae 1f0b1-1f0bf 1f0c1-1f0cf 1f0d1-1f0f5 " + + "1f100-1f1ad 1f1e6-1f202 1f210-1f23b 1f240-1f248 1f250-1f251 1f260-1f265 1f300-1f6d7 1f6dc-1f6ec " + + "1f6f0-1f6fc 1f700-1f776 1f77b-1f7d9 1f7e0-1f7eb 1f7f0 1f800-1f80b 1f810-1f847 1f850-1f859 " + + "1f860-1f887 1f890-1f8ad 1f8b0-1f8b1 1f900-1fa53 1fa60-1fa6d 1fa70-1fa7c 1fa80-1fa88 1fa90-1fabd " + + "1fabf-1fac5 1face-1fadb 1fae0-1fae8 1faf0-1faf8 1fb00-1fb92 1fb94-1fbca 1fbf0-1fbf9 20000-2a6df " + + "2a700-2b739 2b740-2b81d 2b820-2cea1 2ceb0-2ebe0 2f800-2fa1d 30000-3134a 31350-323af e0001 " + + "e0020-e007f e0100-e01ef f0000-ffffd 100000-10fffd"; diff --git a/apps/server/src/fork/reviewRules/reviewRules.test.ts b/apps/server/src/fork/reviewRules/reviewRules.test.ts index ccba74f148b5c..78704c48ac98c 100644 --- a/apps/server/src/fork/reviewRules/reviewRules.test.ts +++ b/apps/server/src/fork/reviewRules/reviewRules.test.ts @@ -17,14 +17,14 @@ import { lensScan, } from "./lensComment.ts"; import { ReviewPlanError, globMatches, planReview, type ReviewBlock } from "./plan.ts"; -import { repr, splitlines } from "./pyText.ts"; +import { PyTextError } from "./pyText.ts"; +import { PY_ASSIGNED, PY_UNICODE } from "./pyUnicode.ts"; +import { vectorPosts } from "./vectors.testkit.ts"; import { CLEARED, - LOOSE, REPORT, judgeRounds, requiredLenses, - roundMarker, roundsText, type EntryHow, } from "./rounds.ts"; @@ -48,6 +48,11 @@ const FIELDS: Record | null> = { cases: ["name", "config", "changes", "weight", "lenses", "hits", "protected"], findings: ["name", "group", "body", "findings", "section"], scans: ["name", "posts", "history", "entries"], + linear: ["name", "fn", "parts", "expect", "ms"], + py_unicode: null, + unicode: ["name", "body", "findings", "section", "unassigned", "refused"], + // Run by lensStart.test.ts: lens_start's copy of lens_reads, review_rounds and verdict. + reads: ["name", "posts", "head", "same", "override_authors", "required", "expect"], rounds: [ "name", "config", @@ -87,17 +92,7 @@ function replayRound(v: any) { }; } -// 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); +const scan = (v: any) => lensScan(vectorPosts(v.posts), V.override_prefix); describe("the shared vectors", () => { it("runs every section and every field, each vector name once", () => { @@ -158,6 +153,56 @@ describe("the shared vectors", () => { for (const r of V.rounds) assert.deepStrictEqual(replayRound(r), r.expect, r.name); }); + // Each with its own time bound: the server's test timeout is 120 s, so a slow but not hanging path would pass it. + it("every linear-time vector, in its time", () => { + assert.isAtLeast(V.linear.length, 17); + const fns: Record unknown> = { + read_findings: (body) => readFindings(body), + lens_problem: (body) => lensProblem(body, V.override_prefix), + }; + for (const v of V.linear) { + const body = (v.parts as Array<[string, number]>).map(([text, n]) => text.repeat(n)).join(""); + assert.property(fns, v.fn, v.name); + // 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(); + const got = fns[v.fn]!(body); + // oxlint-disable-next-line t3code/no-wall-clock-in-tests -- the same bound + assert.isBelow(performance.now() - t, v.ms, v.name); + assert.deepStrictEqual(got, v.expect, v.name); + } + }); + + it("the gate's Unicode table, and text whose code points this runtime assigns otherwise is refused", () => { + assert.deepStrictEqual( + [PY_UNICODE, PY_ASSIGNED], + [V.py_unicode.version, V.py_unicode.assigned], + ); + assert.isAtLeast(V.unicode.length, 3); + let refused = 0; + for (const v of V.unicode) { + // Unassigned in the gate's Unicode and assigned here as a letter, number, mark, format character or space: those + // read differently. A new symbol (an emoji) reads alike. + const drift = (v.refused as string[]).filter( + (u) => !/^\p{Cn}$/u.test(String.fromCodePoint(Number.parseInt(u.slice(2), 16))), + ); + if (drift.length === 0) { + assert.deepStrictEqual(readFindings(v.body), [v.findings, v.section], v.name); + continue; + } + refused++; + for (const read of [readFindings, lensProblem, lensHeader, lensKey, fold]) { + assert.throws(() => read(v.body), PyTextError, undefined, `${v.name}: ${read.name}`); + try { + read(v.body); + } catch (error) { + assert.deepStrictEqual((error as PyTextError).codePoints, drift, v.name); + } + } + } + // This runtime's Unicode is newer than 15.0 (Node 24: 16 or later), so the new letter is refused. + assert.isAtLeast(refused, 1); + }); + it("every recorded lens_header and lens_key call of the gate's corpus", () => { const fns: Record unknown> = { lens_header: (body: string) => lensHeader(body), @@ -301,101 +346,4 @@ describe("the T3 side's own edges", () => { ); 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 index 2cd40418dbfdf..1c9ed04e5f7be 100644 --- a/apps/server/src/fork/reviewRules/rounds.ts +++ b/apps/server/src/fork/reviewRules/rounds.ts @@ -5,13 +5,13 @@ 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"; +import { byCodePoint, 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 LOOSE = "loose"; const UNREAD = "unread"; export const CLEARED = "cleared"; const NOT_JUDGED = "skip"; @@ -22,14 +22,6 @@ export type EntryHow = | 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; diff --git a/apps/server/src/fork/reviewRules/vectors.testkit.ts b/apps/server/src/fork/reviewRules/vectors.testkit.ts new file mode 100644 index 0000000000000..eb9f21b568c70 --- /dev/null +++ b/apps/server/src/fork/reviewRules/vectors.testkit.ts @@ -0,0 +1,49 @@ +/** + * A vector's posts (`scans`, `reads`) as the gate lists them, built as review_judge.test.py's vector_pr() builds them: + * comments, then reviews, then inline comments, each by its `author` (else `someone`), one second apart unless `when`. + * With `overridePrefix`, a valid override comment (lens.Review.override_sha) carries the sha it vouches for. + */ +import type { LensStartPost } from "./lensStart.ts"; + +export interface VectorPost { + readonly body: string; + readonly edited?: boolean; + readonly hidden?: boolean; + readonly kind?: "comment" | "review" | "inline"; + readonly when?: string; + readonly flags?: boolean; + readonly author?: string; +} + +const escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); + +const second = (i: number) => + `2026-01-01T00:${String(Math.floor(i / 60)).padStart(2, "0")}:${String(i % 60).padStart(2, "0")}Z`; + +export function vectorPosts( + posts: ReadonlyArray, + overridePrefix?: string, +): LensStartPost[] { + const valid = + overridePrefix === undefined + ? null + : new RegExp(`^${escape(overridePrefix)} ([0-9a-f]{40}):`, "u"); + const listed = posts.map((p, i) => { + const when = p.when ?? second(i); + const author = p.author ?? "someone"; + const unread = p.kind === "review" && p.flags === false; + const sha = !p.edited && !p.hidden && !unread ? valid?.exec(p.body)?.[1] : undefined; + const post: LensStartPost = { + body: p.body, + edited: p.edited ?? false, + hidden: p.hidden ?? false, + where: `by ${author} at ${when || "?"}`, + when, + author, + ...(unread ? { unread: true } : {}), + ...(sha === undefined ? {} : { override: sha }), + }; + return { post, rank: p.kind === "review" ? 1 : p.kind === "inline" ? 2 : 0 }; + }); + return listed.toSorted((a, b) => a.rank - b.rank).map(({ post }) => post); +} diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index ea2b377c8e92a..f097feeba817b 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -157,15 +157,24 @@ whole). Then (`review_judge.py`, `review_glob.py`): `review.vectors.json` holds the shared cases (globs, rule sets, changed paths with 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 +findings read in them; lens comment scans; review rounds; what the head check +reads of a pull request's lens posts and overrides at a head (`lens_reads`, +`review_rounds`' lenses that must post again, the verdict), which T3's +`lens_start` reads the same way; bodies each rule must read in linear time, +with a time bound; the gate's Unicode version and the code points it assigns, +and text whose code points T3's newer Unicode assigns otherwise, which T3 +refuses rather than reads another way when a rule reads them). 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 +`judge_rounds`, `lens.Review.lens_scan` the way `review_judge.test.py`'s +`scan()` posts it, with `override_prefix`, or its `replay_reads()`: a post is a +comment, or a `review` or an `inline` review comment, with its own `when` and, +for a review, `flags` false when its flags were not read), 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. diff --git a/fork-ci/actions/pr-queue/review.vectors.json b/fork-ci/actions/pr-queue/review.vectors.json index 6a065e72e39dc..5cd0c50ce82a0 100644 --- a/fork-ci/actions/pr-queue/review.vectors.json +++ b/fork-ci/actions/pr-queue/review.vectors.json @@ -1,5 +1,5 @@ { - "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a post that only looks like a report is a `comment without a first-line lens header` entry that reads nothing). `rounds`: review_judge.judge_rounds on a history, each lens key's newest entry [how, body], `decided`, and `changes` (sha -> what the pull request changes at it; a sha not listed is its own change). Every section is run by both sides: a test fails if one side meets a section or a vector it does not run. How a vector is made: README.md, \"Review rules\".", + "about": "Shared test vectors of the review rules (README.md, \"Review rules\"). The Python tests (review_glob.test.py, review_judge.test.py) read this file, and the TypeScript side reads the same file: a change to the matching or the judge that updates one side only fails the other side's tests. Paths are made up. `globs`: [glob, path, matches]. `cases`: a config from `configs` (a whole `review` block, which must parse), the changed paths as `git diff --name-status -M` prints them ([status, path] or [R|C, old, new]), and the expected weight, required lenses (in order), rules hit (in rule order) and protected paths (in diff order). The config file is `config_path`. `findings`: a lens report body and what review_judge.read_findings reads in it ([kind, line] of each blocker or major, and whether it has a findings section); `group` says which rule it shows. `scans`: counted posts (by the lens author association, in order, one second apart, `edited` and `hidden` as GitHub records them) and what lens.Review.lens_scan reads with `override_prefix` (the history of [name, sha] and each lens key's newest [sha, why]; a 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\".", "config_path": ".github/pr-queue.json", "override_prefix": "override for head", "globs": [ @@ -1479,6 +1479,76 @@ "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none �", "findings": [], "section": true + }, + { + "name": "re.I reads the dotted capital I as an i: a blocker label", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none\nblockİng: x", + "findings": [["blocker", "blockİng: x"]], + "section": true + }, + { + "name": "a letter after not safe is part of the word: no verdict", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none\nverdict: not safeé", + "findings": [], + "section": true + }, + { + "name": "a sign after not safe ends the word: a NOT SAFE verdict", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none\nverdict: not safe!", + "findings": [["blocker", "the report says NOT SAFE: verdict: not safe!"]], + "section": true + }, + { + "name": "a heading with nothing under it before the next heading", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\n### Major\n## Next section\nnone", + "findings": [["major", "Major (nothing under it)"]], + "section": true + }, + { + "name": "an upper-case label", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nMAJOR: x", + "findings": [["major", "MAJOR: x"]], + "section": true + }, + { + "name": "a dotted capital I after the label stays as written", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: İx", + "findings": [["major", "major: İx"]], + "section": true + }, + { + "name": "an HTML character reference and a backslash escape in a label", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor\\: x", + "findings": [["major", "major: x"]], + "section": true + }, + { + "name": "a Cyrillic look-alike letter in a label", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajоr: x", + "findings": [["major", "major: x"]], + "section": true + }, + { + "name": "a line separator ends a line as Python splitlines does", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none
major: x", + "findings": [["major", "major: x"]], + "section": true + }, + { + "name": "a fullwidth label folds to ASCII", + "group": "python-text", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: x", + "findings": [["major", "major: x"]], + "section": true } ], "scans": [ @@ -1939,6 +2009,190 @@ null ] } + }, + { + "name": "a review reads like a comment", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review" + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + } + }, + { + "name": "a review whose flags were not read reads nothing, and is never hidden", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review", + "flags": false, + "hidden": true + }, + { + "body": "Looks fine.\nlens: data · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review", + "flags": false, + "hidden": true + } + ], + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "entries": { + "code": [ + null, + "a review whose edit and hidden flags were not read from GitHub: re-run, or post a new comment" + ], + "comment without a first-line lens header (by someone at 2026-01-01T00:00:01Z, holds a lens header line that is not its first plain line (a later line, a code block, quote or table), starts with 'Looks fine.')": [ + null, + null + ] + } + }, + { + "name": "an edited or hidden review reads nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review", + "edited": true + }, + { + "body": "lens: data · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review", + "hidden": true + } + ], + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["data", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + ], + "entries": { + "code": [null, "edited after posting: post a new comment instead"], + "data": [null, "hidden: post a new comment instead"] + } + }, + { + "name": "the newest post by time wins, not the last one listed", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:09Z" + }, + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "review", + "when": "2026-01-01T00:00:01Z" + } + ], + "history": [ + ["code", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"], + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + ], + "entries": { + "code": ["bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", null] + } + }, + { + "name": "at the same time the later one listed wins: comments, then reviews, then inline comments", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "kind": "inline", + "when": "2026-01-01T00:00:05Z" + }, + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "kind": "review", + "when": "2026-01-01T00:00:05Z" + }, + { + "body": "lens: data · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "kind": "review", + "when": "2026-01-01T00:00:05Z" + }, + { + "body": "lens: data · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:05Z" + } + ], + "history": [ + ["data", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"], + ["data", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"], + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + ], + "entries": { + "data": ["bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", null], + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + } + }, + { + "name": "a post with no time is the oldest, and is named at ?", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:01Z" + }, + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "when": "" + }, + { + "body": "Looks fine.\nlens: data · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "when": "" + } + ], + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null], + "comment without a first-line lens header (by someone at ?, holds a lens header line that is not its first plain line (a later line, a code block, quote or table), starts with 'Looks fine.')": [ + null, + null + ] + } + }, + { + "name": "an older edited post does not hide a newer read", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:09Z" + }, + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nblocker: none\nmajor: none", + "kind": "inline", + "edited": true, + "when": "2026-01-01T00:00:02Z" + } + ], + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "entries": { + "code": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null] + } + }, + { + "name": "a quote and a backslash in a post's start are shown as Python's repr shows them", + "posts": [ + { + "body": "it's \"x\" \\\nread at: 1234567" + } + ], + "history": [], + "entries": { + "comment without a first-line lens header (by someone at 2026-01-01T00:00:00Z, starts with 'it\\'s \"x\" \\\\')": [ + null, + null + ] + } } ], "rounds": [ @@ -2549,6 +2803,774 @@ ], "text": "round 1 of 4; lens code reported a blocker that no later round cleared (issue #99): \"blocker: it's gone\"; fix it, and lens code posts a new report on the fixed head with no blocker or major (`major: none`); or 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); lens data-1 reported a major that no later round cleared (issue #99): 'major: rows lost'; fix it, and lens data-1 posts a new report on the fixed head with no blocker or major (`major: none`); or 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)" } + }, + { + "name": "a round marker in Arabic-Indic digits counts", + "config": "basic", + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code r٣", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "reports": {}, + "expect": { + "round": 3, + "approach": true, + "over_cap": false, + "findings": [], + "problems": [], + "text": "round 3 of 4, approach lens approach required from round 3; no blocker or major open" + } + }, + { + "name": "a round marker in fullwidth digits counts", + "config": "basic", + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code r3", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "reports": {}, + "expect": { + "round": 3, + "approach": true, + "over_cap": false, + "findings": [], + "problems": [], + "text": "round 3 of 4, approach lens approach required from round 3; no blocker or major open" + } + }, + { + "name": "a round marker in bold counts", + "config": "basic", + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code **r12**", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "reports": {}, + "expect": { + "round": 12, + "approach": true, + "over_cap": true, + "findings": [], + "problems": [ + "review round 12 is past the cap of 4 rounds (issue #100): no more rounds; a person decides: close the pull request, or 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). A person's override alone is enough, also for a required approach lens that never posted" + ], + "text": "round 12 of 4, approach lens approach required from round 3; review round 12 is past the cap of 4 rounds (issue #100): no more rounds; a person decides: close the pull request, or 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). A person's override alone is enough, also for a required approach lens that never posted" + } + }, + { + "name": "a two-digit round marker in Arabic-Indic digits counts", + "config": "basic", + "history": [ + ["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + ["code r١٢", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] + ], + "reports": {}, + "expect": { + "round": 12, + "approach": true, + "over_cap": true, + "findings": [], + "problems": [ + "review round 12 is past the cap of 4 rounds (issue #100): no more rounds; a person decides: close the pull request, or 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). A person's override alone is enough, also for a required approach lens that never posted" + ], + "text": "round 12 of 4, approach lens approach required from round 3; review round 12 is past the cap of 4 rounds (issue #100): no more rounds; a person decides: close the pull request, or 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). A person's override alone is enough, also for a required approach lens that never posted" + } + }, + { + "name": "findings are listed by code point, not by UTF-16 unit", + "config": "basic", + "history": [], + "reports": { + "😀": ["loose", "major: x"], + "b": ["loose", "major: y"] + }, + "expect": { + "round": 0, + "approach": false, + "over_cap": false, + "findings": [ + ["b", "major", "major: y"], + ["😀", "major", "major: x"] + ], + "problems": [ + "lens b reported a major that no later round cleared (issue #99): 'major: y'; fix it, and lens b posts a new report on the fixed head with no blocker or major (`major: none`); or 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)", + "lens 😀 reported a major that no later round cleared (issue #99): 'major: x'; fix it, and lens 😀 posts a new report on the fixed head with no blocker or major (`major: none`); or 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)" + ], + "text": "round 0 of 4; lens b reported a major that no later round cleared (issue #99): 'major: y'; fix it, and lens b posts a new report on the fixed head with no blocker or major (`major: none`); or 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); lens 😀 reported a major that no later round cleared (issue #99): 'major: x'; fix it, and lens 😀 posts a new report on the fixed head with no blocker or major (`major: none`); or 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)" + } + }, + { + "name": "a finding line with a symbol new after Unicode 15.0 is shown escaped", + "config": "basic", + "history": [["code", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]], + "reports": { + "code": [ + "report", + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: the 🫩 race" + ] + }, + "expect": { + "round": 1, + "approach": false, + "over_cap": false, + "findings": [["code", "major", "major: the 🫩 race"]], + "problems": [ + "lens code reported a major that no later round cleared (issue #99): 'major: the \\U0001fae9 race'; fix it, and lens code posts a new report on the fixed head with no blocker or major (`major: none`); or 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)" + ], + "text": "round 1 of 4; lens code reported a major that no later round cleared (issue #99): 'major: the \\U0001fae9 race'; fix it, and lens code posts a new report on the fixed head with no blocker or major (`major: none`); or 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)" + } + } + ], + "reads": [ + { + "name": "a report of the head reads it", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "a newer override covers an older report, which is still judged", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "an edited report under an agent's override is UNREAD", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none", + "edited": true + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": ["code"], + "passes": false + } + }, + { + "name": "a person's override for the head clears an UNREAD report", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none", + "edited": true + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked", + "author": "owner-person" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": ["Owner-Person"], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "a person's override for another change clears nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nstate: fine\nblocker: none\nmajor: none", + "edited": true + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked", + "author": "owner-person" + }, + { + "body": "override for head bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: a person looked" + } + ], + "head": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "same": [], + "override_authors": ["owner-person"], + "required": ["code"], + "expect": { + "reads": { + "code": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + }, + "again": ["code"], + "passes": false + } + }, + { + "name": "a person's override for the same change clears it", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nstate: fine\nblocker: none\nmajor: none", + "edited": true + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked", + "author": "owner-person" + } + ], + "head": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "same": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + "override_authors": ["owner-person"], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "the newest override by time covers, not the last one listed", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: cccccccccccccccccccccccccccccccccccccccc\nstate: fine\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:01Z" + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked", + "when": "2026-01-01T00:00:05Z" + }, + { + "body": "override for head bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: a person looked", + "when": "2026-01-01T00:00:03Z", + "kind": "review" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "an override older than the report covers nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nstate: fine\nblocker: none\nmajor: none", + "when": "2026-01-01T00:00:09Z" + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked", + "when": "2026-01-01T00:00:05Z" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + }, + "again": [], + "passes": false + } + }, + { + "name": "a report of the head with no findings section fails until that lens posts again", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": ["code"], + "passes": false + } + }, + { + "name": "two lenses that read different heads", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + }, + { + "body": "lens: data-1 · reviewer: x · read at: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nstate: fine\nblocker: none\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "data-1": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + }, + "again": [], + "passes": false + } + }, + { + "name": "a short sha reads nothing", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaa\nstate: fine\nblocker: none\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": null + }, + "again": [], + "passes": false + } + }, + { + "name": "a read of the same change merged with the base passes", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + } + ], + "head": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "same": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": true + } + }, + { + "name": "a required lens with no post fails", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code", "data-1"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": [], + "passes": false + } + }, + { + "name": "an override with no lens post reads nothing", + "posts": [ + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": [], + "expect": { + "reads": {}, + "again": [], + "passes": true + } + }, + { + "name": "a review whose flags were not read is UNREAD under an agent's override", + "posts": [ + { + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nstate: fine\nblocker: none\nmajor: none", + "kind": "review", + "flags": false + }, + { + "body": "override for head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: a person looked" + } + ], + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "same": [], + "override_authors": [], + "required": ["code"], + "expect": { + "reads": { + "code": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "again": ["code"], + "passes": false + } + } + ], + "linear": [ + { + "name": "major, a long run of spaces, x", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor", 1], + [" ", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "blocker: none, a long run of spaces, x", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none", + 1 + ], + [" ", 200000], + ["x", 1] + ], + "expect": [[["blocker", "blocker: none x"]], false], + "ms": 2000 + }, + { + "name": "a table, then a long run of spaces", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| a | b |\n", + 1 + ], + [" ", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "a table, then a pipe and a long run of spaces", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| a | b |\n|", + 1 + ], + [" ", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "a table, then a rule start and a long run of spaces", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| a | b |\n|-", + 1 + ], + [" ", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "not, a long run of spaces, safe", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nnot", 1], + [" ", 200000], + ["safe", 1] + ], + "expect": [[["blocker", "the report says NOT SAFE: not safe"]], false], + "ms": 2000 + }, + { + "name": "finding:, a long run of spaces, x", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nfinding:", + 1 + ], + [" ", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "major: none, a long run of spaces and tabs, x", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: none", + 1 + ], + [" \t", 100000], + ["x", 1] + ], + "expect": [[["major", "major: none x"]], false], + "ms": 2000 + }, + { + "name": "a wide table row of majors", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| ", 1], + ["major | ", 8000] + ], + "expect": [ + [ + [ + "major", + "major major major major major major major major major major major major major major major major major major major major " + ] + ], + false + ], + "ms": 2000 + }, + { + "name": "a wide table row of majors, then plain cells", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| ", 1], + ["major | ", 4000], + ["x | ", 4000] + ], + "expect": [ + [ + [ + "major", + "major major major major major major major major major major major major major major major major major major major major " + ] + ], + false + ], + "ms": 2000 + }, + { + "name": "a wide table of majors with its rule and a row", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| ", 1], + ["major | ", 3000], + ["\n|", 1], + ["---|", 3000], + ["\n| ", 1], + ["x | ", 3000] + ], + "expect": [ + [ + [ + "major", + "x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x " + ] + ], + false + ], + "ms": 2000 + }, + { + "name": "one major cell, then many empty cells", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| major |", + 1 + ], + [" |", 30000], + [" x |", 1] + ], + "expect": [[["major", "major x"]], false], + "ms": 2000 + }, + { + "name": "a wide table rule", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n|", 1], + ["---|", 16000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "many loose lens lines with a sha", + "fn": "lens_problem", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", 1], + ["lens: x read at 1234567\n", 2000] + ], + "expect": "holds a lens header line 2001 times (post one comment per lens), starts with 'lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaa'", + "ms": 2000 + }, + { + "name": "a long run of quote markers before a header", + "fn": "lens_problem", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", 1], + ["> ", 16000], + ["lens: code · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1] + ], + "expect": "holds a lens header line 2 times (post one comment per lens), starts with 'lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaa'", + "ms": 2000 + }, + { + "name": "a long run of spaces before a read at", + "fn": "lens_problem", + "parts": [ + ["x\n", 1], + [" ", 64000], + ["read at 1234567", 1] + ], + "expect": "starts with 'x'", + "ms": 2000 + }, + { + "name": "not a lens, then many quoted reads", + "fn": "lens_problem", + "parts": [ + ["not a lens: x\n", 1], + ["> read at: 1234567\n", 2000] + ], + "expect": null, + "ms": 2000 + }, + { + "name": "major, a long run of a non-ASCII letter, x", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor", 1], + ["é", 200000], + ["x", 1] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "major: none, a long run of non-ASCII spaces, x", + "fn": "read_findings", + "parts": [ + [ + "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nmajor: none", + 1 + ], + ["  ", 100000], + ["x", 1] + ], + "expect": [[["major", "major: none x"]], false], + "ms": 2000 + }, + { + "name": "a wide table row of majors in another script", + "fn": "read_findings", + "parts": [ + ["lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n| ", 1], + ["major ü | ", 6000] + ], + "expect": [[], false], + "ms": 2000 + }, + { + "name": "a long run of non-ASCII letters and emoji before a read at", + "fn": "lens_problem", + "parts": [ + ["x\n", 1], + ["ÿ😀", 40000], + ["read at 1234567", 1] + ], + "expect": "starts with 'x'", + "ms": 2000 + } + ], + "py_unicode": { + "version": "15.0.0", + "assigned": "0-377 37a-37f 384-38a 38c 38e-3a1 3a3-52f 531-556 559-58a 58d-58f 591-5c7 5d0-5ea 5ef-5f4 600-70d 70f-74a 74d-7b1 7c0-7fa 7fd-82d 830-83e 840-85b 85e 860-86a 870-88e 890-891 898-983 985-98c 98f-990 993-9a8 9aa-9b0 9b2 9b6-9b9 9bc-9c4 9c7-9c8 9cb-9ce 9d7 9dc-9dd 9df-9e3 9e6-9fe a01-a03 a05-a0a a0f-a10 a13-a28 a2a-a30 a32-a33 a35-a36 a38-a39 a3c a3e-a42 a47-a48 a4b-a4d a51 a59-a5c a5e a66-a76 a81-a83 a85-a8d a8f-a91 a93-aa8 aaa-ab0 ab2-ab3 ab5-ab9 abc-ac5 ac7-ac9 acb-acd ad0 ae0-ae3 ae6-af1 af9-aff b01-b03 b05-b0c b0f-b10 b13-b28 b2a-b30 b32-b33 b35-b39 b3c-b44 b47-b48 b4b-b4d b55-b57 b5c-b5d b5f-b63 b66-b77 b82-b83 b85-b8a b8e-b90 b92-b95 b99-b9a b9c b9e-b9f ba3-ba4 ba8-baa bae-bb9 bbe-bc2 bc6-bc8 bca-bcd bd0 bd7 be6-bfa c00-c0c c0e-c10 c12-c28 c2a-c39 c3c-c44 c46-c48 c4a-c4d c55-c56 c58-c5a c5d c60-c63 c66-c6f c77-c8c c8e-c90 c92-ca8 caa-cb3 cb5-cb9 cbc-cc4 cc6-cc8 cca-ccd cd5-cd6 cdd-cde ce0-ce3 ce6-cef cf1-cf3 d00-d0c d0e-d10 d12-d44 d46-d48 d4a-d4f d54-d63 d66-d7f d81-d83 d85-d96 d9a-db1 db3-dbb dbd dc0-dc6 dca dcf-dd4 dd6 dd8-ddf de6-def df2-df4 e01-e3a e3f-e5b e81-e82 e84 e86-e8a e8c-ea3 ea5 ea7-ebd ec0-ec4 ec6 ec8-ece ed0-ed9 edc-edf f00-f47 f49-f6c f71-f97 f99-fbc fbe-fcc fce-fda 1000-10c5 10c7 10cd 10d0-1248 124a-124d 1250-1256 1258 125a-125d 1260-1288 128a-128d 1290-12b0 12b2-12b5 12b8-12be 12c0 12c2-12c5 12c8-12d6 12d8-1310 1312-1315 1318-135a 135d-137c 1380-1399 13a0-13f5 13f8-13fd 1400-169c 16a0-16f8 1700-1715 171f-1736 1740-1753 1760-176c 176e-1770 1772-1773 1780-17dd 17e0-17e9 17f0-17f9 1800-1819 1820-1878 1880-18aa 18b0-18f5 1900-191e 1920-192b 1930-193b 1940 1944-196d 1970-1974 1980-19ab 19b0-19c9 19d0-19da 19de-1a1b 1a1e-1a5e 1a60-1a7c 1a7f-1a89 1a90-1a99 1aa0-1aad 1ab0-1ace 1b00-1b4c 1b50-1b7e 1b80-1bf3 1bfc-1c37 1c3b-1c49 1c4d-1c88 1c90-1cba 1cbd-1cc7 1cd0-1cfa 1d00-1f15 1f18-1f1d 1f20-1f45 1f48-1f4d 1f50-1f57 1f59 1f5b 1f5d 1f5f-1f7d 1f80-1fb4 1fb6-1fc4 1fc6-1fd3 1fd6-1fdb 1fdd-1fef 1ff2-1ff4 1ff6-1ffe 2000-2064 2066-2071 2074-208e 2090-209c 20a0-20c0 20d0-20f0 2100-218b 2190-2426 2440-244a 2460-2b73 2b76-2b95 2b97-2cf3 2cf9-2d25 2d27 2d2d 2d30-2d67 2d6f-2d70 2d7f-2d96 2da0-2da6 2da8-2dae 2db0-2db6 2db8-2dbe 2dc0-2dc6 2dc8-2dce 2dd0-2dd6 2dd8-2dde 2de0-2e5d 2e80-2e99 2e9b-2ef3 2f00-2fd5 2ff0-2ffb 3000-303f 3041-3096 3099-30ff 3105-312f 3131-318e 3190-31e3 31f0-321e 3220-a48c a490-a4c6 a4d0-a62b a640-a6f7 a700-a7ca a7d0-a7d1 a7d3 a7d5-a7d9 a7f2-a82c a830-a839 a840-a877 a880-a8c5 a8ce-a8d9 a8e0-a953 a95f-a97c a980-a9cd a9cf-a9d9 a9de-a9fe aa00-aa36 aa40-aa4d aa50-aa59 aa5c-aac2 aadb-aaf6 ab01-ab06 ab09-ab0e ab11-ab16 ab20-ab26 ab28-ab2e ab30-ab6b ab70-abed abf0-abf9 ac00-d7a3 d7b0-d7c6 d7cb-d7fb d800-fa6d fa70-fad9 fb00-fb06 fb13-fb17 fb1d-fb36 fb38-fb3c fb3e fb40-fb41 fb43-fb44 fb46-fbc2 fbd3-fd8f fd92-fdc7 fdcf fdf0-fe19 fe20-fe52 fe54-fe66 fe68-fe6b fe70-fe74 fe76-fefc feff ff01-ffbe ffc2-ffc7 ffca-ffcf ffd2-ffd7 ffda-ffdc ffe0-ffe6 ffe8-ffee fff9-fffd 10000-1000b 1000d-10026 10028-1003a 1003c-1003d 1003f-1004d 10050-1005d 10080-100fa 10100-10102 10107-10133 10137-1018e 10190-1019c 101a0 101d0-101fd 10280-1029c 102a0-102d0 102e0-102fb 10300-10323 1032d-1034a 10350-1037a 10380-1039d 1039f-103c3 103c8-103d5 10400-1049d 104a0-104a9 104b0-104d3 104d8-104fb 10500-10527 10530-10563 1056f-1057a 1057c-1058a 1058c-10592 10594-10595 10597-105a1 105a3-105b1 105b3-105b9 105bb-105bc 10600-10736 10740-10755 10760-10767 10780-10785 10787-107b0 107b2-107ba 10800-10805 10808 1080a-10835 10837-10838 1083c 1083f-10855 10857-1089e 108a7-108af 108e0-108f2 108f4-108f5 108fb-1091b 1091f-10939 1093f 10980-109b7 109bc-109cf 109d2-10a03 10a05-10a06 10a0c-10a13 10a15-10a17 10a19-10a35 10a38-10a3a 10a3f-10a48 10a50-10a58 10a60-10a9f 10ac0-10ae6 10aeb-10af6 10b00-10b35 10b39-10b55 10b58-10b72 10b78-10b91 10b99-10b9c 10ba9-10baf 10c00-10c48 10c80-10cb2 10cc0-10cf2 10cfa-10d27 10d30-10d39 10e60-10e7e 10e80-10ea9 10eab-10ead 10eb0-10eb1 10efd-10f27 10f30-10f59 10f70-10f89 10fb0-10fcb 10fe0-10ff6 11000-1104d 11052-11075 1107f-110c2 110cd 110d0-110e8 110f0-110f9 11100-11134 11136-11147 11150-11176 11180-111df 111e1-111f4 11200-11211 11213-11241 11280-11286 11288 1128a-1128d 1128f-1129d 1129f-112a9 112b0-112ea 112f0-112f9 11300-11303 11305-1130c 1130f-11310 11313-11328 1132a-11330 11332-11333 11335-11339 1133b-11344 11347-11348 1134b-1134d 11350 11357 1135d-11363 11366-1136c 11370-11374 11400-1145b 1145d-11461 11480-114c7 114d0-114d9 11580-115b5 115b8-115dd 11600-11644 11650-11659 11660-1166c 11680-116b9 116c0-116c9 11700-1171a 1171d-1172b 11730-11746 11800-1183b 118a0-118f2 118ff-11906 11909 1190c-11913 11915-11916 11918-11935 11937-11938 1193b-11946 11950-11959 119a0-119a7 119aa-119d7 119da-119e4 11a00-11a47 11a50-11aa2 11ab0-11af8 11b00-11b09 11c00-11c08 11c0a-11c36 11c38-11c45 11c50-11c6c 11c70-11c8f 11c92-11ca7 11ca9-11cb6 11d00-11d06 11d08-11d09 11d0b-11d36 11d3a 11d3c-11d3d 11d3f-11d47 11d50-11d59 11d60-11d65 11d67-11d68 11d6a-11d8e 11d90-11d91 11d93-11d98 11da0-11da9 11ee0-11ef8 11f00-11f10 11f12-11f3a 11f3e-11f59 11fb0 11fc0-11ff1 11fff-12399 12400-1246e 12470-12474 12480-12543 12f90-12ff2 13000-13455 14400-14646 16800-16a38 16a40-16a5e 16a60-16a69 16a6e-16abe 16ac0-16ac9 16ad0-16aed 16af0-16af5 16b00-16b45 16b50-16b59 16b5b-16b61 16b63-16b77 16b7d-16b8f 16e40-16e9a 16f00-16f4a 16f4f-16f87 16f8f-16f9f 16fe0-16fe4 16ff0-16ff1 17000-187f7 18800-18cd5 18d00-18d08 1aff0-1aff3 1aff5-1affb 1affd-1affe 1b000-1b122 1b132 1b150-1b152 1b155 1b164-1b167 1b170-1b2fb 1bc00-1bc6a 1bc70-1bc7c 1bc80-1bc88 1bc90-1bc99 1bc9c-1bca3 1cf00-1cf2d 1cf30-1cf46 1cf50-1cfc3 1d000-1d0f5 1d100-1d126 1d129-1d1ea 1d200-1d245 1d2c0-1d2d3 1d2e0-1d2f3 1d300-1d356 1d360-1d378 1d400-1d454 1d456-1d49c 1d49e-1d49f 1d4a2 1d4a5-1d4a6 1d4a9-1d4ac 1d4ae-1d4b9 1d4bb 1d4bd-1d4c3 1d4c5-1d505 1d507-1d50a 1d50d-1d514 1d516-1d51c 1d51e-1d539 1d53b-1d53e 1d540-1d544 1d546 1d54a-1d550 1d552-1d6a5 1d6a8-1d7cb 1d7ce-1da8b 1da9b-1da9f 1daa1-1daaf 1df00-1df1e 1df25-1df2a 1e000-1e006 1e008-1e018 1e01b-1e021 1e023-1e024 1e026-1e02a 1e030-1e06d 1e08f 1e100-1e12c 1e130-1e13d 1e140-1e149 1e14e-1e14f 1e290-1e2ae 1e2c0-1e2f9 1e2ff 1e4d0-1e4f9 1e7e0-1e7e6 1e7e8-1e7eb 1e7ed-1e7ee 1e7f0-1e7fe 1e800-1e8c4 1e8c7-1e8d6 1e900-1e94b 1e950-1e959 1e95e-1e95f 1ec71-1ecb4 1ed01-1ed3d 1ee00-1ee03 1ee05-1ee1f 1ee21-1ee22 1ee24 1ee27 1ee29-1ee32 1ee34-1ee37 1ee39 1ee3b 1ee42 1ee47 1ee49 1ee4b 1ee4d-1ee4f 1ee51-1ee52 1ee54 1ee57 1ee59 1ee5b 1ee5d 1ee5f 1ee61-1ee62 1ee64 1ee67-1ee6a 1ee6c-1ee72 1ee74-1ee77 1ee79-1ee7c 1ee7e 1ee80-1ee89 1ee8b-1ee9b 1eea1-1eea3 1eea5-1eea9 1eeab-1eebb 1eef0-1eef1 1f000-1f02b 1f030-1f093 1f0a0-1f0ae 1f0b1-1f0bf 1f0c1-1f0cf 1f0d1-1f0f5 1f100-1f1ad 1f1e6-1f202 1f210-1f23b 1f240-1f248 1f250-1f251 1f260-1f265 1f300-1f6d7 1f6dc-1f6ec 1f6f0-1f6fc 1f700-1f776 1f77b-1f7d9 1f7e0-1f7eb 1f7f0 1f800-1f80b 1f810-1f847 1f850-1f859 1f860-1f887 1f890-1f8ad 1f8b0-1f8b1 1f900-1fa53 1fa60-1fa6d 1fa70-1fa7c 1fa80-1fa88 1fa90-1fabd 1fabf-1fac5 1face-1fadb 1fae0-1fae8 1faf0-1faf8 1fb00-1fb92 1fb94-1fbca 1fbf0-1fbf9 20000-2a6df 2a700-2b739 2b740-2b81d 2b820-2cea1 2ceb0-2ebe0 2f800-2fa1d 30000-3134a 31350-323af e0001 e0020-e007f e0100-e01ef f0000-ffffd 100000-10fffd" + }, + "unicode": [ + { + "name": "a letter new in Unicode 16 before a label", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nᲉmajor: x", + "findings": [["major", "major: x"]], + "section": true, + "unassigned": ["U+1C89"], + "refused": ["U+1C89"] + }, + { + "name": "a code point unassigned in every version", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: x 󠂀", + "findings": [["major", "major: x 󠂀"]], + "section": true, + "unassigned": ["U+E0080"], + "refused": [] + }, + { + "name": "only code points Python assigns", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: İx 😀", + "findings": [["major", "major: İx 😀"]], + "section": true, + "unassigned": [], + "refused": [] + }, + { + "name": "a symbol new in Unicode 16 (an emoji) reads alike", + "body": "lens: code · reviewer: x · read at: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nblocker: none\nmajor: none 🫩", + "findings": [], + "section": true, + "unassigned": ["U+1FAE9"], + "refused": [] } ] } diff --git a/fork-ci/actions/pr-queue/review_judge.test.py b/fork-ci/actions/pr-queue/review_judge.test.py index f3590095f0e3f..95298a994ccaa 100644 --- a/fork-ci/actions/pr-queue/review_judge.test.py +++ b/fork-ci/actions/pr-queue/review_judge.test.py @@ -5,7 +5,7 @@ rest here: reading git's name-status output, and that a rule set the parser would refuse, or a diff line nobody knows, never judges. """ -import dataclasses, json, os, sys, time, unittest +import dataclasses, json, os, re, sys, time, types, unittest, unittest.mock sys.dont_write_bytecode = True # no __pycache__ next to the scripts @@ -15,6 +15,8 @@ import lens # noqa: E402 import review_config as rc # noqa: E402 import review_judge as rj # noqa: E402 +sys.path.insert(0, os.path.join(HERE, '..', 'head-check')) +import head_check # noqa: E402 (the `reads` vectors: lens_reads, review_rounds and verdict, as the gate runs them) with open(os.path.join(HERE, 'review.vectors.json'), encoding='utf-8') as _f: VECTORS = json.load(_f) @@ -213,9 +215,11 @@ def test_every_shared_findings_vector(self): self.assertEqual(section, v['section']) def test_each_rule_keeps_its_vectors(self): # a vector dropped from the file is a rule no longer shown - sizes = {g: len(group(g)) for g in ('finding', 'clean', 'section', 'one-kind', 'one-label', 'mention')} + sizes = {g: len(group(g)) for g in ('finding', 'clean', 'section', 'one-kind', 'one-label', 'mention', 'named', + 'python-text')} self.assertEqual(sizes, {'finding': 58, 'clean': 37, 'section': 9, 'one-kind': 9, 'one-label': 4, - 'mention': 8}) + 'mention': 8, 'named': 8, 'python-text': 10}) + self.assertEqual(sum(sizes.values()), len(FINDINGS)) def test_each_real_finding_format_counts(self): for v in group('finding'): @@ -240,25 +244,6 @@ def test_a_section_needs_a_blocker_and_a_major_label(self): # #740 round 2, A self.assertEqual(len(r.problems), 1) self.assertIn('lens code: its newest report has no findings section', r.problems[0]) - def test_a_long_run_of_spaces_takes_linear_time(self): # #740 round 2: 81-91 s for one 65,000-character line - n = 200_000 - for line in ('major' + ' ' * n + 'x', 'blocker: none' + ' ' * n + 'x', '| a | b |\n' + ' ' * n + 'x', - '| a | b |\n|' + ' ' * n + 'x', '| a | b |\n|-' + ' ' * n + 'x', - 'not' + ' ' * n + 'safe', 'finding:' + ' ' * n + 'x', 'major: none' + ' \t' * (n // 2) + 'x'): - with self.subTest(line[:12]): - start = time.monotonic() - rj.read_findings(HEAD + line) - self.assertLess(time.monotonic() - start, 2) - - def test_a_wide_table_row_takes_linear_time(self): # the old per-cell read: 13 s at 4,000 cells, minutes at 65,536 chars - for text in ('| ' + 'major | ' * 8_000, '| ' + 'major | ' * 4_000 + 'x | ' * 4_000, - '| ' + 'major | ' * 3_000 + '\n|' + '---|' * 3_000 + '\n| ' + 'x | ' * 3_000, - '| major |' + ' |' * 30_000 + ' x |', '|' + '---|' * 16_000 + 'x'): - with self.subTest(text[:12]): # each about one full-size comment (65,536 characters): 0.2-0.5 s here - start = time.monotonic() - rj.read_findings(HEAD + text) - self.assertLess(time.monotonic() - start, 2) - def test_a_table_does_not_go_on_past_a_fence(self): # a fence ends the table, as GitHub renders it table = '| blocker | major |\n|---|---|\n| none | none |\n' self.assertEqual(rj.read_findings(table + '```\ncode\n```\n| a | b |'), ([], True)) @@ -372,8 +357,12 @@ def test_the_same_comments_give_the_same_verdict(self): # runs again: pure # Every section of review.vectors.json, replayed whole: the TypeScript side (apps/server/src/reviewRules) runs the same # sections, and each side fails on a section or a vector field it does not run, so neither can skip one quietly. -SECTIONS = {'about', 'config_path', 'override_prefix', 'globs', 'configs', 'cases', 'findings', 'scans', 'rounds'} -FIELDS = {'cases': {'name', 'config', 'changes', 'weight', 'lenses', 'hits', 'protected'}, +SECTIONS = {'about', 'config_path', 'override_prefix', 'globs', 'configs', 'cases', 'findings', 'scans', 'rounds', + 'reads', 'linear', 'py_unicode', 'unicode'} +FIELDS = {'linear': {'name', 'fn', 'parts', 'expect', 'ms'}, + 'unicode': {'name', 'body', 'findings', 'section', 'unassigned', 'refused'}, + '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'}, 'rounds': {'name', 'config', 'history', 'reports', 'decided', 'changes', 'override_authors', 'findings', @@ -381,12 +370,28 @@ def test_the_same_comments_give_the_same_verdict(self): # runs again: pure SCAN = lens.Review((), VECTORS['override_prefix'], 'OWNER', ('OWNER',)) +def vector_pr(posts): + """The vector's posts as a pull request: each by its `author` (else `someone`), one second apart unless it names its + `when`; a comment by default, else a `review` (its flags read unless `flags` is false) or an `inline` review + comment.""" + pr = {'comments': [], 'reviews': [], lens.REVIEW_FLAGS: {}, lens.REVIEW_COMMENTS: []} + for i, p in enumerate(posts): + when = p.get('when', f'2026-01-01T00:{i // 60:02d}:{i % 60:02d}Z') + post = {'body': p['body'], 'author': {'login': p.get('author', 'someone')}, 'authorAssociation': 'OWNER'} + flags = {'includesCreatedEdit': p.get('edited', False), 'isMinimized': p.get('hidden', False)} + kind = p.get('kind', 'comment') + if kind == 'review': + pr['reviews'].append({**post, 'id': f'R{i}', 'submittedAt': when, + 'includesCreatedEdit': False, 'isMinimized': False}) # gh's defaults, never read + if p.get('flags', True): + pr[lens.REVIEW_FLAGS][f'R{i}'] = flags + else: + pr['comments' if kind == 'comment' else lens.REVIEW_COMMENTS].append({**post, 'createdAt': when, **flags}) + return pr + + def scan(posts): - comments = [{'body': p['body'], 'author': {'login': 'someone'}, 'authorAssociation': 'OWNER', - 'createdAt': f'2026-01-01T00:{i // 60:02d}:{i % 60:02d}Z', - 'includesCreatedEdit': p.get('edited', False), 'isMinimized': p.get('hidden', False)} - for i, p in enumerate(posts)] - found, history = SCAN.lens_scan({'comments': comments, 'reviews': []}) + 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()} @@ -400,6 +405,49 @@ def replay_round(v): 'findings': [list(f) for f in r.findings], 'problems': list(r.problems), 'text': r.text(review)} +class _MergeCommit: + """A checkout of GitHub's merge commit of `head` that knows no history (own_change: each read its own change).""" + holder = 'the checkout merges' + + def __init__(self, head): + self.parents = ('0' * 40, head) + + def merge_parents(self): + return self.parents + + def git(self, *a): + return types.SimpleNamespace(returncode=1, stdout='', stderr='no history here') + + def has(self, sha): + return True + + fetch = has + + +AGAIN_RE = re.compile(r'lens (.+?): its newest report (?:reads nothing|has no findings section)') + + +def replay_reads(v): + """What the gate reads of the lens posts at `head`, under the `basic` rules in enforce with findings judged: + lens.Review.lens_reads (each key's sha), the keys review_rounds fails until that lens posts again (UNREAD, or a + report with no findings section), and whether head_check.verdict and the rounds pass. `same`: the reads that are + the head's change merged with the base (head_check.same_change).""" + head = v['head'] + pr = {**vector_pr(v['posts']), 'isDraft': False, 'headRefOid': head} + rules = dataclasses.replace(CONFIGS['basic'], mode='enforce', findings=True, + override_authors=tuple(v['override_authors'])) + checkout = _MergeCommit(head) + same = lambda _checkout, h, read: (read == h or read in v['same'], 'the same change') # noqa: E731 + with unittest.mock.patch.object(head_check, 'same_change', same): + reads = {k: sha for k, (sha, _, _) in SCAN.lens_reads(pr).items()} + rounds, why = head_check.review_rounds(rules, SCAN, pr, checkout, VECTORS['override_prefix']) + ok, _, _ = head_check.verdict(pr, SCAN, checkout, {lens.lens_key(n): n for n in v['required']}) + if rounds is None: + raise AssertionError(why) + again = sorted(m.group(1) for p in rounds.problems for m in [AGAIN_RE.match(p)] if m) + return {'reads': reads, 'again': again, 'passes': ok and not rounds.problems} + + class SharedVectors(unittest.TestCase): def test_this_side_runs_every_section_and_field(self): self.assertEqual(set(VECTORS), SECTIONS) @@ -409,12 +457,58 @@ def test_this_side_runs_every_section_and_field(self): for v in VECTORS[section]: self.assertLessEqual(set(v), fields, f'{section}: {v["name"]}') + def test_every_linear_vector_in_its_time(self): # #740 round 2: 81-91 s for one 65,000-character line before + for v in VECTORS['linear']: # each its own bound: a slow but not hanging path would pass a test timeout + with self.subTest(v['name']): + body = ''.join(text * times for text, times in v['parts']) + start = time.monotonic() + if v['fn'] == 'read_findings': + said, section = rj.read_findings(body) + got = [[list(f) for f in said], section] + else: + self.assertEqual(v['fn'], 'lens_problem') + got = SCAN.lens_problem({'body': body}) + self.assertLess(time.monotonic() - start, v['ms'] / 1000) + self.assertEqual(got, v['expect']) + + def test_the_unicode_table_is_this_pythons(self): # T3 refuses text whose code points its Unicode assigns otherwise + import unicodedata + u = VECTORS['py_unicode'] + self.assertEqual(u['version'], unicodedata.unidata_version, + 'a new Python reads a new Unicode: regenerate py_unicode and T3\'s pyUnicode.ts together') + ranges, start = [], None + for cp in range(0x110000): + assigned = unicodedata.category(chr(cp)) != 'Cn' + if assigned and start is None: + start = cp + if not assigned and start is not None: + ranges.append((start, cp - 1)) + start = None + if start is not None: + ranges.append((start, 0x10ffff)) + self.assertEqual(u['assigned'], ' '.join(f'{a:x}' if a == b else f'{a:x}-{b:x}' for a, b in ranges)) + for v in VECTORS['unicode']: + with self.subTest(v['name']): + said, section = rj.read_findings(v['body']) + self.assertEqual(([list(f) for f in said], section), (v['findings'], v['section'])) + self.assertEqual(v['unassigned'], + sorted({f'U+{ord(c):04X}' for c in v['body'] if unicodedata.category(c) == 'Cn'})) + # What T3 refuses on a runtime that assigns them (a letter, number, mark, format or space there): a + # subset; the rest (a new symbol) reads alike here and there. + self.assertLessEqual(set(v['refused']), set(v['unassigned'])) + def test_every_scan(self): # same comment twice, edited, hidden, old forms, no comment at all 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'])) + def test_every_reads_vector(self): # lens_start's copy of lens_reads, review_rounds' UNREAD and verdict + self.assertGreaterEqual(len(VECTORS['reads']), 10) + for v in VECTORS['reads']: + with self.subTest(v['name']): + self.assertEqual(replay_reads(v), v['expect']) + def test_every_round(self): self.assertGreaterEqual(len(VECTORS['rounds']), 28) for v in VECTORS['rounds']: