From bd3d888ec9bf849c9ab14cf2cb2031b52466a6b0 Mon Sep 17 00:00:00 2001 From: Yshuro Date: Wed, 25 Nov 2026 08:41:00 +0100 Subject: [PATCH] fix(report): name evidence kinds in summary instead of folding into groups Signed-off-by: Yshuro --- packages/cli/src/report/evidence.ts | 38 +++++++++++++++++++++++++ packages/cli/src/report/summary.ts | 28 +++++++++++-------- packages/cli/test/report.test.ts | 43 ++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/report/evidence.ts b/packages/cli/src/report/evidence.ts index 187febfcb..2062dedfa 100644 --- a/packages/cli/src/report/evidence.ts +++ b/packages/cli/src/report/evidence.ts @@ -131,3 +131,41 @@ export function groupTotals(rule: { } return totals; } + +/** + * Non-zero counts by kind, larger first, `reviews` group before `conventions` + * on a tie. + */ +export function sourceCounts(rule: { + surfaced?: { reviewComments: number }; + evidence?: Evidence; +}): Array<{ source: RuleSource; count: number }> { + const counts: Record = { + reviews: rule.surfaced?.reviewComments ?? 0, + commits: rule.evidence?.commits ?? 0, + issues: rule.evidence?.issues ?? 0, + "agent-files": rule.evidence?.["agent-files"] ?? 0, + conventions: rule.evidence?.conventions ?? 0, + docs: rule.evidence?.docs ?? 0, + tests: rule.evidence?.tests ?? 0, + }; + const order: readonly RuleSource[] = [ + "reviews", + "commits", + "issues", + "agent-files", + "conventions", + "docs", + "tests", + ]; + return order + .filter((source) => counts[source] > 0) + .map((source) => ({ source, count: counts[source] })) + .toSorted((a, b) => { + if (b.count !== a.count) return b.count - a.count; + return ( + (SOURCE_GROUPS[a.source] === "reviews" ? 0 : 1) - + (SOURCE_GROUPS[b.source] === "reviews" ? 0 : 1) + ); + }); +} diff --git a/packages/cli/src/report/summary.ts b/packages/cli/src/report/summary.ts index 6c07468e0..358599c18 100644 --- a/packages/cli/src/report/summary.ts +++ b/packages/cli/src/report/summary.ts @@ -1,4 +1,4 @@ -import { groupTotals, type SourceGroup } from "./evidence"; +import { sourceCounts, type RuleSource } from "./evidence"; import type { ReportRule, ReportV1 } from "./types"; /** @@ -39,19 +39,25 @@ function plural(count: number, one: string, many: string): string { return `${String(count)} ${count === 1 ? one : many}`; } +const SOURCE_LABELS: Record = { + reviews: ["review comment", "review comments"], + commits: ["fix-up commit", "fix-up commits"], + issues: ["issue", "issues"], + "agent-files": ["agent file", "agent files"], + conventions: ["convention", "conventions"], + docs: ["doc", "docs"], + tests: ["test", "tests"], +}; + /** - * "6 times in reviews, 1 time in conventions": each group above zero, the - * larger first, reviews first on a tie. Empty when the rule has neither. + * "4 fix-up commits, 2 review comments, 1 doc": each kind above zero, + * larger first, reviews group first on a tie. Empty when the rule has none. */ function evidenceSuffix(rule: ReportRule): string { - const totals = groupTotals(rule); - const order: SourceGroup[] = - totals.conventions > totals.reviews - ? ["conventions", "reviews"] - : ["reviews", "conventions"]; - const parts = order - .filter((group) => totals[group] > 0) - .map((group) => `${plural(totals[group], "time", "times")} in ${group}`); + const parts = sourceCounts(rule).map(({ source, count }) => { + const [one, many] = SOURCE_LABELS[source]; + return plural(count, one, many); + }); return parts.length === 0 ? "" : `: ${parts.join(", ")}`; } diff --git a/packages/cli/test/report.test.ts b/packages/cli/test/report.test.ts index 4c07e421b..851d995f1 100644 --- a/packages/cli/test/report.test.ts +++ b/packages/cli/test/report.test.ts @@ -864,7 +864,7 @@ describe("renderSummary", () => { invocation: "npx @taskless/cli", }); expect(summary).toContain( - "Rule a (Taskless ast-grep rule): 9 times in reviews\n" + "Rule a (Taskless ast-grep rule): 9 review comments\n" ); expect(summary).toContain("https://tskl.es/r/abc"); expect(summary).toContain("can be deleted after review"); @@ -918,17 +918,52 @@ describe("renderSummary", () => { invocation: "npx @taskless/cli", }); expect(summary).toContain( - "Rule a (Taskless ast-grep rule): 6 times in reviews, 1 time in conventions\n" + "Rule a (Taskless ast-grep rule): 4 fix-up commits, 2 review comments, 1 doc\n" ); expect(summary).toContain( - "Rule b (Taskless ast-grep rule): 5 times in conventions\n" + "Rule b (Taskless ast-grep rule): 3 tests, 2 agent files\n" ); expect(summary).toContain("Rule c (Taskless ast-grep rule)\n"); expect(summary).toContain( - "Rule d (Taskless ast-grep rule): 1 time in reviews, 1 time in conventions\n" + "Rule d (Taskless ast-grep rule): 1 review comment, 1 agent file\n" ); }); + it("credits commits by kind and never says reviews when there are no review comments", () => { + const report = assembleReport( + draftOf(["a", "b", "c"].map((id) => localRule(id))), + factsFor([], { + rules: [ + ruleWithEvidence("a", 0, { + sources: ["commits"], + evidence: { commits: 3 }, + }), + ruleWithEvidence("b", 0, { + sources: ["issues"], + evidence: { issues: 1 }, + }), + ruleWithEvidence("c", 0, { + sources: ["docs"], + evidence: { docs: 2 }, + }), + ], + }) + ); + const summary = renderSummary({ + report, + url: "https://tskl.es/r/abc", + expiresAt: "2026-11-12T00:00:00Z", + record: "2026-10-13_142200.json", + invocation: "npx @taskless/cli", + }); + expect(summary).toContain( + "Rule a (Taskless ast-grep rule): 3 fix-up commits\n" + ); + expect(summary).toContain("Rule b (Taskless ast-grep rule): 1 issue\n"); + expect(summary).toContain("Rule c (Taskless ast-grep rule): 2 docs\n"); + expect(summary).not.toContain("reviews"); + }); + it("states no problem count it does not have", () => { const summary = summaryOf( draftOf(["a", "b", "c"].map((id) => localRule(id)))