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

Automate a review finding as a lint or test: Boxes 1, 3, 4, 5 are met on the API and page; box 2 is met. #13754

Merged opened this

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

Merged

torque/forge:torque/13747-automate-a-review-finding-as-a-lint-or-t → main 2 commits fork 1 thread · 1 unresolved

  • Merged. torque/13747-automate-a-review-finding-as-a-lint-or-t was merged into main as 64d4a7d.

Review

Sign in to review this change.
3 files changed +74 −1
docs/features/review-repeats.md +2
@@ -9,4 +9,6 @@ Once a reviewer asks for the same thing four times in a week, a rule says it for
99
1010 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.
1111
12 A reviewer's box verdict ("Boxes 1, 3 are met on the API; box 2 is met.") is not a finding either (#13747): every `;`-joined part must be a bare verdict with at most a short parenthetical or an "on/in/by ..." tail. A comma, an imperative, a code span or a path keeps the line, so "Box 3 is not met, add a test." still counts.
13
1214 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 +22 −1
@@ -98,6 +98,27 @@ export const isRoundHeading = (line: string): boolean => {
9898 return bare.length < 80 && !bare.includes("`") && !/[\w-]\/[\w-]|\.(?:ts|js|md|json|css)\b/.test(bare) && !bare.includes(":") && ROUND_HEAD.test(bare);
9999 };
100100
101 const BOX_VERDICT = /^(?:box(?:es)?\s*:?\s*)?\d[\d,\s]*?(?:and\s*\d+\s*)?(?:is|are)\s+(?:not(?:\s+met)?|met)(?:\s*\([^(),;:]{0,40}\))?(?:\s+(?:on|in|by)\s+[^,;:]*)?\.?$/i;
outdated

This pattern accepts any tail without a colon, so "Box 3 is not met, add a test." is dropped as a verdict. Split on ; and require every part to be a bare verdict, and reject a tail containing a comma or an imperative.

102 const ASKS = /\b(?:add|fix|make|write|remove|rename|change|use|update|ensure|drop|move|cover|include|show|replace|require|keep|split|please|should|need|needs|must|missing)\b/i;
103
104 const verdictParts = (bare: string): boolean =>
105 bare.split(/;|\.\s/).map((p) => p.trim()).filter(Boolean).every((p) => BOX_VERDICT.test(p) && !ASKS.test(p));
106
107 /**
108 * Rule "a box verdict is not a finding" (#13747, beside #13197's): a reviewer's line that only
109 * reports which of the issue's Done-when boxes the pull meets, "Boxes 1, 3, 4, 5 are met on the API
110 * and page; box 2 is met.", "Box 3 is not met (screenshots).", says where the pull stands and asks
111 * for nothing. Counted as a finding it flagged reviewers for reporting the verdict, four times in a
112 * week. Under 160 characters, no code or path; "Box 3 is not met: add a test for `x`" is kept.
113 * Every `;`-joined part must be a bare verdict (optional short parenthetical or "on/in/by ..."
114 * tail, no comma, no ask): "Box 3 is not met, add a test." and "Box 2 is not met; the page is
115 * missing." are kept, because a false drop hides the ask from the builder.
116 */
117 export const isBoxVerdict = (line: string): boolean => {
118 const bare = line.replace(/^[\s*_]+|[\s*_]+$/g, "");
119 return bare.length < 160 && !bare.includes("`") && !/[\w-]\/[\w-]|\.(?:ts|js|md|json|css)\b/.test(bare) && verdictParts(bare);
120 };
121
101122 /**
102123 * The findings in one review body: its list items or lines, each a request.
103124 * A line that ends in a colon introduces the list that follows ("Smaller
@@ -109,7 +130,7 @@ export function linesOf(body: string): string[] {
109130 return body
110131 .split("\n")
111132 .map((l) => l.replace(/^\s*(?:[-*]|\d+[.)])\s+/, "").trim())
112 .filter((l) => l.length >= 12 && !isLeadIn(l) && !isCount(l) && !isRoundHeading(l))
133 .filter((l) => l.length >= 12 && !isLeadIn(l) && !isCount(l) && !isRoundHeading(l) && !isBoxVerdict(l))
113134 .slice(0, MAX_LINES)
114135 .map((l) => l.slice(0, MAX_LINE));
115136 }
test/review-repeats.test.ts +50
@@ -254,3 +254,53 @@ describe(RULE, () => {
254254 expect(await dueGroups(app.db, r.value.id, now)).toEqual([]);
255255 });
256256 });
257
258 const BOX_RULE = "a box verdict is not a finding (#13747)";
259
260 describe(BOX_RULE, () => {
261 const verdicts = [
262 "Boxes 1, 3, 4, 5 are met on the API and page; box 2 is met.",
263 "Boxes: 1 and 3 are met; 2 is met on the page only.",
264 "Boxes 1 and 2 are met in substance on the page; box 3 is not (screenshots).",
265 "Boxes: 1 and 2 are met on the wording; 3 is met by the API assertion.",
266 "**Box 3 is not met (screenshots).**",
267 ];
268
269 test("linesOf drops a reviewer's box verdict and keeps a request that starts like one", () => {
270 for (const line of verdicts)
271 if (linesOf(line).length) throw new Error(`${BOX_RULE}: "${line}" reports where the pull stands, not a finding`);
272 expect(linesOf("Boxes 1 and 3 are met.\n- Escape the user name in the page.")).toEqual(["Escape the user name in the page."]);
273 for (const kept of [
274 "Box 3 is not met: add a test for `wordsOf` in the page.",
275 "Boxes are drawn with a border; use space to separate them.",
276 "Box 2 is met only in src/flow/repeats.ts, add the page too.",
277 "Box 3 is not met, add a test for the page.",
278 "Box 2 is not met; the page is missing.",
279 "Box 1 is met; box 3 is not met, add a test.",
280 "Box 3 is not met on the page and the API; add a test for the empty case before this lands, and say so in the description.",
281 ])
282 if (linesOf(kept).join() !== kept) throw new Error(`${BOX_RULE}: "${kept}" is a real ask and must be kept`);
283 });
284
285 test("a long verdict line under the limit is dropped and one over it is kept", () => {
286 const ok = "Boxes 1, 3, 4, 5 are met on the API and page and the preview; box 2 is met in the test message and the page too.";
287 expect(ok.length).toBeLessThan(160);
288 expect(linesOf(ok)).toEqual([]);
289 const long = `${ok.replace(/\.$/, "")}; box 6 is met on ${"the page and ".repeat(8)}the API.`;
290 expect(long.length).toBeGreaterThanOrEqual(160);
291 expect(linesOf(long)).toEqual([long]);
292 });
293
294 test("a week of box verdicts makes no due group", async () => {
295 const r = await createRepo(app, builder, { name: "boxes", visibility: "public" });
296 if (!r.ok) throw new Error(String(r.error));
297 for (const [i, body] of verdicts.entries()) {
298 const pull = createIssue(app.db, { repoId: r.value.id, authorId: builder.id, title: "work", kind: "pull" });
299 if (!pull.ok) throw new Error(pull.error);
300 app.db
301 .query(`INSERT INTO review (id, issue_id, author_id, state, body, created_at) VALUES (?1, ?2, ?3, 'changes_requested', ?4, ?5)`)
302 .run(crypto.randomUUID(), pull.value.id, reviewer.id, body, new Date(now.getTime() - (i + 1) * 3_600_000).toISOString());
303 }
304 expect(await dueGroups(app.db, r.value.id, now)).toEqual([]);
305 });
306 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs