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.

fix(ui): say a repository has no hotspot files instead of blaming the scope (#3713)

Imaduddin Bhaisaheb9fd05905a327
diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts
index 354b90065..9f199f7b4 100644
--- a/packages/types/src/health.ts
+++ b/packages/types/src/health.ts
@@ -1073,7 +1073,10 @@ export interface FileHealthTrend {
export interface HealthTrendResponse {
history: Array<{
taken_at: string | null;
- /** `null` under a narrowed scope, which recorded only the average. */
+ /**
+ * `null` under a narrowed scope, which recorded only the average, and on
+ * the full scope when that snapshot recorded no hotspot files.
+ */
hotspot_health: number | null;
average_health: number;
worst_performer_path: string | null;
@@ -1091,7 +1094,10 @@ export interface HealthTrendResponse {
doc_drift_count?: number | null;
}>;
summary: {
- /** `null` under a narrowed scope: only the average covers both populations. */
+ /**
+ * `null` under a narrowed scope (only the average covers both populations),
+ * and on the full scope when the newest snapshot recorded no hotspot files.
+ */
current_hotspot_health: number | null;
current_average_health: number;
previous_hotspot_health: number | null;
diff --git a/packages/ui/__tests__/health/trend-view.test.tsx b/packages/ui/__tests__/health/trend-view.test.tsx
index 09e91236e..a9d3a5e1e 100644
--- a/packages/ui/__tests__/health/trend-view.test.tsx
+++ b/packages/ui/__tests__/health/trend-view.test.tsx
@@ -29,6 +29,62 @@ const deltas = (n: number, offset = 0) =>
delta: -1,
}));
+describe("TrendView — hotspot health stat", () => {
+ const noHotspots = {
+ current_hotspot_health: null,
+ current_average_health: 8.1,
+ previous_hotspot_health: null,
+ previous_average_health: 8,
+ hotspot_delta: null,
+ average_delta: 0.1,
+ };
+
+ it("says a repository has no hotspot files on the full scope, not that the scope hid them", () => {
+ render(
+ <TrendView
+ data={response({ scope: "all", summary: noHotspots })}
+ isLoading={false}
+ error={null}
+ />,
+ );
+ expect(screen.getByText("no hotspot files")).toBeTruthy();
+ expect(screen.queryByText("not measured for this scope")).toBeNull();
+ });
+
+ it("keeps saying the figure was not measured under a narrowed scope", () => {
+ render(
+ <TrendView
+ data={response({ scope: "production", summary: noHotspots })}
+ isLoading={false}
+ error={null}
+ />,
+ );
+ expect(screen.getByText("not measured for this scope")).toBeTruthy();
+ expect(screen.queryByText("no hotspot files")).toBeNull();
+ });
+
+ it("still shows the score and its delta when a hotspot figure exists", () => {
+ render(
+ <TrendView
+ data={response({
+ scope: "all",
+ summary: {
+ ...noHotspots,
+ current_hotspot_health: 6.5,
+ previous_hotspot_health: 5,
+ hotspot_delta: 1.5,
+ },
+ })}
+ isLoading={false}
+ error={null}
+ />,
+ );
+ expect(screen.getByText("6.5")).toBeTruthy();
+ expect(screen.queryByText("no hotspot files")).toBeNull();
+ expect(screen.queryByText("not measured for this scope")).toBeNull();
+ });
+});
+
describe("TrendView — largest score changes", () => {
// Two caps sit between the response and the picture: the server slices its
// list, and the chart draws only the largest few of what arrives. The block
diff --git a/packages/ui/src/health/trend-view.tsx b/packages/ui/src/health/trend-view.tsx
index 2b4981ab3..bcdb69512 100644
--- a/packages/ui/src/health/trend-view.tsx
+++ b/packages/ui/src/health/trend-view.tsx
@@ -90,10 +90,16 @@ function codeHealthStat(summary: TrendSummary, otherReading: boolean): RibbonSta
};
}
-function hotspotStat(summary: TrendSummary, otherReading: boolean): RibbonStat {
- // Absent under a narrowed scope: only the average was recorded for both
- // populations, so a repo-wide hotspot figure would describe files this view
- // has dropped. Say so rather than printing one.
+function hotspotStat(
+ summary: TrendSummary,
+ otherReading: boolean,
+ narrowed: boolean,
+): RibbonStat {
+ // Absent for one of two reasons. Under a narrowed scope only the average was
+ // recorded for both populations, so a repo-wide hotspot figure would describe
+ // files this view has dropped. On the full scope it means the newest snapshot
+ // recorded no hotspot files at all. Say which, rather than blaming the scope
+ // for a repository that simply has none.
const hotspot = summary.current_hotspot_health;
return {
label: "Hotspot health",
@@ -104,7 +110,9 @@ function hotspotStat(summary: TrendSummary, otherReading: boolean): RibbonStat {
...(hotspot == null ? {} : { valueColor: scoreTextColor(hotspot) }),
sub:
hotspot == null
- ? "not measured for this scope"
+ ? narrowed
+ ? "not measured for this scope"
+ : "no hotspot files"
: deltaSub(summary.hotspot_delta, summary.previous_hotspot_health),
...(hotspot != null && Math.abs(summary.hotspot_delta ?? 0) >= 0.05
? { subColor: deltaColor(summary.hotspot_delta) }
@@ -234,10 +242,13 @@ export function TrendView({
// the other reading of them here put two different numbers under one name on
// one screen — the exact confusion the single headline exists to end.
const otherReading = counts === "code_shape";
+ // The response names the scope it used, which is what tells a null hotspot
+ // figure under a narrowed scope apart from one on the full scope.
+ const narrowed = data.scope === "production";
const stats: RibbonStat[] = [
codeHealthStat(data.summary, otherReading),
- hotspotStat(data.summary, otherReading),
+ hotspotStat(data.summary, otherReading, narrowed),
{
label: "Snapshots",
value: String(data.snapshot_count),