Public: anyone can read this; the crew can change it.
Automate a review finding as a lint or test: Direction: the pipeline items (#6534, #6611, #5276, #3316, #6217, #6428, #1242, #14339
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14287-automate-a-review-finding-as-a-lint-or-t → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +22
−2
src/kernel/direction.ts +7 −1
| @@ -20,6 +20,12 @@ | ||
| 20 | 20 | import type { Change } from "./pin_edits.ts"; |
| 21 | 21 | |
| 22 | 22 | const FEATURE = /^(src\/web\/pages\/[^/]+\.ts|src\/tui\/.+\.ts|docs\/features\/[^/]+\.md)$/; |
| 23 | /** | |
| 24 | * Added, not edited: a new module a feature reaches people by (#14287). Five reviews (#10916, | |
| 25 | * #10979, #11165, #11715, #13992) asked "why does this go ahead of the pipeline" of pulls that | |
| 26 | * added an action, a core module or an HTTP route and no page. | |
| 27 | */ | |
| 28 | const NEW_MODULE = /^src\/(actions|core|http)\/[^/]+\.ts$/; | |
| 23 | 29 | const VENDORED = /^(.*\/)?vendor\//; |
| 24 | 30 | const PIPELINE = /^(scripts\/|src\/flow\/|src\/nightly\/|src\/checks\/|forge\.json$)/; |
| 25 | 31 | /** A feature pull that goes ahead of the pipeline: one page and its how-to. */ |
| @@ -48,7 +54,7 @@ export function directionProblems( | ||
| 48 | 54 | .map((c) => `${VENDORED.exec(c.path)?.[0]}`); |
| 49 | 55 | const features = [ |
| 50 | 56 | ...changes |
| 51 | .filter((c) => FEATURE.test(c.path) && (c.status.startsWith("A") || (lines.get(c.path) ?? 0) >= REDESIGN_LINES)) | |
| 57 | .filter((c) => (FEATURE.test(c.path) || (c.status.startsWith("A") && (NEW_MODULE.test(c.path)))) && (c.status.startsWith("A") || (lines.get(c.path) ?? 0) >= REDESIGN_LINES)) | |
| 52 | 58 | .map((c) => c.path), |
| 53 | 59 | ...new Set(vendored), |
| 54 | 60 | ]; |
test/direction.test.ts +15 −1
| @@ -19,7 +19,7 @@ test("a pipeline change, or a Direction line of 10+ characters, passes", () => { | ||
| 19 | 19 | }); |
| 20 | 20 | |
| 21 | 21 | test("edits and non-feature files are never asked", () => { |
| 22 | expect(directionProblems([ch("M", "src/web/pages/machines.ts"), ch("A", "src/core/x.ts")], [])).toEqual([]); | |
| 22 | expect(directionProblems([ch("M", "src/web/pages/machines.ts"), ch("M", "src/core/x.ts")], [])).toEqual([]); | |
| 23 | 23 | expect(directionProblems([ch("A", "docs/features/x.md")], [])).toHaveLength(1); |
| 24 | 24 | }); |
| 25 | 25 | |
| @@ -64,3 +64,17 @@ test("vendored code added under vendor/ is a feature, once per directory, naming | ||
| 64 | 64 | expect(directionProblems([...vendored, ch("M", "scripts/gate.ts")], [])).toEqual([]); |
| 65 | 65 | expect(directionProblems([ch("M", "src/web/render/vendor/three/README.md")], [])).toEqual([]); |
| 66 | 66 | }); |
| 67 | ||
| 68 | test("a new action, core module or route is a feature too, naming the rule (#14287)", () => { | |
| 69 | for (const path of ["src/actions/statement_csv.ts", "src/core/x.ts", "src/http/statement.ts"]) { | |
| 70 | const out = directionProblems([ch("A", path)], ["Add it"]); | |
| 71 | expect(out).toHaveLength(1); | |
| 72 | expect(out[0]).toContain('rule "pipeline first"'); | |
| 73 | expect(out[0]).toContain(path); | |
| 74 | expect(directionProblems([ch("A", path)], ["Direction: owner asked for it on #7642"])).toEqual([]); | |
| 75 | } | |
| 76 | // Editing one, or editing a script beside a new one, is not asked. | |
| 77 | expect(directionProblems([ch("M", "src/core/x.ts")], [])).toEqual([]); | |
| 78 | expect(directionProblems([ch("A", "src/core/x.ts"), ch("M", "scripts/gate.ts")], [])).toEqual([]); | |
| 79 | expect(directionProblems([ch("A", "src/core/x.ts"), ch("A", "src/checks/y.ts")], [])).toEqual([]); | |
| 80 | }); |
new above
offline
Nit: the predicate is hard to read. NEW_MODULE is only reached when status starts with A, and the trailing (A || lines>=REDESIGN_LINES) is then redundant for it, and the NEW_MODULE test has a stray double paren. Split it: (FEATURE.test(p) && (A || big)) || (A && NEW_MODULE.test(p)). Same behaviour, one line to read.