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): name the worst test file and mark unverified findings (#2733)

Raghav Chamadiya6ded04bc9d3e
diff --git a/packages/core/src/repowise/core/persistence/crud/analysis/health.py b/packages/core/src/repowise/core/persistence/crud/analysis/health.py
index ea4bc2aa5..0cd9a1db5 100644
--- a/packages/core/src/repowise/core/persistence/crud/analysis/health.py
+++ b/packages/core/src/repowise/core/persistence/crud/analysis/health.py
@@ -26,7 +26,7 @@ from ....analysis.health.ranking import (
sort_metrics_worst_first,
worst_metric,
)
-from ....analysis.health.rows import detail_map
+from ....analysis.health.rows import detail_map, split_tests
from ....analysis.health.scope import scores_language
from ....analysis.health.scoring import ADVISORY_DIMENSION, nloc_weighted_attr
from ....test_paths import is_test_related_path
@@ -624,6 +624,8 @@ async def get_health_summary(
"average_health": 10.0,
"worst_performer_path": None,
"worst_performer_score": None,
+ "worst_test_path": None,
+ "worst_test_score": None,
"open_findings": 0,
"maintainability_average": None,
"performance_average": None,
@@ -696,7 +698,11 @@ async def get_health_summary(
# agreed with the worst-files list only because every caller happened to
# pass an already-ranked list — a floor tie made the headline and the list
# under it disagree the moment one did not.
- worst = worst_metric(metrics, deduction_by_path(findings))
+ deductions = deduction_by_path(findings)
+ worst = worst_metric(metrics, deductions)
+ # The worst production file heads the page; the worst test file is named
+ # apart, under the same ranking, so a weak test is not lost behind it.
+ worst_test = worst_metric(split_tests(metrics)[1], deductions)
by_dim: dict[str, int] = {}
for finding in findings:
@@ -722,6 +728,8 @@ async def get_health_summary(
"average_health": round(avg, 2),
"worst_performer_path": worst.file_path,
"worst_performer_score": round(worst.score, 2),
+ "worst_test_path": worst_test.file_path if worst_test is not None else None,
+ "worst_test_score": round(worst_test.score, 2) if worst_test is not None else None,
# Advisory findings carry a zero health impact, so counting them
# here would grow the headline without anything having got worse.
"open_findings": len(findings) - by_dim.get(ADVISORY_DIMENSION, 0),
diff --git a/packages/types/src/files.ts b/packages/types/src/files.ts
index d829d5893..fec9613f5 100644
--- a/packages/types/src/files.ts
+++ b/packages/types/src/files.ts
@@ -36,6 +36,8 @@ export interface FileHealthFinding {
* `defect` when an older payload omits it.
*/
dimension?: HealthDimension;
+ /** `"unverified"` for a provisional finding type; null for a validated one. */
+ verification?: string | null;
}
export interface FileHealthMetric {
diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts
index bf90ed82e..7bfad3a66 100644
--- a/packages/types/src/health.ts
+++ b/packages/types/src/health.ts
@@ -334,6 +334,9 @@ export interface HealthFinding {
* older payload omits it.
*/
dimension?: HealthDimension;
+ /** `"unverified"` for a provisional finding type, shown because it was asked
+ * for by name. Null or absent for a validated type. */
+ verification?: string | null;
}
export type PerformanceExecutionContext = "production" | "tooling" | "test" | "unknown";
@@ -627,6 +630,10 @@ export interface HealthOverviewSummary {
hotspot_health?: number | null;
worst_performer_path: string | null;
worst_performer_score: number | null;
+ /** The lowest-scoring test file, ranked apart from production files. Null
+ * without test files; absent on an older server. */
+ worst_test_path?: string | null;
+ worst_test_score?: number | null;
open_findings: number;
severity_breakdown?: {
critical: number;
diff --git a/packages/ui/__tests__/files/file-health-tab.test.tsx b/packages/ui/__tests__/files/file-health-tab.test.tsx
index 829e812f0..07ecc4ffd 100644
--- a/packages/ui/__tests__/files/file-health-tab.test.tsx
+++ b/packages/ui/__tests__/files/file-health-tab.test.tsx
@@ -93,3 +93,11 @@ describe("FileHealthTab", () => {
expect(screen.getByText("No health data")).toBeTruthy();
});
});
+
+describe("FileHealthTab verification", () => {
+ it("marks a provisional finding type as unverified", () => {
+ const findings = [{ ...makeFinding(0), verification: "unverified" }, makeFinding(1)];
+ render(<FileHealthTab health={makeHealth(findings)} functionBlame={[]} />);
+ expect(screen.getAllByText("unverified")).toHaveLength(1);
+ });
+});
diff --git a/packages/ui/__tests__/health/code-health-lede.test.tsx b/packages/ui/__tests__/health/code-health-lede.test.tsx
index 620b804ac..2c3f1812a 100644
--- a/packages/ui/__tests__/health/code-health-lede.test.tsx
+++ b/packages/ui/__tests__/health/code-health-lede.test.tsx
@@ -114,3 +114,21 @@ describe("CodeHealthLede — the figure and its band agree at the edge", () => {
expect(container.textContent).not.toContain("7.0 out of 10");
});
});
+
+describe("CodeHealthLede: the worst test file", () => {
+ it("names the lowest-scoring test file apart from production", () => {
+ const { container } = render(
+ <CodeHealthLede
+ summary={summary({ worst_test_path: "tests/test_big.py", worst_test_score: 2.4 })}
+ />,
+ );
+ expect(screen.getByText("tests/test_big.py")).toBeInTheDocument();
+ expect(container.textContent).toContain("Test files are ranked apart.");
+ expect(container.textContent).toContain("at 2.4.");
+ });
+
+ it("says nothing about tests when there are none, or the server predates it", () => {
+ const { container } = render(<CodeHealthLede summary={summary({ worst_test_path: null })} />);
+ expect(container.textContent).not.toContain("Test files are ranked apart");
+ });
+});
diff --git a/packages/ui/src/files/file-health-tab.tsx b/packages/ui/src/files/file-health-tab.tsx
index 8868c35b0..981f0564d 100644
--- a/packages/ui/src/files/file-health-tab.tsx
+++ b/packages/ui/src/files/file-health-tab.tsx
@@ -21,6 +21,7 @@ import { FileSignalsPanel } from "../health/file-signals-panel";
import { FindingOpportunityLink } from "../health/file-opportunity";
import { StatRibbon, type RibbonStat } from "../stats/stat-ribbon";
import { SeverityMark } from "../health/severity-mark";
+import { VerificationTag } from "../health/verification-tag";
import { formatNumber } from "../lib/format";
import type { FileDetailHealth, FunctionBlameRow } from "@repowise-dev/types/files";
import type { RefactoringOpportunity } from "@repowise-dev/types/refactoring";
@@ -245,6 +246,7 @@ export function FileHealthTab({
<span className="text-sm font-semibold text-[var(--color-text-primary)]">
{biomarkerLabel(f.biomarker_type)}
</span>
+ <VerificationTag verification={f.verification} />
{/* Category and pillar are machine-produced labels, so they
are mono micro-labels rather than two tinted chips —
rule 9, nothing here responds to a click. */}
diff --git a/packages/ui/src/health/code-health-lede.tsx b/packages/ui/src/health/code-health-lede.tsx
index 5bc3f1e9a..921df5133 100644
--- a/packages/ui/src/health/code-health-lede.tsx
+++ b/packages/ui/src/health/code-health-lede.tsx
@@ -109,6 +109,8 @@ export function CodeHealthLede({
const perf = summary.performance_average;
const perfFindings = summary.performance_findings ?? 0;
const hotspot = summary.hotspot_health;
+ const worstTestPath = summary.worst_test_path;
+ const worstTestScore = summary.worst_test_score;
// Read off the response, not the page's control: the two disagree while a
// request is in flight, and a figure captioned by the mode the reader just
// asked for rather than the one it was computed under is the whole bug this
@@ -262,6 +264,25 @@ export function CodeHealthLede({
, {describeGap(hotspot, health)}
</p>
)}
+
+ {/* Tests are ranked apart from production files, so the weakest one
+ would otherwise never be named on this page. */}
+ {worstTestPath && worstTestScore != null && (
+ <p className="mt-2.5">
+ Test files are ranked apart. The lowest scoring is{" "}
+ <span className="break-all font-mono text-[12px] text-[var(--color-text-primary)]">
+ {worstTestPath}
+ </span>{" "}
+ at{" "}
+ <strong
+ className="font-semibold"
+ style={{ color: healthBandColor(bandForScore(worstTestScore)) }}
+ >
+ {formatScore(worstTestScore)}
+ </strong>
+ .
+ </p>
+ )}
</PageLede>
<StatRibbon stats={stats} />
diff --git a/packages/ui/src/health/health-file-drawer.tsx b/packages/ui/src/health/health-file-drawer.tsx
index 71692803b..7805dff86 100644
--- a/packages/ui/src/health/health-file-drawer.tsx
+++ b/packages/ui/src/health/health-file-drawer.tsx
@@ -48,6 +48,7 @@ import type {
} from "@repowise-dev/types/health";
import type { RefactoringOpportunity } from "@repowise-dev/types/refactoring";
import { SeverityMark } from "./severity-mark";
+import { VerificationTag } from "./verification-tag";
import { ImpactFigure } from "./impact-figure";
export interface HealthDrawerFinding {
@@ -63,6 +64,8 @@ export interface HealthDrawerFinding {
details?: BiomarkerDetailsRecord | null;
/** Home pillar; falls back to the biomarker's glossary dimension. */
dimension?: BiomarkerDimension | string;
+ /** `"unverified"` for a provisional finding type. */
+ verification?: string | null;
}
export interface HealthDrawerMetric {
@@ -222,6 +225,7 @@ export function HealthFileDrawer({
<span className="text-[10px] uppercase tracking-wider text-[var(--color-text-tertiary)]">
{CATEGORY_LABEL[info.category]}
</span>
+ <VerificationTag verification={f.verification} />
{(() => {
// A history marker wears a neutral "Watch" chip instead of its
// pillar's: it is scored, but nothing in this file will clear it.
diff --git a/packages/ui/src/health/refactoring-card.tsx b/packages/ui/src/health/refactoring-card.tsx
index 5df146df6..ab97d62fa 100644
--- a/packages/ui/src/health/refactoring-card.tsx
+++ b/packages/ui/src/health/refactoring-card.tsx
@@ -17,6 +17,7 @@ import { FindingOpportunityLink } from "./file-opportunity";
import type { RefactoringOpportunity } from "@repowise-dev/types/refactoring";
import { AskAboutThis } from "../chat/ask-about-this";
import { SeverityMark } from "./severity-mark";
+import { VerificationTag } from "./verification-tag";
export type EffortBucket = "S" | "M" | "L" | "XL";
@@ -31,6 +32,8 @@ export interface HealthWorkItemFinding {
reason: string;
status?: string;
details?: BiomarkerDetailsRecord | null;
+ /** `"unverified"` for a provisional finding type. */
+ verification?: string | null;
}
export interface HealthWorkItem {
@@ -285,6 +288,7 @@ export function HealthWorkItemCard({
<span className="text-xs font-medium text-[var(--color-text-primary)]">
{biomarkerLabel(f.biomarker_type)}
</span>
+ <VerificationTag verification={f.verification} />
{f.function_name ? (
<span className="text-xs font-mono text-[var(--color-text-tertiary)]">{f.function_name}</span>
) : null}
diff --git a/packages/ui/src/health/verification-tag.tsx b/packages/ui/src/health/verification-tag.tsx
new file mode 100644
index 000000000..87e5ae363
--- /dev/null
+++ b/packages/ui/src/health/verification-tag.tsx
@@ -0,0 +1,19 @@
+/**
+ * The mark a provisional finding type carries wherever it is shown.
+ *
+ * A provisional type has not yet earned a place on default surfaces, so it
+ * appears only when someone asked for it by name. The server labels those rows
+ * (`verification: "unverified"`); this says so on the row instead of letting
+ * the finding read like a validated one. Renders nothing for a validated type.
+ */
+export function VerificationTag({ verification }: { verification?: string | null | undefined }) {
+ if (!verification) return null;
+ return (
+ <span
+ className="rounded border border-[var(--color-border-default)] px-1 font-mono text-[10px] uppercase tracking-[0.12em] text-[var(--color-text-secondary)]"
+ title="A provisional finding type, not yet validated against bug-fix history. Shown because it was asked for by name."
+ >
+ {verification}
+ </span>
+ );
+}
diff --git a/tests/unit/persistence/test_health_overview_reads.py b/tests/unit/persistence/test_health_overview_reads.py
index 5ae75e160..ce1db4852 100644
--- a/tests/unit/persistence/test_health_overview_reads.py
+++ b/tests/unit/persistence/test_health_overview_reads.py
@@ -308,3 +308,33 @@ async def test_snapshot_file_counts_on_a_repo_with_no_history(
repo = await upsert_repository(async_session, name="repo", local_path=str(tmp_path))
assert await get_health_snapshot_file_counts(async_session, repo.id) == []
+
+
+async def test_summary_names_the_worst_test_file_apart(async_session, tmp_path) -> None:
+ """The headline names the worst production file; the worst test is its own pair."""
+ repo = await _seed(
+ async_session,
+ tmp_path,
+ [
+ _metric("src/a.py", 4.0),
+ _metric("src/b.py", 6.0),
+ {**_metric("tests/test_a.py", 2.0), "is_test": True},
+ {**_metric("tests/test_b.py", 5.0), "is_test": True},
+ ],
+ [],
+ )
+
+ summary = await get_health_summary(async_session, repo.id)
+
+ assert summary["worst_performer_path"] == "src/a.py"
+ assert summary["worst_test_path"] == "tests/test_a.py"
+ assert summary["worst_test_score"] == 2.0
+
+
+async def test_summary_worst_test_is_null_without_test_files(async_session, tmp_path) -> None:
+ repo = await _seed(async_session, tmp_path, [_metric("src/a.py", 4.0)], [])
+
+ summary = await get_health_summary(async_session, repo.id)
+
+ assert summary["worst_test_path"] is None
+ assert summary["worst_test_score"] is None
diff --git a/tests/unit/server/test_health_excludes.py b/tests/unit/server/test_health_excludes.py
index 62a6e1290..bfb54ce08 100644
--- a/tests/unit/server/test_health_excludes.py
+++ b/tests/unit/server/test_health_excludes.py
@@ -91,6 +91,8 @@ async def test_health_reads_honor_repo_settings_excludes(session, tmp_path) -> N
"average_health": 8.5,
"worst_performer_path": "src/app.py",
"worst_performer_score": 8.5,
+ "worst_test_path": None,
+ "worst_test_score": None,
"open_findings": 1,
"maintainability_average": None,
"performance_average": None,