Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(ui): name the 1.0 floor in the Why this score arithmetic (#4132)
Raghav Chamadiya0b59f83b284b
diff --git a/packages/types/src/health.ts b/packages/types/src/health.tsindex d99bc6a6b..7c0953c5f 100644--- a/packages/types/src/health.ts+++ b/packages/types/src/health.ts@@ -164,6 +164,9 @@ export const HEALTH_BAND_RANGE_LABEL: Record<HealthBand, string> = {at_risk: "under 4.0",};+/** The lowest score a file can show. Mirror of `SCORE_FLOOR` in core scoring. */+export const SCORE_FLOOR = 1.0;+/*** Pure score -> band mapping. Mirror of `grading.band_for` in core. Prefer the* API-provided `band` where available; use this only when deriving locally.diff --git a/packages/ui/__tests__/health/score-breakdown.test.tsx b/packages/ui/__tests__/health/score-breakdown.test.tsxnew file mode 100644index 000000000..e3fba6424--- /dev/null+++ b/packages/ui/__tests__/health/score-breakdown.test.tsx@@ -0,0 +1,30 @@+import { describe, it, expect } from "vitest";+import { render, screen } from "@testing-library/react";+import { ScoreBreakdown } from "../../src/health/score-breakdown.js";++describe("ScoreBreakdown arithmetic", () => {+ it("states the sum plainly above the floor", () => {+ render(<ScoreBreakdown score={7.5} totalDeduction={2.5} categories={[]} />);+ expect(screen.getByText("10.0 − 2.50 = 7.5")).toBeInTheDocument();+ });++ it("names the floor when the deductions go past it", () => {+ render(<ScoreBreakdown score={1.0} totalDeduction={11.2} categories={[]} />);+ expect(screen.getByText("10.0 − 11.20 = −1.20, floored at 1.0")).toBeInTheDocument();+ });++ it("needs no floor note when the deductions land exactly on it", () => {+ render(<ScoreBreakdown score={1.0} totalDeduction={9} categories={[]} />);+ expect(screen.getByText("10.0 − 9.00 = 1.0")).toBeInTheDocument();+ });++ it("shows a sum between zero and the floor as it is", () => {+ render(<ScoreBreakdown score={1.0} totalDeduction={9.5} categories={[]} />);+ expect(screen.getByText("10.0 − 9.50 = 0.50, floored at 1.0")).toBeInTheDocument();+ });++ it("never prints a negative zero", () => {+ render(<ScoreBreakdown score={1.0} totalDeduction={10.004} categories={[]} />);+ expect(screen.getByText("10.0 − 10.00 = 0.00, floored at 1.0")).toBeInTheDocument();+ });+});diff --git a/packages/ui/src/health/file-trend-chart.tsx b/packages/ui/src/health/file-trend-chart.tsxindex 464b0956d..6a925381c 100644--- a/packages/ui/src/health/file-trend-chart.tsx+++ b/packages/ui/src/health/file-trend-chart.tsx@@ -2,7 +2,7 @@import { TrendingDown } from "lucide-react";import { EmptyState } from "../shared/empty-state";-import type { FileHealthTrend } from "@repowise-dev/types/health";+import { SCORE_FLOOR, type FileHealthTrend } from "@repowise-dev/types/health";import { formatDate } from "../lib/format";import { deltaColor, formatDelta, scoreTextColor } from "./tokens";@@ -13,9 +13,6 @@ export interface FileTrendChartProps {bare?: boolean;}-/** The score floor. Below it the visible score stops moving; see `plotted`. */-const SCORE_FLOOR = 1;-/*** The value actually drawn for a point: the score with the floor undone where* the server recorded how deep the file is, and the plain score otherwise.diff --git a/packages/ui/src/health/score-breakdown.tsx b/packages/ui/src/health/score-breakdown.tsxindex a14ce10c3..e417f8272 100644--- a/packages/ui/src/health/score-breakdown.tsx+++ b/packages/ui/src/health/score-breakdown.tsx@@ -4,6 +4,7 @@ import {biomarkerLabel,type BiomarkerCategory,} from "./biomarker-glossary";+import { SCORE_FLOOR } from "@repowise-dev/types/health";import { type Severity } from "./tokens";import { ImpactFigure } from "./impact-figure";import { SeverityMark } from "./severity-mark";@@ -54,6 +55,15 @@ export interface ScoreBreakdownProps {showFindings?: boolean;}+/** "10.0 − X = score", naming the floor when the deductions go past it. */+function arithmetic(score: number, totalDeduction: number): string {+ const head = `10.0 − ${totalDeduction.toFixed(2)} = `;+ const raw = 10 - totalDeduction;+ if (raw >= SCORE_FLOOR || score > SCORE_FLOOR) return head + score.toFixed(1);+ const shown = raw.toFixed(2).replace(/^-(0\.00)$/, "$1").replace(/^-/, "−");+ return `${head}${shown}, floored at ${SCORE_FLOOR.toFixed(1)}`;+}+export function ScoreBreakdown({score,totalDeduction,@@ -67,7 +77,7 @@ export function ScoreBreakdown({it already shows at four times the size. What this section is for isthe subtraction, not the total. */}<p className="text-xs tabular-nums text-[var(--color-text-tertiary)]">- 10.0 − {totalDeduction.toFixed(2)} = {score.toFixed(1)}+ {arithmetic(score, totalDeduction)}</p><div className="space-y-2.5">