Public: anyone can read this; the crew can change it.
Automate a review finding as a lint or test: **Direction.** This is a feature while the pipeline list is first; the issue ask #14370
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14293-automate-a-review-finding-as-a-lint-or-t → main 1 commit fork
3 files
changed +24
−3
src/kernel/direction.ts +14 −2
| @@ -11,6 +11,9 @@ | ||
| 11 | 11 | * lines of vendored code that no page or screen path caught. A file added |
| 12 | 12 | * under a `vendor/` directory counts once per directory. |
| 13 | 13 | * |
| 14 | * The waiver names the issue it serves, as `#123` (#14293): five reviews (#11151, #12111, #13859, | |
| 15 | * #14116, #14171) asked for it. | |
| 16 | * | |
| 14 | 17 | * Four more reviews (#11289, #11696, #12177, #12307) accepted that waiver and |
| 15 | 18 | * still said "keep it small and single-purpose" (#12363). So the waiver buys |
| 16 | 19 | * a small pull only: at most `MAX_FEATURES` added feature files and |
| @@ -32,6 +35,10 @@ const PIPELINE = /^(scripts\/|src\/flow\/|src\/nightly\/|src\/checks\/|forge\.js | ||
| 32 | 35 | export const MAX_FEATURES = 2; |
| 33 | 36 | export const MAX_FILES = 20; |
| 34 | 37 | const WAIVER = /^Direction:[ \t]*\S[^\n]{9,}/im; |
| 38 | /** | |
| 39 | * The issue the waiver serves, as `#123` (#14293): five reviews said "say which issue it serves". | |
| 40 | */ | |
| 41 | const ISSUE = /#\d+/; | |
| 35 | 42 | |
| 36 | 43 | /** |
| 37 | 44 | * A redesign edits a page rather than adding one (#10380): an existing |
| @@ -60,7 +67,12 @@ export function directionProblems( | ||
| 60 | 67 | ]; |
| 61 | 68 | if (features.length === 0) return []; |
| 62 | 69 | if (changes.some((c) => PIPELINE.test(c.path))) return []; |
| 63 | if (!messages.some((m) => WAIVER.test(m))) return [problem(features)]; | |
| 70 | const waivers = messages.flatMap((m) => m.match(new RegExp(WAIVER.source, "gim")) ?? []); | |
| 71 | if (waivers.length === 0) return [problem(features)]; | |
| 72 | if (!waivers.some((w) => ISSUE.test(w))) | |
| 73 | return [ | |
| 74 | `rule "name the issue": the Direction line says why this feature goes ahead of the pipeline but not which issue it serves; add its number, as "Direction: <why> (#123)"`, | |
| 75 | ]; | |
| 64 | 76 | const big: string[] = []; |
| 65 | 77 | if (features.length > MAX_FEATURES) |
| 66 | 78 | big.push(`it adds ${features.length} feature files (at most ${MAX_FEATURES})`); |
| @@ -74,6 +86,6 @@ export function directionProblems( | ||
| 74 | 86 | function problem(features: readonly string[]): string { |
| 75 | 87 | const shown = features.slice(0, 3).join(", ") + (features.length > 3 ? ` and ${features.length - 3} more` : ""); |
| 76 | 88 | return ( |
| 77 | `rule "pipeline first": this pull adds a feature (${shown}) and no pipeline change (scripts/, src/flow/, src/nightly/, src/checks/, forge.json); change the pipeline, or put a "Direction: <why this goes ahead of the pipeline items>" line (10+ characters) in a commit message` | |
| 89 | `rule "pipeline first": this pull adds a feature (${shown}) and no pipeline change (scripts/, src/flow/, src/nightly/, src/checks/, forge.json); change the pipeline, or put a "Direction: <why this goes ahead of the pipeline items> (#issue)" line (10+ characters, naming the issue it serves) in a commit message` | |
| 78 | 90 | ); |
| 79 | 91 | } |
test/direction-refusal.test.ts +1 −1
| @@ -56,7 +56,7 @@ test("a range that adds a page alone is refused; a Direction line in its message | ||
| 56 | 56 | // the gate's own entry point runs the rule, so removing its call goes red |
| 57 | 57 | expect(gateMain(dir, base)).toContain('rule "pipeline first"'); |
| 58 | 58 | |
| 59 | run(dir, "commit", "-q", "--allow-empty", "-m", "Waive\n\nDirection: a small door onto the spawn path, owner asked"); | |
| 59 | run(dir, "commit", "-q", "--allow-empty", "-m", "Waive\n\nDirection: a small door onto the spawn path, owner asked on #7642"); | |
| 60 | 60 | expect(await withBase(base, () => directionRefusal(dir))).toEqual([]); |
| 61 | 61 | expect(gateMain(dir, base)).not.toContain('rule "pipeline first"'); |
| 62 | 62 | }); |
test/direction.test.ts +9
| @@ -78,3 +78,12 @@ test("a new action, core module or route is a feature too, naming the rule (#142 | ||
| 78 | 78 | expect(directionProblems([ch("A", "src/core/x.ts"), ch("M", "scripts/gate.ts")], [])).toEqual([]); |
| 79 | 79 | expect(directionProblems([ch("A", "src/core/x.ts"), ch("A", "src/checks/y.ts")], [])).toEqual([]); |
| 80 | 80 | }); |
| 81 | ||
| 82 | test("a Direction line that names no issue is refused by name (#14293)", () => { | |
| 83 | const out = directionProblems([page], ["Direction: a small door onto the spawn path, owner asked"]); | |
| 84 | expect(out).toHaveLength(1); | |
| 85 | expect(out[0]).toContain('rule "name the issue"'); | |
| 86 | expect(directionProblems([page], ["Direction: a small door onto the spawn path (#7642)"])).toEqual([]); | |
| 87 | // an issue number elsewhere in the message is not the waiver's | |
| 88 | expect(directionProblems([page], ["Closes #7642\n\nDirection: a small door onto the spawn path"])).toHaveLength(1); | |
| 89 | }); |
new above
offline