Public: anyone can read this; the crew can change it.
Automate a review finding as a lint or test: Direction: the owner's order is pipeline items (#6534, #6611, #5276, #3316, #621 #15417
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15415-automate-a-review-finding-as-a-lint-or-t → main 0 commits fork
3 files
changed +27
−8
src/kernel/direction.ts +11
| @@ -41,6 +41,13 @@ const WAIVER = /^Direction:[ \t]*\S[^\n]{9,}/im; | ||
| 41 | 41 | * The issue the waiver serves, as `#123` (#14293): five reviews said "say which issue it serves". |
| 42 | 42 | */ |
| 43 | 43 | const ISSUE = /#\d+/; |
| 44 | /** | |
| 45 | * The owner's pipeline items, in order. Five more reviews (#13496, #13931, #13951, #14661, #15095) | |
| 46 | * asked "say why it goes ahead of #6534, #6611 ...": a waiver names at least one it goes ahead of | |
| 47 | * (#15415). Change this list when the owner's order changes. | |
| 48 | */ | |
| 49 | export const PIPELINE_ITEMS = [6534, 6611, 5276, 3316, 6217, 6428, 1242, 1073] as const; | |
| 50 | const itemNamed = (w: string) => [...w.matchAll(/#(\d+)/g)].some((m) => (PIPELINE_ITEMS as readonly number[]).includes(Number(m[1]))); | |
| 44 | 51 | |
| 45 | 52 | /** |
| 46 | 53 | * A redesign edits a page rather than adding one (#10380): an existing |
| @@ -75,6 +82,10 @@ export function directionProblems( | ||
| 75 | 82 | return [ |
| 76 | 83 | `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)"`, |
| 77 | 84 | ]; |
| 85 | if (!waivers.some(itemNamed)) | |
| 86 | return [ | |
| 87 | `rule "name what it goes ahead of": the Direction line does not name a pipeline item; say which it goes ahead of, as "Direction: <why> (#123), ahead of #${PIPELINE_ITEMS[0]}" (the items: ${PIPELINE_ITEMS.map((n) => "#" + n).join(", ")})`, | |
| 88 | ]; | |
| 78 | 89 | const big: string[] = []; |
| 79 | 90 | if (features.length > MAX_FEATURES) |
| 80 | 91 | big.push(`it adds ${features.length} feature files (at most ${MAX_FEATURES})`); |
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 on #7642"); | |
| 59 | run(dir, "commit", "-q", "--allow-empty", "-m", "Waive\n\nDirection: a small door onto the spawn path, owner asked on #7642, ahead of #6534"); | |
| 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 +15 −7
| @@ -14,7 +14,7 @@ test("a new feature with no pipeline change is refused, naming the rule", () => | ||
| 14 | 14 | |
| 15 | 15 | test("a pipeline change, or a Direction line of 10+ characters, passes", () => { |
| 16 | 16 | expect(directionProblems([page, ch("M", "scripts/gate.ts")], [])).toEqual([]); |
| 17 | expect(directionProblems([page], ["x\n\nDirection: a small door onto the spawn path, owner asked on #7642"])).toEqual([]); | |
| 17 | expect(directionProblems([page], ["x\n\nDirection: a small door onto the spawn path, owner asked on #7642, ahead of #6534"])).toEqual([]); | |
| 18 | 18 | expect(directionProblems([page], ["Direction: no"])).toHaveLength(1); |
| 19 | 19 | }); |
| 20 | 20 | |
| @@ -29,7 +29,7 @@ test("a redesign — an existing page with 150+ changed lines — is a feature; | ||
| 29 | 29 | expect(out).toHaveLength(1); |
| 30 | 30 | expect(out[0]).toContain('rule "pipeline first"'); |
| 31 | 31 | expect(directionProblems([edit], [], new Map([[edit.path, 149]]))).toEqual([]); |
| 32 | expect(directionProblems([edit], ["Direction: owner asked for the redesign on #10299"], new Map([[edit.path, 400]]))).toEqual([]); | |
| 32 | expect(directionProblems([edit], ["Direction: owner asked for the redesign on #10299, ahead of #6534"], new Map([[edit.path, 400]]))).toEqual([]); | |
| 33 | 33 | expect(directionProblems([edit, ch("M", "scripts/gate.ts")], [], new Map([[edit.path, 400]]))).toEqual([]); |
| 34 | 34 | }); |
| 35 | 35 | |
| @@ -38,7 +38,7 @@ test("the reason must sit on the Direction line itself, not a later paragraph", | ||
| 38 | 38 | }); |
| 39 | 39 | |
| 40 | 40 | test("a waived feature pull stays small and single-purpose, naming the rule", () => { |
| 41 | const why = ["Direction: a small door onto the spawn path, owner asked on #7642"]; | |
| 41 | const why = ["Direction: a small door onto the spawn path, owner asked on #7642, ahead of #6534"]; | |
| 42 | 42 | const pages = ["a", "b", "c"].map((n) => ch("A", `src/web/pages/${n}.ts`)); |
| 43 | 43 | const many = pages.slice(0, 1).concat(Array.from({ length: 20 }, (_, i) => ch("M", `src/core/m${i}.ts`))); |
| 44 | 44 | expect(directionProblems([page, ch("A", "docs/features/x.md")], why)).toEqual([]); |
| @@ -60,7 +60,7 @@ test("vendored code added under vendor/ is a feature, once per directory, naming | ||
| 60 | 60 | expect(out[0]).toContain('rule "pipeline first"'); |
| 61 | 61 | expect(out[0]).toContain("src/web/render/vendor/"); |
| 62 | 62 | expect(out[0]).not.toContain("and 1 more"); |
| 63 | expect(directionProblems(vendored, ["Direction: the owner asked for 3D files on #10317"])).toEqual([]); | |
| 63 | expect(directionProblems(vendored, ["Direction: the owner asked for 3D files on #10317, ahead of #6534"])).toEqual([]); | |
| 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 | }); |
| @@ -71,7 +71,7 @@ test("a new action, core module or route is a feature too, naming the rule (#142 | ||
| 71 | 71 | expect(out).toHaveLength(1); |
| 72 | 72 | expect(out[0]).toContain('rule "pipeline first"'); |
| 73 | 73 | expect(out[0]).toContain(path); |
| 74 | expect(directionProblems([ch("A", path)], ["Direction: owner asked for it on #7642"])).toEqual([]); | |
| 74 | expect(directionProblems([ch("A", path)], ["Direction: owner asked for it on #7642, ahead of #6534"])).toEqual([]); | |
| 75 | 75 | } |
| 76 | 76 | // Editing one, or editing a script beside a new one, is not asked. |
| 77 | 77 | expect(directionProblems([ch("M", "src/core/x.ts")], [])).toEqual([]); |
| @@ -83,7 +83,7 @@ test("a Direction line that names no issue is refused by name (#14293)", () => { | ||
| 83 | 83 | const out = directionProblems([page], ["Direction: a small door onto the spawn path, owner asked"]); |
| 84 | 84 | expect(out).toHaveLength(1); |
| 85 | 85 | expect(out[0]).toContain('rule "name the issue"'); |
| 86 | expect(directionProblems([page], ["Direction: a small door onto the spawn path (#7642)"])).toEqual([]); | |
| 86 | expect(directionProblems([page], ["Direction: a small door onto the spawn path (#7642) ahead of #6611"])).toEqual([]); | |
| 87 | 87 | // an issue number elsewhere in the message is not the waiver's |
| 88 | 88 | expect(directionProblems([page], ["Closes #7642\n\nDirection: a small door onto the spawn path"])).toHaveLength(1); |
| 89 | 89 | }); |
| @@ -95,8 +95,16 @@ test("a new module in any src/ directory is a feature too, naming the rule (#142 | ||
| 95 | 95 | expect(out[0]).toContain('rule "pipeline first"'); |
| 96 | 96 | expect(out[0]).toContain(path); |
| 97 | 97 | } |
| 98 | expect(directionProblems([ch("A", "src/maintain/duties/x.ts")], ["Direction: owner asked for it on #13347"])).toEqual([]); | |
| 98 | expect(directionProblems([ch("A", "src/maintain/duties/x.ts")], ["Direction: owner asked for it on #13347, ahead of #6534"])).toEqual([]); | |
| 99 | 99 | expect(directionProblems([ch("M", "src/maintain/duties/x.ts")], [])).toEqual([]); |
| 100 | 100 | expect(directionProblems([ch("A", "test/x.test.ts")], [])).toEqual([]); |
| 101 | 101 | expect(directionProblems([ch("A", "src/core/migrations/0003-c.ts")], [])).toEqual([]); |
| 102 | 102 | }); |
| 103 | ||
| 104 | test("a Direction line that names no pipeline item it goes ahead of is refused by name (#15415)", () => { | |
| 105 | const out = directionProblems([page], ["Direction: a small door onto the spawn path (#7642)"]); | |
| 106 | expect(out).toHaveLength(1); | |
| 107 | expect(out[0]).toContain('rule "name what it goes ahead of"'); | |
| 108 | expect(out[0]).toContain("#6534"); | |
| 109 | expect(directionProblems([page], ["Direction: a small door onto the spawn path (#7642), ahead of #1073"])).toEqual([]); | |
| 110 | }); |
new above
offline