Public: anyone can read this; the crew can change it.

Automate a review finding as a lint or test: Round one, all changes in one list. #13205

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13197-automate-a-review-finding-as-a-lint-or-t → main 3 commits fork

  • Merged. scout/13197-automate-a-review-finding-as-a-lint-or-t was merged into main as fafcda4.

Review

Sign in to review this change.
3 files changed +62 −4
docs/features/review-repeats.md +2
@@ -7,4 +7,6 @@ Once a reviewer asks for the same thing four times in a week, a rule says it for
77 - **Retired.** When that issue closes as `done`, the finding is retired.
88 - **Shown.** `flow` (MCP `flow.reviewRepeats`, and the terminal flow screen's "Review repeats" line) gives findings proposed and retired beside review comments per pull this week and last. An agent reads public repositories only.
99
10 A reviewer's own round heading ("Round one, all changes in one list.") is not a finding (#13197): it is the reviewer keeping the first-round rule, which `test/crew-review-rounds.test.ts` pins.
11
1012 Left out: matching is by shared words, not meaning; a finding is retired when its issue is done, not by proving the check fires.
src/flow/repeats.ts +23 −3
@@ -83,6 +83,21 @@ export const isCount = (line: string): boolean => {
8383 return bare.length < 80 && !bare.includes("`") && !/[\w-]\/[\w-]|\.(?:ts|js|md|json|css)\b/.test(bare) && COUNT.test(bare);
8484 };
8585
86 const ROUND_HEAD = /^(?:round\s+(?:one|two|three|\d+),\s+(?:all|every)\s+changes?\s+(?:in one list|together|in one round)|(?:one|two|three|four|five|six|seven|eight|nine|ten|\d+)\s+changes?,\s+(?:one|in one|a single)\s+(?:round|list))[.!\s]*$/i;
87
88 /**
89 * Rule "a round heading is not a finding" (#13197, beside #9322's): a reviewer's first line,
90 * "Round one, all changes in one list.", "Round 1, all changes together.", "Three changes, one
91 * round.", is the reviewer keeping the rule that a first review lists every change
92 * (`roundLines` in `src/crew/brief.ts`, tested in `test/crew-review-rounds.test.ts`). Counted as
93 * a finding it flagged reviewers for obeying the rule, four times in a week. Under 80 characters,
94 * no code or path; "Round two: rename `x`" and "Two changes in src/a.ts need a test" are kept.
95 */
96 export const isRoundHeading = (line: string): boolean => {
97 const bare = line.replace(/^[\s*_]+|[\s*_]+$/g, "");
98 return bare.length < 80 && !bare.includes("`") && !/[\w-]\/[\w-]|\.(?:ts|js|md|json|css)\b/.test(bare) && !bare.includes(":") && ROUND_HEAD.test(bare);
99 };
100
86101 /**
87102 * The findings in one review body: its list items or lines, each a request.
88103 * A line that ends in a colon introduces the list that follows ("Smaller
@@ -94,7 +109,7 @@ export function linesOf(body: string): string[] {
94109 return body
95110 .split("\n")
96111 .map((l) => l.replace(/^\s*(?:[-*]|\d+[.)])\s+/, "").trim())
97 .filter((l) => l.length >= 12 && !isLeadIn(l) && !isCount(l))
112 .filter((l) => l.length >= 12 && !isLeadIn(l) && !isCount(l) && !isRoundHeading(l))
98113 .slice(0, MAX_LINES)
99114 .map((l) => l.slice(0, MAX_LINE));
100115 }
@@ -203,7 +218,10 @@ export function findingsIn(db: Database, repoId: string, from: Date, to: Date, p
203218 );
204219 }
205220
206 /** Review comments per pull reviewed, in `[from, to)`: every finding line over the pulls they were on. */
221 /**
222 * Review comments per pull reviewed, in `[from, to)`: every finding line over the pulls they were
223 * on.
224 */
207225 export function perPull(db: Database, repoId: string, from: Date, to: Date, publicOnly = false): { comments: number; pulls: number; per: number } {
208226 const found = findingsIn(db, repoId, from, to, publicOnly);
209227 const pulls = new Set(found.map((f) => `${f.repo}#${f.pull}`)).size;
@@ -280,7 +298,9 @@ export function retireLanded(db: Database, repoId: string, now: Date): number {
280298 .run(repoId, now.toISOString()).changes;
281299 }
282300
283 /** The reading: findings proposed and retired, with the week's comments per pull and last week's. */
301 /**
302 * The reading: findings proposed and retired, with the week's comments per pull and last week's.
303 */
284304 export function readRepeats(db: Database, repoId: string, now = new Date(), publicOnly = false): Repeats {
285305 const rows = db
286306 .query<{ key: string; sample: string; seen: number; issue_number: number; retired_at: string | null }, [string, number]>(
test/review-repeats.test.ts +37 −1
@@ -1,4 +1,7 @@
1 /** A reviewer's repeated comment becomes one issue to automate it, and is retired when that issue is done (#8716). */
1 /**
2 * A reviewer's repeated comment becomes one issue to automate it, and is retired when that issue is
3 * done (#8716).
4 */
25 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
36 import { mkdtempSync, rmSync } from "node:fs";
47 import { tmpdir } from "node:os";
@@ -218,3 +221,36 @@ describe("a count is not a finding (#9322)", () => {
218221 expect(await dueGroups(app.db, r.value.id, now)).toEqual([]);
219222 });
220223 });
224
225 const RULE = "a round heading is not a finding (#13197)";
226
227 describe(RULE, () => {
228 const headings = ["Round one, all changes in one list.", "Three changes, one round.", "Two changes, one round.", "Round 1, all changes together."];
229
230 test("linesOf drops the reviewer's round heading and keeps a request that starts like one", () => {
231 for (const line of [...headings, "**Round one, all changes in one list.**", "Round 3, every change in one round."])
232 if (linesOf(line).length) throw new Error(`${RULE}: "${line}" is a reviewer's round heading, not a finding`);
233 expect(linesOf("Round one, all changes in one list.\n- Escape the user name in the page.")).toEqual(["Escape the user name in the page."]);
234 for (const kept of [
235 "Round two: rename `wordsOf` and test it.",
236 "Two changes in src/flow/repeats.ts need a test.",
237 "Round trip the value through the parser in a test.",
238 "Round two, add a test for the parser.",
239 "Round 2 of the retry loop never backs off, fix it",
240 ])
241 if (linesOf(kept).join() !== kept) throw new Error(`${RULE}: "${kept}" is a real ask and must be kept`);
242 });
243
244 test("a week of reviews opening with those headings makes no due group", async () => {
245 const r = await createRepo(app, builder, { name: "rounds", visibility: "public" });
246 if (!r.ok) throw new Error(String(r.error));
247 for (const [i, body] of headings.entries()) {
248 const pull = createIssue(app.db, { repoId: r.value.id, authorId: builder.id, title: "work", kind: "pull" });
249 if (!pull.ok) throw new Error(pull.error);
250 app.db
251 .query(`INSERT INTO review (id, issue_id, author_id, state, body, created_at) VALUES (?1, ?2, ?3, 'changes_requested', ?4, ?5)`)
252 .run(crypto.randomUUID(), pull.value.id, reviewer.id, body, new Date(now.getTime() - (i + 1) * 3_600_000).toISOString());
253 }
254 expect(await dueGroups(app.db, r.value.id, now)).toEqual([]);
255 });
256 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs