Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(ui): say where a moved finding came from in the commit health table (#4133)

Raghav Chamadiya5efdf0e540b9
diff --git a/packages/ui/__tests__/commits/commit-health-table.test.tsx b/packages/ui/__tests__/commits/commit-health-table.test.tsx
new file mode 100644
index 000000000..65919d3c5
--- /dev/null
+++ b/packages/ui/__tests__/commits/commit-health-table.test.tsx
@@ -0,0 +1,62 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+import type { CommitHealthFinding } from "@repowise-dev/types/git";
+import { CommitHealthTable } from "../../src/commits/commit-health-table";
+
+function finding(partial: Partial<CommitHealthFinding>): CommitHealthFinding {
+ return {
+ change_kind: "worsened",
+ dimension: "defect",
+ biomarker_type: "complex_method",
+ severity: "high",
+ path: "core/health/engine.py",
+ symbol: "evaluate",
+ line_start: 40,
+ attribution_basis: "added_lines",
+ reason: "evaluate has cyclomatic complexity 22",
+ ...partial,
+ };
+}
+
+describe("CommitHealthTable attribution", () => {
+ it("says where a moved finding came from instead of calling it incidental", () => {
+ render(
+ <CommitHealthTable
+ findings={[
+ finding({
+ attribution_basis: "moved",
+ moved_from: { path: "core/health/old_engine.py", symbol: "evaluate" },
+ }),
+ ]}
+ />,
+ );
+ expect(screen.getAllByText(/moved here from evaluate in core\/health\/old_engine\.py/).length).toBeGreaterThan(0);
+ expect(screen.queryByText(/not on a line it wrote/)).toBeNull();
+ });
+
+ it("names the moved basis even without the source path", () => {
+ render(<CommitHealthTable findings={[finding({ attribution_basis: "moved" })]} />);
+ expect(screen.getAllByText(/moved here from another file/).length).toBeGreaterThan(0);
+ expect(screen.queryByText(/not on a line it wrote/)).toBeNull();
+ });
+
+ it("keeps the incidental note for a file the commit only touched", () => {
+ render(<CommitHealthTable findings={[finding({ attribution_basis: "file_change" })]} />);
+ expect(screen.getAllByText(/not on a line it wrote/).length).toBeGreaterThan(0);
+ });
+
+ it("adds no note when the commit wrote the line", () => {
+ render(<CommitHealthTable findings={[finding({ attribution_basis: "added_lines" })]} />);
+ expect(screen.queryByText(/\(.*\)/)).toBeNull();
+ });
+
+ it("says a call-path finding was reached through a call the commit edited", () => {
+ render(<CommitHealthTable findings={[finding({ attribution_basis: "changed_call_edge" })]} />);
+ expect(screen.getAllByText(/reached through a call this commit edited/).length).toBeGreaterThan(0);
+ });
+
+ it("says an unexplained finding is not explained by the diff", () => {
+ render(<CommitHealthTable findings={[finding({ attribution_basis: "unknown" })]} />);
+ expect(screen.getAllByText(/not explained by this commit's diff/).length).toBeGreaterThan(0);
+ });
+});
diff --git a/packages/ui/src/commits/commit-health-table.tsx b/packages/ui/src/commits/commit-health-table.tsx
index ae7e8fdfb..28925e85e 100644
--- a/packages/ui/src/commits/commit-health-table.tsx
+++ b/packages/ui/src/commits/commit-health-table.tsx
@@ -12,6 +12,22 @@ export interface CommitHealthTableProps {
* touched the file, which is a weaker claim and is labelled as one. */
const DIRECT = new Set(["added_lines", "changed_symbol", "new_file"]);
+const INDIRECT_NOTE: Record<string, string> = {
+ changed_call_edge: "reached through a call this commit edited",
+ unknown: "not explained by this commit's diff",
+};
+
+/** How the commit relates to the finding, when it did not write the line itself. */
+function basisNote(f: CommitHealthFinding): string | null {
+ if (f.attribution_basis === "moved" || f.moved_from) {
+ const src = f.moved_from;
+ if (!src) return "moved here from another file";
+ return src.symbol ? `moved here from ${src.symbol} in ${src.path}` : `moved here from ${src.path}`;
+ }
+ if (DIRECT.has(f.attribution_basis)) return null;
+ return INDIRECT_NOTE[f.attribution_basis] ?? "in a file this commit touched, not on a line it wrote";
+}
+
function where(f: CommitHealthFinding): string {
const at = f.line_start ? `:${f.line_start}` : "";
return f.symbol ? `${f.symbol} — ${f.path}${at}` : `${f.path}${at}`;
@@ -37,17 +53,15 @@ const COLUMNS: ResponsiveColumn<CommitHealthFinding>[] = [
key: "reason",
header: "What changed",
cellClassName: "[overflow-wrap:anywhere]",
- render: (f) => (
- <span>
- {f.reason}
- {!DIRECT.has(f.attribution_basis) && (
- <span className="text-[var(--color-text-tertiary)]">
- {" "}
- (in a file this commit touched, not on a line it wrote)
- </span>
- )}
- </span>
- ),
+ render: (f) => {
+ const note = basisNote(f);
+ return (
+ <span>
+ {f.reason}
+ {note && <span className="text-[var(--color-text-tertiary)]"> ({note})</span>}
+ </span>
+ );
+ },
},
{
key: "where",