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

Merged opened this

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

Merged

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

  • Merged. scout/15415-automate-a-review-finding-as-a-lint-or-t was merged into main as 926062e.

Review

Sign in to review this change.
3 files changed +27 −8
src/kernel/direction.ts +11
@@ -41,6 +41,13 @@ const WAIVER = /^Direction:[ \t]*\S[^\n]{9,}/im;
4141 * The issue the waiver serves, as `#123` (#14293): five reviews said "say which issue it serves".
4242 */
4343 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])));
4451
4552 /**
4653 * A redesign edits a page rather than adding one (#10380): an existing
@@ -75,6 +82,10 @@ export function directionProblems(
7582 return [
7683 `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)"`,
7784 ];
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 ];
7889 const big: string[] = [];
7990 if (features.length > MAX_FEATURES)
8091 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
5656 // the gate's own entry point runs the rule, so removing its call goes red
5757 expect(gateMain(dir, base)).toContain('rule "pipeline first"');
5858
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");
6060 expect(await withBase(base, () => directionRefusal(dir))).toEqual([]);
6161 expect(gateMain(dir, base)).not.toContain('rule "pipeline first"');
6262 });
test/direction.test.ts +15 −7
@@ -14,7 +14,7 @@ test("a new feature with no pipeline change is refused, naming the rule", () =>
1414
1515 test("a pipeline change, or a Direction line of 10+ characters, passes", () => {
1616 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([]);
1818 expect(directionProblems([page], ["Direction: no"])).toHaveLength(1);
1919 });
2020
@@ -29,7 +29,7 @@ test("a redesign — an existing page with 150+ changed lines — is a feature;
2929 expect(out).toHaveLength(1);
3030 expect(out[0]).toContain('rule "pipeline first"');
3131 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([]);
3333 expect(directionProblems([edit, ch("M", "scripts/gate.ts")], [], new Map([[edit.path, 400]]))).toEqual([]);
3434 });
3535
@@ -38,7 +38,7 @@ test("the reason must sit on the Direction line itself, not a later paragraph",
3838 });
3939
4040 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"];
4242 const pages = ["a", "b", "c"].map((n) => ch("A", `src/web/pages/${n}.ts`));
4343 const many = pages.slice(0, 1).concat(Array.from({ length: 20 }, (_, i) => ch("M", `src/core/m${i}.ts`)));
4444 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
6060 expect(out[0]).toContain('rule "pipeline first"');
6161 expect(out[0]).toContain("src/web/render/vendor/");
6262 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([]);
6464 expect(directionProblems([...vendored, ch("M", "scripts/gate.ts")], [])).toEqual([]);
6565 expect(directionProblems([ch("M", "src/web/render/vendor/three/README.md")], [])).toEqual([]);
6666 });
@@ -71,7 +71,7 @@ test("a new action, core module or route is a feature too, naming the rule (#142
7171 expect(out).toHaveLength(1);
7272 expect(out[0]).toContain('rule "pipeline first"');
7373 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([]);
7575 }
7676 // Editing one, or editing a script beside a new one, is not asked.
7777 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)", () => {
8383 const out = directionProblems([page], ["Direction: a small door onto the spawn path, owner asked"]);
8484 expect(out).toHaveLength(1);
8585 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([]);
8787 // an issue number elsewhere in the message is not the waiver's
8888 expect(directionProblems([page], ["Closes #7642\n\nDirection: a small door onto the spawn path"])).toHaveLength(1);
8989 });
@@ -95,8 +95,16 @@ test("a new module in any src/ directory is a feature too, naming the rule (#142
9595 expect(out[0]).toContain('rule "pipeline first"');
9696 expect(out[0]).toContain(path);
9797 }
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([]);
9999 expect(directionProblems([ch("M", "src/maintain/duties/x.ts")], [])).toEqual([]);
100100 expect(directionProblems([ch("A", "test/x.test.ts")], [])).toEqual([]);
101101 expect(directionProblems([ch("A", "src/core/migrations/0003-c.ts")], [])).toEqual([]);
102102 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs