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(health): store no score for a file whose language health cannot analyse (#2955)
Raghav Chamadiyabf1d47fb553f
diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/command.py b/packages/cli/src/repowise/cli/commands/health_cmd/command.pyindex 3e18607cb..3599f590e 100644--- a/packages/cli/src/repowise/cli/commands/health_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/health_cmd/command.py@@ -32,6 +32,7 @@ from repowise.core.analysis.health.counts import (project as project_counts,)from repowise.core.analysis.health.models import split_by_origin+from repowise.core.analysis.health.rows import split_unscoredfrom repowise.core.analysis.health.scope import DEFAULT_SCOPE, SCOPES, parse_scopefrom repowise.core.analysis.health.scoring import compute_kpis@@ -355,6 +356,9 @@ def health_command(# Taken before the projection, so a row the projection cannot read still# keeps its findings rather than reading as a file that left the repo.scoped_paths = {m.file_path for m in metrics}+ # Files in a language health has no dialect for carry no score: they are+ # counted, never ranked or averaged.+ metrics, unanalysed = split_unscored(metrics)code_shape = parse_counts(counts) == "code_shape"if code_shape:# No `unscored` counterpart to the API's: this command scores live, so@@ -481,12 +485,17 @@ def health_command(band_str = f" [[{band_color}]{BAND_LABEL[band]}[/{band_color}]]"console.print(f"\nCode health: [bold]{avg if avg is not None else '?'}[/bold]/10{band_str} · "- f"Hotspot: [bold]{kpis.get('hotspot_health', '?')}[/bold]/10 · "- f"Worst: [bold]{kpis.get('worst_performer_score', '?')}[/bold]/10 "- f"({kpis.get('worst_performer_path', 'n/a')})"+ f"Hotspot: [bold]{kpis.get('hotspot_health') or '?'}[/bold]/10 · "+ f"Worst: [bold]{kpis.get('worst_performer_score') or '?'}[/bold]/10 "+ f"({kpis.get('worst_performer_path') or 'n/a'})")if code_shape:console.print("[dim]Counting code shape only — change history is left out.[/dim]")+ if unanalysed:+ console.print(+ f"[dim]{unanalysed} file(s) not analysed: health does not support "+ "their language yet.[/dim]"+ )_render_split_line(kpis)_render_distribution_line(health_distribution(metrics))diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/persist.py b/packages/cli/src/repowise/cli/commands/health_cmd/persist.pyindex 1db3e0dde..22d47fa7f 100644--- a/packages/cli/src/repowise/cli/commands/health_cmd/persist.py+++ b/packages/cli/src/repowise/cli/commands/health_cmd/persist.py@@ -130,7 +130,7 @@ def _persist_health(repo_path: object, *, report: object) -> None:returns; the CLI does not crash."""from repowise.cli.helpers import get_db_url_for_repo, reconcile_schema_best_effort- from repowise.core.analysis.health.trends import snapshot_file_maps+ from repowise.core.analysis.health.trends import snapshot_fieldsfrom repowise.core.persistence import (create_engine,create_session_factory,@@ -172,21 +172,9 @@ def _persist_health(repo_path: object, *, report: object) -> None:kpis = getattr(report, "kpis", {}) or {}metrics = getattr(report, "metrics", []) or []try:- scores_map, deductions_map = snapshot_file_maps(metrics, findings)- await save_health_snapshot(- session,- repo_id,- hotspot_health=float(kpis.get("hotspot_health", 10.0)),- average_health=float(kpis.get("average_health", 10.0)),- worst_performer_path=kpis.get("worst_performer_path"),- worst_performer_score=kpis.get("worst_performer_score"),- per_file_scores=scores_map,- per_file_deductions=deductions_map,- structure_average=kpis.get("structure_average"),- history_average=kpis.get("history_average"),- production_average=kpis.get("production_average"),- maintainability_average=kpis.get("maintainability_average"),- )+ fields = snapshot_fields(kpis, metrics, findings)+ if fields is not None:+ await save_health_snapshot(session, repo_id, **fields)except Exception as exc:console.print(f"[yellow]Snapshot write skipped: {exc}[/yellow]")diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/refactoring_targets.py b/packages/cli/src/repowise/cli/commands/health_cmd/refactoring_targets.pyindex 1428eb6bf..baeeb6d8f 100644--- a/packages/cli/src/repowise/cli/commands/health_cmd/refactoring_targets.py+++ b/packages/cli/src/repowise/cli/commands/health_cmd/refactoring_targets.py@@ -211,6 +211,16 @@ def _render_stored_refactoring_targets(return True+def _rankable(findings: list, metrics: list) -> list:+ """Findings on files that carry a score.++ A file stored with no score (a language health has no dialect for) is not+ ranked: a stand-in 10.0 would invent one. The API queue skips it too.+ """+ unscored = {m.file_path for m in metrics if m.score is None}+ return [f for f in findings if f.file_path not in unscored]++def _build_targets(metrics: list, findings: list, suggestions: list, *, limit: int) -> list[dict]:@@ -220,7 +230,7 @@ def _build_targets(sugg_by_file.setdefault(_suggestion_path(s), []).append(s)by_file: dict[str, list] = {}- for f in findings:+ for f in _rankable(findings, metrics):by_file.setdefault(f.file_path, []).append(f)metric_by_path = {m.file_path: m for m in metrics}diff --git a/packages/cli/src/repowise/cli/commands/status_cmd.py b/packages/cli/src/repowise/cli/commands/status_cmd.pyindex c1b97d6e3..8c7957fd4 100644--- a/packages/cli/src/repowise/cli/commands/status_cmd.py+++ b/packages/cli/src/repowise/cli/commands/status_cmd.py@@ -242,7 +242,7 @@ def _query_health(repo_path: Path) -> dict | None:# the worst-first sort twice with it).metrics = await get_health_metrics(session, repo.id)summary = await get_health_summary(session, repo.id, metrics=metrics)- if summary["file_count"] == 0:+ if summary["file_count"] == 0 and not summary.get("unanalysed_file_count"):return None# Hotspot health from the one owner. This used to average the# top 25% of files by NLOC, which ranks size rather than churn;@@ -270,6 +270,12 @@ def _query_health_line(repo_path: Path) -> str | None:data = _query_health(repo_path)if not data:return None+ if data["average_health"] is None:+ # Every file is in a language health has no dialect for.+ return (+ f"[bold]Health:[/bold] not analysed · {data['unanalysed_file_count']} files in "+ "languages health does not support yet"+ )worst_path = data["worst_performer_path"] or "n/a"worst_score = data["worst_performer_score"]from repowise.core.analysis.health.grading import (diff --git a/packages/cli/src/repowise/cli/commands/upgrade_flow.py b/packages/cli/src/repowise/cli/commands/upgrade_flow.pyindex a68be0d8a..0f6c4e2c5 100644--- a/packages/cli/src/repowise/cli/commands/upgrade_flow.py+++ b/packages/cli/src/repowise/cli/commands/upgrade_flow.py@@ -461,7 +461,7 @@ async def _run_upgrade(# biomarkers land — otherwise the upgrade leaves the health tables frozen# at the fast index's ESSENTIAL state. Mirrors what `init` / `update` do.try:- from repowise.core.analysis.health.trends import snapshot_file_maps+ from repowise.core.analysis.health.trends import snapshot_fieldsfrom repowise.core.persistence.crud import (save_health_findings,save_health_metrics,@@ -489,23 +489,11 @@ async def _run_upgrade(await save_health_findings(session, repo_id, health_report.findings)kpis = health_report.kpis or {}with contextlib.suppress(Exception): # snapshot is best-effort- scores_map, deductions_map = snapshot_file_maps(- health_report.metrics or [], health_report.findings or []- )- await save_health_snapshot(- session,- repo_id,- hotspot_health=float(kpis.get("hotspot_health", 10.0)),- average_health=float(kpis.get("average_health", 10.0)),- worst_performer_path=kpis.get("worst_performer_path"),- worst_performer_score=kpis.get("worst_performer_score"),- per_file_scores=scores_map,- per_file_deductions=deductions_map,- structure_average=kpis.get("structure_average"),- history_average=kpis.get("history_average"),- production_average=kpis.get("production_average"),- maintainability_average=kpis.get("maintainability_average"),+ fields = snapshot_fields(+ kpis, health_report.metrics or [], health_report.findings or [])+ if fields is not None:+ await save_health_snapshot(session, repo_id, **fields)console.print(f"Code health recomputed at FULL tier: "f"[cyan]{len(health_report.findings)}[/cyan] findings."diff --git a/packages/core/alembic/versions/0094_health_unanalysed_nullable.py b/packages/core/alembic/versions/0094_health_unanalysed_nullable.pynew file mode 100644index 000000000..2af7b78b7--- /dev/null+++ b/packages/core/alembic/versions/0094_health_unanalysed_nullable.py@@ -0,0 +1,46 @@+"""Allow ``health_file_metrics`` score columns to be NULL (PostgreSQL only).++A file whose language health has no dialect for is never walked, so it is now+stored with no ``score``, ``max_ccn`` or ``max_nesting`` instead of a 10.0 and+a complexity of 1 that nothing measured.++Local SQLite stores never run Alembic; ``init_db`` rebuilds that table there+when the columns are still NOT NULL, and new stores get them from the model.++Revision ID: 0094+Revises: 0093+Create Date: 2026-10-03+"""++from __future__ import annotations++from collections.abc import Sequence++import sqlalchemy as sa+from alembic import op++# revision identifiers+revision: str = "0094"+down_revision: str | None = "0093"+branch_labels: str | Sequence[str] | None = None+depends_on: str | Sequence[str] | None = None++_COLUMNS = (("score", sa.Float()), ("max_ccn", sa.Integer()), ("max_nesting", sa.Integer()))+++def upgrade() -> None:+ if op.get_bind().dialect.name != "postgresql":+ return+ for name, kind in _COLUMNS:+ op.alter_column("health_file_metrics", name, existing_type=kind, nullable=True)+++def downgrade() -> None:+ """Restore NOT NULL with the values the old schema wrote for such files."""+ if op.get_bind().dialect.name != "postgresql":+ return+ op.execute("UPDATE health_file_metrics SET score = 10.0 WHERE score IS NULL")+ op.execute("UPDATE health_file_metrics SET max_ccn = 1 WHERE max_ccn IS NULL")+ op.execute("UPDATE health_file_metrics SET max_nesting = 0 WHERE max_nesting IS NULL")+ for name, kind in _COLUMNS:+ op.alter_column("health_file_metrics", name, existing_type=kind, nullable=False)diff --git a/packages/core/src/repowise/core/analysis/change_health/analyzer.py b/packages/core/src/repowise/core/analysis/change_health/analyzer.pyindex 653a2264f..fd7c5a7e8 100644--- a/packages/core/src/repowise/core/analysis/change_health/analyzer.py+++ b/packages/core/src/repowise/core/analysis/change_health/analyzer.py@@ -16,7 +16,7 @@ from ...ingestion.models import EXTENSION_TO_LANGUAGE, SPECIAL_FILENAMES, FileInfrom ...ingestion.parser import parse_filefrom ...test_paths import is_test_related_pathfrom ..health import HealthAnalyzer, HealthFindingData-from ..health.complexity.languages import get_language_map+from ..health.complexity.languages import has_health_dialectfrom ..health.source_reader import MappingSourceReader#: Files above this size are skipped rather than parsed on both sides.@@ -41,11 +41,7 @@ def language_for(path: str) -> str | None:would let a docs-only change read as a clean bill of health."""language = language_of(path)- if language is None:- return None- if language == "sql": # walked by the sqlglot path, not a node map- return language- return language if get_language_map(language) is not None else None+ return language if has_health_dialect(language) else Nonedef is_generated(source: bytes) -> bool:diff --git a/packages/core/src/repowise/core/analysis/coupling/graph.py b/packages/core/src/repowise/core/analysis/coupling/graph.pyindex 0b3480b99..49b13ad24 100644--- a/packages/core/src/repowise/core/analysis/coupling/graph.py+++ b/packages/core/src/repowise/core/analysis/coupling/graph.py@@ -35,7 +35,7 @@ Honesty rules:from __future__ import annotationsfrom dataclasses import dataclass-from typing import Protocol+from typing import Any, Protocolfrom ...co_change import canonical_pair, confidence_ratio, parse_partners@@ -146,6 +146,12 @@ class CouplingGraph:total_files: int = 0+def _node_score(metric: Any) -> float | None:+ """A node's health score; ``None`` without a row or without a score."""+ score = getattr(metric, "score", None)+ return round(score, 2) if score is not None else None++def coupling_graph(metrics: list[MetricLike],git_meta_by_path: dict[str, GitMetaLike],@@ -224,7 +230,7 @@ def coupling_graph(CouplingNode(file_path=path,module=(metric_by_path[path].module if path in metric_by_path else None),- score=(round(metric_by_path[path].score, 2) if path in metric_by_path else None),+ score=_node_score(metric_by_path.get(path)),nloc=(metric_by_path[path].nloc or 0 if path in metric_by_path else 0),)for path in sorted(referenced)diff --git a/packages/core/src/repowise/core/analysis/health/aggregation.py b/packages/core/src/repowise/core/analysis/health/aggregation.pyindex f436cb0a2..11361acdd 100644--- a/packages/core/src/repowise/core/analysis/health/aggregation.py+++ b/packages/core/src/repowise/core/analysis/health/aggregation.py@@ -15,7 +15,7 @@ from typing import Anyfrom .models import Severity, primary_findingfrom .ranking import worst_metric-from .rows import detail_map, field+from .rows import detail_map, field, scored_rowsfrom .scoring import (CATEGORY_CAPS,HISTORY_CATEGORY,@@ -128,7 +128,9 @@ def module_rollups(files are all held at the floor resolves on the path instead of on depth."""buckets: dict[str, list[Any]] = {}- for row in metrics:+ # A file health has no dialect for carries no score and so no weight in+ # its module's average; a module of nothing else is not a row.+ for row in scored_rows(metrics):module = field(row, "module", None)if module:buckets.setdefault(str(module), []).append(row)diff --git a/packages/core/src/repowise/core/analysis/health/churn_complexity.py b/packages/core/src/repowise/core/analysis/health/churn_complexity.pyindex 9ccdbe70f..abf2f2c0b 100644--- a/packages/core/src/repowise/core/analysis/health/churn_complexity.py+++ b/packages/core/src/repowise/core/analysis/health/churn_complexity.py@@ -26,6 +26,8 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Protocol+from .rows import scored_rows+class MetricLike(Protocol):"""The health-metric fields the quadrant reads (duck-typed).@@ -92,7 +94,8 @@ def churn_complexity_points(files. Files with no recent churn are omitted (see module docstring)."""points: list[ChurnComplexityPoint] = []- for m in metrics:+ # No complexity axis for a file health never walked (no score).+ for m in scored_rows(metrics):g = git_meta_by_path.get(m.file_path)commit_count = (g.commit_count_90d or 0) if g else 0if commit_count <= 0:diff --git a/packages/core/src/repowise/core/analysis/health/complexity/languages.py b/packages/core/src/repowise/core/analysis/health/complexity/languages.pyindex 2eba7f205..20425b09e 100644--- a/packages/core/src/repowise/core/analysis/health/complexity/languages.py+++ b/packages/core/src/repowise/core/analysis/health/complexity/languages.py@@ -1177,3 +1177,23 @@ LANGUAGE_MAPS: dict[str, LanguageNodeMap] = {def get_language_map(language: str) -> LanguageNodeMap | None:"""Return the node-type map for *language* or None when unsupported."""return LANGUAGE_MAPS.get(language)+++# The status every surface reports for a file, or a repository, health could+# not score because no dialect covers the language.+NO_DIALECT_STATUS = "language_not_supported"++# SQL has no node map: health walks it through sqlglot (``sql_complexity``).+_WALKED_WITHOUT_A_MAP = frozenset({"sql"})+++def has_health_dialect(language: str | None) -> bool:+ """Whether health measures code shape for *language* at all.++ A file in a language without one is never walked, so a score for it would+ be a mechanical 10.0 that means "nothing looked", not "this code is fine".+ Every surface that stores, averages or prints a file score asks this one+ question rather than keeping its own language list. Narrower than+ ``scope.scores_language``, which decides whether a file gets a row at all.+ """+ return bool(language) and (language in LANGUAGE_MAPS or language in _WALKED_WITHOUT_A_MAP)diff --git a/packages/core/src/repowise/core/analysis/health/defect_accuracy.py b/packages/core/src/repowise/core/analysis/health/defect_accuracy.pyindex c7e9f735f..17329241f 100644--- a/packages/core/src/repowise/core/analysis/health/defect_accuracy.py+++ b/packages/core/src/repowise/core/analysis/health/defect_accuracy.py@@ -24,7 +24,7 @@ from collections.abc import Mappingfrom typing import Anyfrom .ranking import sort_metrics_worst_first-from .rows import detail_map, field+from .rows import detail_map, field, scored_rows_DEFAULT_K = 20_MIN_FILES = 25 # below this a precision@K headline is noise@@ -65,7 +65,9 @@ def compute_defect_accuracy(is still total and deterministic, but the floor-tied band is ordered by pathand so need not match the worst-files list this stat validates."""- scored = [m for m in metrics if field(m, "file_path")]+ # Unscored files (no health dialect for their language) have no place in a+ # worst-first ranking, so they are not part of what this stat validates.+ scored = [m for m in scored_rows(metrics) if field(m, "file_path")]n = len(scored)fix_counts, window_days = _recent_fix_counts(findings)total_defect_files = sum(1 for m in scored if fix_counts.get(field(m, "file_path"), 0) > 0)diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.pyindex a48eee0e4..fbc73d0de 100644--- a/packages/core/src/repowise/core/analysis/health/engine.py+++ b/packages/core/src/repowise/core/analysis/health/engine.py@@ -47,6 +47,7 @@ from .asserts.lexicon import AssertVocabularyfrom .asserts.oracle_reach import collect_cross_file_oraclesfrom .biomarkers import FileContext, detect_allfrom .complexity import FileComplexity, FunctionComplexity, walk_file+from .complexity.languages import has_health_dialectfrom .coverage import is_test_file as _coverage_is_test_filefrom .dataflow import FileDataflowCachefrom .duplication import ClonePair, DuplicationReport@@ -81,7 +82,7 @@ from .scope import scores_languagefrom .scoring import (attach_impacts,compute_kpis,- deduction_split,+ file_score_fields,remap_severities,score_file,)@@ -1638,16 +1639,14 @@ class HealthAnalyzer:_mark_deepest_block(findings, fc_list)# The overall surfaced score stays == the defect dimension (no blend- # yet); the per-dimension scores ride alongside it, additively.- defect_score = scores["defect"]- maint_score = scores["maintainability"]- perf_score = scores["performance"]- structure_deduction, history_deduction = deduction_split(findings)+ # yet); the per-dimension scores ride alongside it, additively. A+ # language with no dialect stores none of them, and no complexity+ # figures either: nothing walked the file.+ analysed = has_health_dialect(pf.file_info.language)metric = HealthFileMetricData(file_path=file_path,- score=round(defect_score, 2),- max_ccn=max_ccn,- max_nesting=max_nesting,+ max_ccn=max_ccn if analysed else None,+ max_nesting=max_nesting if analysed else None,nloc=nloc,# The stored field answers "does something test this file" - that is# how the MCP payload documents it and how every UI renders it@@ -1662,11 +1661,7 @@ class HealthAnalyzer:line_coverage_pct=line_cov,branch_coverage_pct=branch_cov,duplication_pct=dup_pct,- defect_score=round(defect_score, 2),- maintainability_score=(round(maint_score, 2) if maint_score is not None else None),- performance_score=(round(perf_score, 2) if perf_score is not None else None),- structure_deduction=structure_deduction,- history_deduction=history_deduction,+ **file_score_fields(analysed, scores, findings),is_test=bool(pf.file_info.is_test),code_origin=self._origins.get(file_path) or self._origin(pf),)diff --git a/packages/core/src/repowise/core/analysis/health/grading.py b/packages/core/src/repowise/core/analysis/health/grading.pyindex c3e4da506..b02b01c11 100644--- a/packages/core/src/repowise/core/analysis/health/grading.py+++ b/packages/core/src/repowise/core/analysis/health/grading.py@@ -21,7 +21,7 @@ from __future__ import annotationsfrom typing import Any, Literal-from .rows import field+from .rows import field, scored_rowsHealthBand = Literal["excellent", "good", "fair", "needs_work", "at_risk"]@@ -121,10 +121,11 @@ def distribution(metrics: list[Any]) -> dict[str, Any]:bands: dict[str, dict[str, float]] = {b: {"files": 0, "nloc": 0} for b in BAND_ORDER}total_files = 0total_weight = 0- for m in metrics:+ # A file with no score (no health dialect for its language) has no band.+ for m in scored_rows(metrics):if field(m, "file_path") is None:continue- score = float(field(m, "score", 10.0))+ score = float(field(m, "score"))weight = max(int(field(m, "nloc", 0) or 0), 1)band = band_for(score)bands[band]["files"] += 1diff --git a/packages/core/src/repowise/core/analysis/health/history_refresh.py b/packages/core/src/repowise/core/analysis/health/history_refresh.pyindex b3b527983..db0d1204c 100644--- a/packages/core/src/repowise/core/analysis/health/history_refresh.py+++ b/packages/core/src/repowise/core/analysis/health/history_refresh.py@@ -19,10 +19,11 @@ from typing import Anyfrom .biomarkers.base import BiomarkerResult, FileContextfrom .biomarkers.registry import registered_biomarkers+from .complexity.languages import has_health_dialectfrom .governance import GOVERNANCE_BIOMARKERSfrom .models import HealthFindingData, Severityfrom .rows import detail_map, field-from .scoring import attach_impacts, deduction_split, remap_severities, score_file+from .scoring import attach_impacts, file_score_fields, remap_severities, score_file#: History markers whose whole input is the file's git metadata.REFRESHABLE_MARKERS: frozenset[str] = frozenset(@@ -48,12 +49,26 @@ class RefreshedFile:file_path: strfindings: list[HealthFindingData]- score: float- defect_score: float+ # Every number below is ``None`` for a file whose language health has no+ # dialect for (``file_score_fields``).+ score: float | None+ defect_score: float | Nonemaintainability_score: float | Noneperformance_score: float | None- structure_deduction: float- history_deduction: float+ structure_deduction: float | None+ history_deduction: float | None+++def _analysed(language: str, metric: Any) -> bool:+ """Whether the file's numbers are measurements.++ Decided by the language when the graph knows it. A file with no graph node+ keeps what its stored row says, so a missing language never wipes the+ score of a file that was walked.+ """+ if language:+ return has_health_dialect(language)+ return field(metric, "score", None) is not Nonedef as_biomarker_result(finding: Any) -> BiomarkerResult:@@ -143,21 +158,10 @@ def refresh_history(rescored = attach_impacts(results, deductions)for finding in rescored:finding.file_path = path- structure, history = deduction_split(rescored)+ numbers = file_score_fields(_analysed(ctx.language, metric), scores, rescored)rescored.extend(governance)- out.append(- RefreshedFile(- file_path=path,- findings=rescored,- score=round(scores["defect"], 2),- defect_score=round(scores["defect"], 2),- maintainability_score=_round_opt(scores["maintainability"]),- performance_score=_round_opt(scores["performance"]),- structure_deduction=structure,- history_deduction=history,- )- )+ out.append(RefreshedFile(file_path=path, findings=rescored, **numbers))return out@@ -177,10 +181,6 @@ def _carry(stored: Any, path: str) -> HealthFindingData:)-def _round_opt(value: float | None) -> float | None:- return round(value, 2) if value is not None else None--def active_contributors(git_meta_by_path: dict[str, dict]) -> int | None:"""Repo-wide active-contributor count over stored git metadata."""from ...ingestion.git_indexer.enrich import count_active_contributorsdiff --git a/packages/core/src/repowise/core/analysis/health/models.py b/packages/core/src/repowise/core/analysis/health/models.pyindex e7f1198da..a8ddcc895 100644--- a/packages/core/src/repowise/core/analysis/health/models.py+++ b/packages/core/src/repowise/core/analysis/health/models.py@@ -161,9 +161,12 @@ class HealthFileMetricData:"""Per-file aggregate. Persisted as a ``HealthFileMetric`` row."""file_path: str- score: float- max_ccn: int- max_nesting: int+ # ``score``, ``max_ccn`` and ``max_nesting`` are ``None`` for a file whose+ # language health has no dialect for: nothing walked it, so there is no+ # measurement to store (``has_health_dialect``).+ score: float | None+ max_ccn: int | None+ max_nesting: int | Nonenloc: inthas_test_file: boolmodule: str | None = Nonediff --git a/packages/core/src/repowise/core/analysis/health/ranking.py b/packages/core/src/repowise/core/analysis/health/ranking.pyindex 3160883a3..de75c023a 100644--- a/packages/core/src/repowise/core/analysis/health/ranking.py+++ b/packages/core/src/repowise/core/analysis/health/ranking.py@@ -16,7 +16,7 @@ from __future__ import annotationsfrom collections.abc import Iterable, Mapping, Sequencefrom typing import Any-from .rows import field, split_tests+from .rows import field, scored_rows, split_testsfrom .scoring import SCORE_MAX__all__ = [@@ -81,9 +81,10 @@ def worst_metric(rows: Iterable[Any], deductions: Mapping[str, float]) -> Any |production rows without sorting the tail. Sharing the key is what keeps arepo's headline "worst performer" from naming a different file than theworst-files list under it. Test files are ranked separately, so a test only- answers when there is no production row at all.+ answers when there is no production row at all. A row with no score is+ never the worst: nothing measured it."""- production, tests = split_tests(rows)+ production, tests = split_tests(scored_rows(rows))return min(production or tests, key=lambda row: worst_first_key(row, deductions), default=None)diff --git a/packages/core/src/repowise/core/analysis/health/rows.py b/packages/core/src/repowise/core/analysis/health/rows.pyindex 068bac932..dae3cd777 100644--- a/packages/core/src/repowise/core/analysis/health/rows.py+++ b/packages/core/src/repowise/core/analysis/health/rows.py@@ -71,4 +71,22 @@ def split_tests(rows: Iterable[Any]) -> tuple[list[Any], list[Any]]:return production, tests-__all__ = ["detail_map", "field", "json_field", "split_tests"]+def scored_rows(rows: Iterable[Any]) -> list[Any]:+ """The per-file rows that carry a score.++ A file whose language health has no dialect for is stored with no score+ (``has_health_dialect``). It is a file nobody measured, so every average,+ "worst file" and count of scored files leaves it out rather than reading+ it as a perfect 10.0.+ """+ return [row for row in rows if field(row, "score", None) is not None]+++def split_unscored(rows: Iterable[Any]) -> tuple[list[Any], int]:+ """``(scored rows, how many were left out)``, for a figure that says both."""+ rows = list(rows)+ scored = scored_rows(rows)+ return scored, len(rows) - len(scored)+++__all__ = ["detail_map", "field", "json_field", "scored_rows", "split_tests", "split_unscored"]diff --git a/packages/core/src/repowise/core/analysis/health/scope.py b/packages/core/src/repowise/core/analysis/health/scope.pyindex 52919f332..ddc02624a 100644--- a/packages/core/src/repowise/core/analysis/health/scope.py+++ b/packages/core/src/repowise/core/analysis/health/scope.py@@ -37,6 +37,10 @@ def scores_language(language: str | None) -> bool:code shape to measure, while the history markers fire on them hard: achangelog every fix commit touches reads as a bug magnet. They get noscore, no findings and no metric row.++ A wider question than ``complexity.languages.has_health_dialect``: a code+ file in a language with no dialect still gets a metric row (its history+ findings stand), but no score."""return bool(language) and language in _scored_languages()diff --git a/packages/core/src/repowise/core/analysis/health/scoring.py b/packages/core/src/repowise/core/analysis/health/scoring.pyindex b8a428439..44de4e7da 100644--- a/packages/core/src/repowise/core/analysis/health/scoring.py+++ b/packages/core/src/repowise/core/analysis/health/scoring.py@@ -24,7 +24,7 @@ from dataclasses import replacefrom typing import TYPE_CHECKING, Anyfrom .models import HealthFileMetricData, HealthFindingData, Severity-from .rows import field, split_tests+from .rows import field, scored_rows, split_tests, split_unscoredif TYPE_CHECKING:# Annotation-only, and deliberately not imported at runtime: the biomarker@@ -39,6 +39,16 @@ if TYPE_CHECKING:# recording. Values unchanged; this only stops them being written out per site.SCORE_FLOOR: float = 1.0SCORE_MAX: float = 10.0+# The per-file columns that carry a score or a share of one. All ``None`` on a+# file health never walked (:func:`file_score_fields`).+SCORE_FIELDS: tuple[str, ...] = (+ "score",+ "defect_score",+ "maintainability_score",+ "performance_score",+ "structure_deduction",+ "history_deduction",+)# Per-category max deduction.CATEGORY_CAPS: dict[str, float] = {@@ -790,6 +800,33 @@ def deduction_split(findings: Iterable[Any]) -> tuple[float, float]:return round(structure, 3), round(history, 3)+def _rounded(value: float | None) -> float | None:+ return round(value, 2) if value is not None else None+++def file_score_fields(+ analysed: bool, scores: dict[str, float | None], findings: Iterable[Any]+) -> dict[str, float | None]:+ """The score columns one file stores, from its scored findings.++ A file health never walked (*analysed* false: its language has no dialect,+ see ``has_health_dialect``) gets ``None`` in every one, since a number+ would be a default dressed as a measurement (a mechanical 10.0). Its+ findings still stand: the history markers read git rather than the parse.+ """+ if not analysed:+ return dict.fromkeys(SCORE_FIELDS)+ structure, history = deduction_split(findings)+ return {+ "score": _rounded(scores["defect"]),+ "defect_score": _rounded(scores["defect"]),+ "maintainability_score": _rounded(scores["maintainability"]),+ "performance_score": _rounded(scores["performance"]),+ "structure_deduction": structure,+ "history_deduction": history,+ }++def unclamped_score(structure: float | None, history: float | None) -> float | None:"""The score a file would carry without the floor, or ``None`` if unrecorded.@@ -852,10 +889,12 @@ def nloc_weighted_attr(rows: list[HealthFileMetricData], attr: str) -> float | Ndef nloc_weighted_score(rows: list[HealthFileMetricData]) -> float:"""NLOC-weighted mean of ``score``, weighting each file by ``max(nloc, 1)``.+ Rows with no score (a language health has no dialect for) are left out.Returns 10.0 for an empty input. Callers that can distinguish "nothing toaverage" from "averaged to a perfect score" should check emptiness first —:func:`hotspot_health` does exactly that."""+ rows = scored_rows(rows)if not rows:return 10.0total_w = sum(_weight(r) for r in rows)@@ -882,19 +921,50 @@ def hotspot_health(*hotspot_paths* is the set git flagged ``is_hotspot``: top-quartile churn**and** the absolute activity floors from issue #361.- ``None`` means the repo has no hotspot files at all, which is a real answer+ ``None`` means the repo has no scored hotspot files at all, which is a real answerand not a failure — a repo with no recent churn has nothing to be a hotspot.It is kept distinct from a low score on purpose: averaging an empty setyields 10.0, and reporting that would tell a user their hotspots are perfectwhen they have none. :func:`compute_kpis` still floors it to 10.0 for thepersisted KPI, and says why there."""- rows = [m for m in metrics if field(m, "file_path") in hotspot_paths]+ rows = [m for m in scored_rows(metrics) if field(m, "file_path") in hotspot_paths]if not rows:return Nonereturn round(nloc_weighted_score(rows), 2)+def _empty_kpis(unanalysed: int) -> dict[str, object]:+ """KPIs with no scored file. An empty repository keeps its historical 10.0+ floors (the snapshot columns need a number); a repository whose files are+ all unscored has no average to report, so its headline is ``None``."""+ floor = None if unanalysed else SCORE_MAX+ return {+ "hotspot_health": floor,+ "average_health": floor,+ "unanalysed_file_count": unanalysed,+ "worst_performer_path": None,+ "worst_performer_score": None,+ "worst_test_path": None,+ "worst_test_score": None,+ "file_count": 0,+ **dict.fromkeys(+ (+ "maintainability_average",+ "maintainability_hotspot",+ "performance_average",+ "performance_hotspot",+ "structure_average",+ "structure_hotspot",+ "history_average",+ "history_hotspot",+ "production_average",+ )+ ),+ "production_file_count": 0,+ }++def compute_kpis(metrics: list[HealthFileMetricData],hotspot_paths: set[str],@@ -918,29 +988,16 @@ def compute_kpis(one is holding the score down. ``None`` until files carry the split.- ``production_average``: ``average_health`` over non-test files, weightedidentically, so a narrowed view and a narrowed trend agree.+ - ``unanalysed_file_count``: files stored with no score because health has+ no dialect for their language. Every KPI above leaves them out; when no+ file is scored at all, the two headline averages are ``None``."""+ metrics, unanalysed = split_unscored(metrics)if not metrics:- return {- "hotspot_health": 10.0,- "average_health": 10.0,- "worst_performer_path": None,- "worst_performer_score": None,- "worst_test_path": None,- "worst_test_score": None,- "file_count": 0,- "maintainability_average": None,- "maintainability_hotspot": None,- "performance_average": None,- "performance_hotspot": None,- "structure_average": None,- "structure_hotspot": None,- "history_average": None,- "history_hotspot": None,- "production_average": None,- "production_file_count": 0,- }+ return _empty_kpis(unanalysed)hotspots = [m for m in metrics if field(m, "file_path") in hotspot_paths]+production, tests = split_tests(metrics)# Production first; a test file names the worst only in a tests-only repo.worst = min(production or metrics, key=_row_score)@@ -977,4 +1034,5 @@ def compute_kpis(round(nloc_weighted_score(production), 2) if production else None),"production_file_count": len(production),+ "unanalysed_file_count": unanalysed,}diff --git a/packages/core/src/repowise/core/analysis/health/trends.py b/packages/core/src/repowise/core/analysis/health/trends.pyindex e0f7e6e0d..2650c18db 100644--- a/packages/core/src/repowise/core/analysis/health/trends.py+++ b/packages/core/src/repowise/core/analysis/health/trends.py@@ -37,6 +37,7 @@ from datetime import datetimefrom functools import lru_cachefrom typing import Any, TypeAlias+from .rows import scored_rowsfrom .scoring import SCORE_FLOOR, SCORE_MAXDECLINE_THRESHOLD: float = 0.5@@ -493,6 +494,7 @@ def snapshot_file_maps((deepest is 12.91 of a possible 13.5), and recording the pre-cap suminstead would be recording a number the score was never computed from."""+ metrics = scored_rows(metrics)per_file_scores = {m.file_path: round(float(m.score), 2) for m in metrics}totals: dict[str, float] = {}@@ -510,6 +512,33 @@ def snapshot_file_maps(return per_file_scores, per_file_deductions+def snapshot_fields(+ kpis: dict[str, Any], metrics: list[Any], findings: list[Any]+) -> dict[str, Any] | None:+ """``save_health_snapshot``'s keyword arguments for one health report.++ ``None`` when no file carries a score (every file is in a language health+ has no dialect for): a trend point would chart a 10.0 nobody measured.+ Shared by the three snapshot writers for the reason+ :func:`snapshot_file_maps` gives.+ """+ if "average_health" in kpis and kpis["average_health"] is None:+ return None+ scores_map, deductions_map = snapshot_file_maps(metrics, findings)+ return {+ "hotspot_health": float(kpis.get("hotspot_health", SCORE_MAX)),+ "average_health": float(kpis.get("average_health", SCORE_MAX)),+ "worst_performer_path": kpis.get("worst_performer_path"),+ "worst_performer_score": kpis.get("worst_performer_score"),+ "per_file_scores": scores_map,+ "per_file_deductions": deductions_map,+ "structure_average": kpis.get("structure_average"),+ "history_average": kpis.get("history_average"),+ "production_average": kpis.get("production_average"),+ "maintainability_average": kpis.get("maintainability_average"),+ }++#: One normalized snapshot reading for a single file: when it was taken, the#: clamped score, and the recorded pre-clamp deduction where the reading#: captured one. The storage-neutral input to :func:`build_file_points`.diff --git a/packages/core/src/repowise/core/generation/editor_files/fetcher.py b/packages/core/src/repowise/core/generation/editor_files/fetcher.pyindex 7144d06e0..ba965b434 100644--- a/packages/core/src/repowise/core/generation/editor_files/fetcher.py+++ b/packages/core/src/repowise/core/generation/editor_files/fetcher.py@@ -18,7 +18,7 @@ from sqlalchemy.ext.asyncio import AsyncSessionfrom repowise.core.analysis.finding_registry import excluded_typesfrom repowise.core.analysis.health.grading import BAND_LABEL, band_forfrom repowise.core.analysis.health.perf.coverage import coverage_for_metrics-from repowise.core.analysis.health.rows import split_tests+from repowise.core.analysis.health.rows import scored_rows, split_testsfrom repowise.core.analysis.health.scoring import hotspot_health, nloc_weighted_scorefrom repowise.core.analysis.health.trends import DECLINE_LOOKBACK, hotspot_trendfrom repowise.core.entry_candidacy import conventional_entry_stems@@ -360,7 +360,9 @@ class EditorFileDataFetcher:KPIs, then the lead of the Fix-first queue every other surface renders.``None`` when no health data yet."""- metric_rows = list(+ # Scored rows only: a file in a language health has no dialect for+ # carries no score, and a repository of nothing else has no block.+ metric_rows = scored_rows((await self._session.execute(select(HealthFileMetric).where(diff --git a/packages/core/src/repowise/core/persistence/crud/analysis/__init__.py b/packages/core/src/repowise/core/persistence/crud/analysis/__init__.pyindex f7b4a6d55..fe14e0801 100644--- a/packages/core/src/repowise/core/persistence/crud/analysis/__init__.py+++ b/packages/core/src/repowise/core/persistence/crud/analysis/__init__.py@@ -71,6 +71,7 @@ from .health import (HealthSnapshotScalars,backfill_is_test,backfill_module_attribution,+ clear_unanalysed_scores,get_average_health,get_deduction_by_path,get_file_language_map,@@ -130,6 +131,7 @@ __all__ = ["HealthSnapshotScalars","backfill_is_test","backfill_module_attribution",+ "clear_unanalysed_scores","count_refactoring_suggestions","coverage_by_module","coverage_row_dict",diff --git a/packages/core/src/repowise/core/persistence/crud/analysis/health.py b/packages/core/src/repowise/core/persistence/crud/analysis/health.pyindex c993cfca1..05a2c61fc 100644--- a/packages/core/src/repowise/core/persistence/crud/analysis/health.py+++ b/packages/core/src/repowise/core/persistence/crud/analysis/health.py@@ -16,6 +16,7 @@ if TYPE_CHECKING:from ....analysis.health.perf.coverage import PerfCoveragefrom ....analysis.finding_registry import excluded_types+from ....analysis.health.complexity.languages import has_health_dialectfrom ....analysis.health.finding_identity import (finding_public_id,legacy_finding_public_id,@@ -30,9 +31,9 @@ from ....analysis.health.ranking import (sort_metrics_worst_first,worst_metric,)-from ....analysis.health.rows import detail_map, split_tests+from ....analysis.health.rows import detail_map, split_tests, split_unscoredfrom ....analysis.health.scope import scores_language-from ....analysis.health.scoring import ADVISORY_DIMENSION, nloc_weighted_attr+from ....analysis.health.scoring import ADVISORY_DIMENSION, SCORE_FIELDS, nloc_weighted_attrfrom ....test_paths import is_test_related_pathfrom ...models import (DocDriftFinding,@@ -205,13 +206,18 @@ async def replace_governance_findings(await _insert_keeping_triage(session, repository_id, findings, scope)+def _opt(cast: Any, value: Any) -> Any:+ """*value* through *cast*, keeping ``None`` (a file health never walked)."""+ return None if value is None else cast(value)++def _health_metric_row_data(metric: Any) -> dict:"""One metric dataclass as column values. Both writers go through here."""return {"file_path": metric.file_path,- "score": float(metric.score),- "max_ccn": int(metric.max_ccn),- "max_nesting": int(metric.max_nesting),+ "score": _opt(float, metric.score),+ "max_ccn": _opt(int, metric.max_ccn),+ "max_nesting": _opt(int, metric.max_nesting),"nloc": int(metric.nloc),"duplication_pct": metric.duplication_pct,"has_test_file": bool(metric.has_test_file),@@ -342,6 +348,34 @@ async def prune_unscored_health_rows(session: AsyncSession, repository_id: str)return removed+async def clear_unanalysed_scores(session: AsyncSession, repository_id: str) -> int:+ """Drop the numbers stored for files in a language health has no dialect for.++ A store written before such files were left unscored holds a 10.0 and a+ max_ccn of 1 for each, which every average would keep counting until a full+ rescore. The answer comes from the language alone, so an update fixes it in+ place, git history or not. Files with no graph node are left alone, as in+ ``prune_unscored_health_rows``. Returns the number of rows cleared.+ """+ languages = await get_file_language_map(session, repository_id)+ paths = [p for p, lang in languages.items() if lang and not has_health_dialect(lang)]+ cleared = 0+ for i in range(0, len(paths), _BATCH_SIZE):+ rows = await session.execute(+ select(HealthFileMetric).where(+ HealthFileMetric.repository_id == repository_id,+ HealthFileMetric.file_path.in_(paths[i : i + _BATCH_SIZE]),+ HealthFileMetric.score.is_not(None),+ )+ )+ for row in rows.scalars().all():+ for name in (*SCORE_FIELDS, "max_ccn", "max_nesting"):+ setattr(row, name, None)+ cleared += 1+ await session.flush()+ return cleared++async def backfill_module_attribution(session: AsyncSession,repository_id: str,@@ -617,14 +651,9 @@ async def get_average_health(session: AsyncSession, repository_id: str) -> float),await _health_exclude_spec(session, repository_id),)- if not rows:- return None- total_nloc = sum(max(r.nloc, 1) for r in rows)- if total_nloc:- avg = sum(r.score * max(r.nloc, 1) for r in rows) / total_nloc- else:- avg = sum(r.score for r in rows) / len(rows)- return round(avg, 2)+ # Files with no score (no health dialect for their language) are skipped,+ # so a repository of nothing else reads unmeasured, never 10.0.+ return _rounded(nloc_weighted_attr(rows, "score"))async def get_file_language_map(session: AsyncSession, repository_id: str) -> dict[str, str]:@@ -675,10 +704,14 @@ async def get_health_summary("""if metrics is None:metrics = await get_health_metrics(session, repository_id)+ # A file in a language health has no dialect for is stored unscored. It is+ # counted apart and left out of every figure below.+ metrics, unanalysed = split_unscored(metrics)if not metrics:return {"file_count": 0,- "average_health": 10.0,+ "unanalysed_file_count": unanalysed,+ "average_health": None if unanalysed else 10.0,"worst_performer_path": None,"worst_performer_score": None,"worst_test_path": None,@@ -699,42 +732,14 @@ async def get_health_summary("worst_performance_path": None,"worst_performance_score": None,}- total_nloc = sum(max(m.nloc, 1) for m in metrics)- if total_nloc:- avg = sum(m.score * max(m.nloc, 1) for m in metrics) / total_nloc- else:- avg = sum(m.score for m in metrics) / len(metrics)-- # Maintainability headline: NLOC-weighted average over the per-file- # maintainability scores (skipping rows that predate the split / lack one).- # ``None`` when no row carries a maintainability score so the surface reads- # "not measured" rather than a misleading 10.0.- maint_scored = [m for m in metrics if getattr(m, "maintainability_score", None) is not None]- maintainability_average: float | None = None- if maint_scored:- maint_nloc = sum(max(m.nloc, 1) for m in maint_scored)- if maint_nloc:- maintainability_average = (- sum(m.maintainability_score * max(m.nloc, 1) for m in maint_scored) / maint_nloc- )- else:- maintainability_average = sum(m.maintainability_score for m in maint_scored) / len(- maint_scored- )+ avg = nloc_weighted_attr(metrics, "score")- # Performance headline: same NLOC-weighted average over the per-file- # performance scores (static performance RISK). ``None`` when no row carries- # a performance score so the surface reads "not measured" rather than 10.0.+ # The two co-surfaced pillars: the same NLOC weighting over their own+ # columns, ``None`` when no row carries one so a surface reads "not+ # measured" rather than a misleading 10.0.+ maintainability_average = nloc_weighted_attr(metrics, "maintainability_score")+ performance_average = nloc_weighted_attr(metrics, "performance_score")perf_scored = [m for m in metrics if getattr(m, "performance_score", None) is not None]- performance_average: float | None = None- if perf_scored:- perf_nloc = sum(max(m.nloc, 1) for m in perf_scored)- if perf_nloc:- performance_average = (- sum(m.performance_score * max(m.nloc, 1) for m in perf_scored) / perf_nloc- )- else:- performance_average = sum(m.performance_score for m in perf_scored) / len(perf_scored)# Worst-performance file: the lowest per-file performance score, surfaced only# when there is genuine risk (score < 10) so a clean repo shows no actionable@@ -782,7 +787,8 @@ async def get_health_summary()return {"file_count": len(metrics),- "average_health": round(avg, 2),+ "unanalysed_file_count": unanalysed,+ "average_health": _rounded(avg),"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,diff --git a/packages/core/src/repowise/core/persistence/database.py b/packages/core/src/repowise/core/persistence/database.pyindex 7ae81763b..0687d60ea 100644--- a/packages/core/src/repowise/core/persistence/database.py+++ b/packages/core/src/repowise/core/persistence/database.py@@ -26,7 +26,7 @@ from sqlalchemy.ext.asyncio import (create_async_engine,)from sqlalchemy.pool import NullPool, StaticPool-from sqlalchemy.schema import CreateIndex+from sqlalchemy.schema import CreateIndex, CreateTablefrom sqlalchemy.sql import textfrom .models import Base@@ -441,6 +441,43 @@ def _run_data_step(step: Callable[[object], object], connection: object) -> Nonestep(connection)+#: Tables a SQLite store rebuilds when a column the model now allows NULL in is+#: still NOT NULL on disk: SQLite cannot relax a constraint in place, and the+#: additive reconciler below never does. Leaf tables only, since nothing may+#: reference a table that is copied, dropped and renamed. Each holds derived+#: rows, so an interrupted rebuild costs a recompute, never source data.+_SQLITE_REBUILD_FOR_NULLABLE: frozenset[str] = frozenset({"health_file_metrics"})+++def _relax_not_null(connection: object, table: object) -> None:+ """Rebuild *table* from the model if a now-nullable column is NOT NULL.++ SQLite's documented procedure: create the new shape under a staging name,+ copy the shared columns, drop the old table, rename, recreate indexes.+ """+ live = {c["name"]: c for c in inspect(connection).get_columns(table.name)} # type: ignore[attr-defined]+ columns = [c for c in table.columns if c.name in live] # type: ignore[attr-defined]+ if not any(c.nullable and not live[c.name]["nullable"] for c in columns):+ return+ name = table.name # type: ignore[attr-defined]+ staging = f"_rebuild_{name}"+ dialect = connection.dialect # type: ignore[attr-defined]+ ddl = str(CreateTable(table).compile(dialect=dialect)) # type: ignore[arg-type]+ quoted = dialect.identifier_preparer.quote(name)+ ddl = ddl.replace(f"CREATE TABLE {quoted} ", f'CREATE TABLE "{staging}" ', 1)+ shared = ", ".join(f'"{c.name}"' for c in columns)+ run = connection.execute # type: ignore[attr-defined]+ run(text(f'DROP TABLE IF EXISTS "{staging}"'))+ run(text(ddl))+ run(text(f'INSERT INTO "{staging}" ({shared}) SELECT {shared} FROM "{name}"'))+ run(text(f'DROP TABLE "{name}"'))+ run(text(f'ALTER TABLE "{staging}" RENAME TO "{name}"'))+ # Indexes went with the old table. Not a per-row loop: one per declared index.+ for index in table.indexes: # type: ignore[attr-defined]+ run(CreateIndex(index))+ log.info("schema_table_rebuilt_for_nullable", table=name)++def _reconcile_schema(connection: object) -> None:"""Bring an existing database up to ``Base.metadata`` (additive only).@@ -544,6 +581,15 @@ def _reconcile_schema(connection: object) -> None:if data_step is not None and not any(name == what for name, _ in failures):_run(f"{what}:data", lambda data_step=data_step: _run_data_step(data_step, connection))+ # --- Nullability (SQLite only) -----------------------------------+ # After the columns, so the copy carries every one of them, and before+ # the indexes, which the rebuild recreates itself.+ if continue_past_failure and table.name in _SQLITE_REBUILD_FOR_NULLABLE:+ _run(+ f"{table.name}:nullable",+ lambda table=table: _relax_not_null(connection, table),+ )+# --- Indexes ---------------------------------------------------# Only model-declared indexes (i.e. ``Index(...)`` on the table# or ``index=True`` on a column) are reconciled. Indexes createddiff --git a/packages/core/src/repowise/core/persistence/models.py b/packages/core/src/repowise/core/persistence/models.pyindex a5b5638d8..f1c15029e 100644--- a/packages/core/src/repowise/core/persistence/models.py+++ b/packages/core/src/repowise/core/persistence/models.py@@ -2126,9 +2126,12 @@ class HealthFileMetric(Base):String(32), ForeignKey("repositories.id", ondelete="CASCADE"), nullable=False)file_path: Mapped[str] = mapped_column(Text, nullable=False)- score: Mapped[float] = mapped_column(Float, nullable=False, default=10.0)- max_ccn: Mapped[int] = mapped_column(Integer, nullable=False, default=0)- max_nesting: Mapped[int] = mapped_column(Integer, nullable=False, default=0)+ # NULL for a file whose language health has no dialect for: nothing walked+ # it, so a number would claim a measurement that never happened. A store+ # created while these were NOT NULL is rebuilt by ``init_db``.+ score: Mapped[float | None] = mapped_column(Float, nullable=True)+ max_ccn: Mapped[int | None] = mapped_column(Integer, nullable=True)+ max_nesting: Mapped[int | None] = mapped_column(Integer, nullable=True)nloc: Mapped[int] = mapped_column(Integer, nullable=False, default=0)duplication_pct: Mapped[float | None] = mapped_column(Float, nullable=True)has_test_file: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)diff --git a/packages/core/src/repowise/core/pipeline/incremental.py b/packages/core/src/repowise/core/pipeline/incremental.pyindex aaf698cf8..16d8481e6 100644--- a/packages/core/src/repowise/core/pipeline/incremental.py+++ b/packages/core/src/repowise/core/pipeline/incremental.py@@ -1197,14 +1197,19 @@ def _numbers_moved(refreshed: Any, stored: Any) -> bool:the split ships backfills it without touching any finding."""return (- round(refreshed.score, 2) != round(float(stored.score), 2)- or stored.structure_deduction is None- or stored.history_deduction is None- or round(refreshed.structure_deduction, 3) != round(float(stored.structure_deduction), 3)- or round(refreshed.history_deduction, 3) != round(float(stored.history_deduction), 3)+ _differs(refreshed.score, stored.score, 2)+ or _differs(refreshed.structure_deduction, stored.structure_deduction, 3)+ or _differs(refreshed.history_deduction, stored.history_deduction, 3))+def _differs(new: float | None, old: float | None, places: int) -> bool:+ """``None`` is a value here: a file that is no longer scored has moved."""+ if new is None or old is None:+ return (new is None) != (old is None)+ return round(new, places) != round(float(old), places)++def _history_findings_moved(refreshed: Any, stored_findings: list[Any]) -> bool:"""Whether the git-derived findings themselves changed.@@ -1234,11 +1239,14 @@ def _refreshed_metric(refreshed: Any, stored: Any) -> dict:complexity and coverage columns, which need a parse — keep their storedvalues instead of being reset to a default."""+ # A file health never walked carries no complexity figures either, which+ # also clears the ones a store written before that rule kept.+ walked = refreshed.score is not Nonereturn {"file_path": refreshed.file_path,"score": refreshed.score,- "max_ccn": stored.max_ccn,- "max_nesting": stored.max_nesting,+ "max_ccn": stored.max_ccn if walked else None,+ "max_nesting": stored.max_nesting if walked else None,"nloc": stored.nloc,"duplication_pct": stored.duplication_pct,"has_test_file": stored.has_test_file,@@ -1350,9 +1358,14 @@ async def persist_partial_health(# average, and rows written before ``is_test`` existed get it from their# path. Both before the refresh, which should not re-score a row that is# about to be deleted.- from repowise.core.persistence.crud import backfill_is_test, prune_unscored_health_rows+ from repowise.core.persistence.crud import (+ backfill_is_test,+ clear_unanalysed_scores,+ prune_unscored_health_rows,+ )await prune_unscored_health_rows(session, repo_id)+ await clear_unanalysed_scores(session, repo_id)await backfill_is_test(session, repo_id)# Then the files this run did not walk, whose git-derived markers the fresh# metadata may have moved. Before the snapshot, or the trend would describediff --git a/packages/core/src/repowise/core/pipeline/persist.py b/packages/core/src/repowise/core/pipeline/persist.pyindex b6c5eb0da..5e3cab2cf 100644--- a/packages/core/src/repowise/core/pipeline/persist.py+++ b/packages/core/src/repowise/core/pipeline/persist.py@@ -1857,7 +1857,7 @@ async def snapshot_health_from_store(session: Any, repo_id: str) -> None:from sqlalchemy import selectfrom repowise.core.analysis.health.scoring import compute_kpis- from repowise.core.analysis.health.trends import snapshot_file_maps+ from repowise.core.analysis.health.trends import snapshot_fieldsfrom repowise.core.persistence.crud import get_hotspot_file_paths, save_health_snapshotfrom repowise.core.persistence.models import HealthFileMetric, HealthFinding@@ -1886,21 +1886,9 @@ async def snapshot_health_from_store(session: Any, repo_id: str) -> None:.all())kpis = compute_kpis(metrics, await get_hotspot_file_paths(session, repo_id))- scores_map, deductions_map = snapshot_file_maps(metrics, findings)- await save_health_snapshot(- session,- repo_id,- hotspot_health=float(kpis.get("hotspot_health", 10.0)),- average_health=float(kpis.get("average_health", 10.0)),- worst_performer_path=kpis.get("worst_performer_path"),- worst_performer_score=kpis.get("worst_performer_score"),- per_file_scores=scores_map,- per_file_deductions=deductions_map,- structure_average=kpis.get("structure_average"),- history_average=kpis.get("history_average"),- production_average=kpis.get("production_average"),- maintainability_average=kpis.get("maintainability_average"),- )+ fields = snapshot_fields(kpis, metrics, findings)+ if fields is not None:+ await save_health_snapshot(session, repo_id, **fields)except Exception as exc:logger.warning("health_snapshot_skipped", error=str(exc))diff --git a/packages/server/src/repowise/server/mcp_server/tool_context/enrichment.py b/packages/server/src/repowise/server/mcp_server/tool_context/enrichment.pyindex df87e3056..86cf75f35 100644--- a/packages/server/src/repowise/server/mcp_server/tool_context/enrichment.py+++ b/packages/server/src/repowise/server/mcp_server/tool_context/enrichment.py@@ -28,6 +28,7 @@ from repowise.core.analysis.doc_drift.serialize import (documents_with_drift,)from repowise.core.analysis.finding_registry import excluded_types+from repowise.core.analysis.health.complexity.languages import NO_DIALECT_STATUSfrom repowise.core.analysis.health.signals import file_signalsfrom repowise.core.ingestion.models import (FILE_DEPENDENCY_EDGE_TYPES,@@ -723,7 +724,9 @@ async def _resolve_health()health: dict[str, Any] = {- "score": round(metric.score, 2),+ "score": round(metric.score, 2) if metric.score is not None else None,+ # Said in words, so a missing score is not read as a missing index.+ **({"analysis_status": NO_DIALECT_STATUS} if metric.score is None else {}),"max_ccn": metric.max_ccn,"max_nesting": metric.max_nesting,"nloc": metric.nloc,diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/dashboard.py b/packages/server/src/repowise/server/mcp_server/tool_health/dashboard.pyindex 348809ad5..8d05d74a8 100644--- a/packages/server/src/repowise/server/mcp_server/tool_health/dashboard.py+++ b/packages/server/src/repowise/server/mcp_server/tool_health/dashboard.py@@ -37,6 +37,7 @@ def build_dashboard(hotspot_paths=data.hotspot_paths,performance_findings=data.perf_findings_count,coverage=data.perf_coverage,+ unanalysed=len(pop.unanalysed_paths),)result: dict[str, Any] = {# The one lead; every block below ranks and describes.@@ -45,6 +46,9 @@ def build_dashboard("scope": pop.reported_scope,"counts": pop.reported_counts,"unscored_files": pop.unscored_files,+ # Files in a language health has no dialect for: no score, so in no+ # figure here. Only said when there are some.+ **({"unanalysed_files": len(pop.unanalysed_paths)} if pop.unanalysed_paths else {}),"kpis": kpis,"distribution": health_distribution(all_metrics),# Where the gap to the target concentrates: a short list of files.diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/population.py b/packages/server/src/repowise/server/mcp_server/tool_health/population.pyindex ed048f26d..b11855548 100644--- a/packages/server/src/repowise/server/mcp_server/tool_health/population.py+++ b/packages/server/src/repowise/server/mcp_server/tool_health/population.py@@ -10,6 +10,7 @@ from sqlalchemy import selectfrom repowise.core.analysis.health.counts import parse_countsfrom repowise.core.analysis.health.counts import project as project_countsfrom repowise.core.analysis.health.models import split_by_origin+from repowise.core.analysis.health.rows import scored_rowsfrom repowise.core.analysis.health.scope import parse_scopefrom repowise.core.persistence.models import HealthFileMetricfrom repowise.server.mcp_server._helpers import _get_exclude_spec, filter_rows_by_attr@@ -29,6 +30,9 @@ class Population:reported_counts: strunscored_files: intunscored_paths: set[str]+ # Files stored with no score because health has no dialect for their+ # language. Out of every block; a target among them says so.+ unanalysed_paths: set[str]file_targets: list[str]matched_modules: set[str]scoped: bool@@ -81,6 +85,12 @@ async def load_population(all_metrics = [m for m in all_metrics if not m.is_test]scope_paths = {m.file_path for m in all_metrics}+ # Before ``counts``, so a file nobody measured is reported as that rather+ # than as a code-shape reading with no recorded split.+ listed = all_metrics+ unanalysed_paths = {m.file_path for m in all_metrics if m.score is None}+ all_metrics = scored_rows(all_metrics)+# Composes with the scope: a re-read off the stored structure/history# split, not a rescore. Findings narrow by origin, not by path, so a row# it cannot read lands in ``unscored_files`` with its findings intact.@@ -93,7 +103,7 @@ async def load_population(unscored_paths = before - {m.file_path for m in all_metrics}file_targets, matched_modules = _expand_module_targets(- all_metrics, req.module_targets, req.file_targets+ listed, req.module_targets, req.file_targets)# Keyed off the raw targets, not the resolved ones: a target that resolves# to nothing must not fall through to repo-wide numbers.@@ -107,6 +117,7 @@ async def load_population(reported_counts=reported_counts,unscored_files=unscored_files,unscored_paths=unscored_paths,+ unanalysed_paths=unanalysed_paths,file_targets=file_targets,matched_modules=matched_modules,scoped=scoped,diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py b/packages/server/src/repowise/server/mcp_server/tool_health/summary.pyindex 9c8f5dad6..e5ddd7610 100644--- a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py+++ b/packages/server/src/repowise/server/mcp_server/tool_health/summary.py@@ -4,6 +4,7 @@ from __future__ import annotationsfrom typing import Any+from repowise.core.analysis.health.complexity.languages import NO_DIALECT_STATUSfrom repowise.core.analysis.health.grading import TARGET_SCORE, band_forfrom repowise.core.analysis.health.models import primary_finding, split_by_originfrom repowise.core.analysis.health.perf.coverage import PerfCoverage@@ -140,13 +141,17 @@ def _compute_kpis(hotspot_paths: set[str] | None = None,performance_findings: int = 0,coverage: PerfCoverage | None = None,+ unanalysed: int = 0,) -> dict[str, Any]:+ """*metrics* are scored rows; *unanalysed* counts the files left out of+ them because health has no dialect for their language."""if not metrics:return {"file_count": 0,"average_health": None,"band": None,- "analysis_status": "unavailable",+ # A repository of only unsupported languages is not missing data.+ "analysis_status": NO_DIALECT_STATUS if unanalysed else "unavailable","hotspot_health": None,"worst_performer_path": None,"worst_performer_score": None,diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/targeted.py b/packages/server/src/repowise/server/mcp_server/tool_health/targeted.pyindex 9d85a745d..12f38cfc6 100644--- a/packages/server/src/repowise/server/mcp_server/tool_health/targeted.py+++ b/packages/server/src/repowise/server/mcp_server/tool_health/targeted.py@@ -59,6 +59,7 @@ def build_targeted(excluded_paths=pop.excluded_paths,unscored_paths=pop.unscored_paths,repo_root=repo_root,+ unanalysed_paths=pop.unanalysed_paths,)if unresolved:result["unresolved"] = unresolveddiff --git a/packages/server/src/repowise/server/mcp_server/tool_health/targets.py b/packages/server/src/repowise/server/mcp_server/tool_health/targets.pyindex c7653e083..d1256dcf6 100644--- a/packages/server/src/repowise/server/mcp_server/tool_health/targets.py+++ b/packages/server/src/repowise/server/mcp_server/tool_health/targets.py@@ -5,6 +5,8 @@ from __future__ import annotationsfrom pathlib import Pathfrom typing import Any+from repowise.core.analysis.health.complexity.languages import NO_DIALECT_STATUS+def _expand_module_targets(metrics: list[Any], module_targets: list[str], file_targets: list[str]@@ -35,6 +37,7 @@ def _unresolved_targets(excluded_paths: set[str],unscored_paths: set[str],repo_root: Any,+ unanalysed_paths: set[str] = frozenset(),) -> list[dict[str, str]]:"""Name every requested target that produced no rows, with a reason.@@ -42,10 +45,18 @@ def _unresolved_targets(reason is actionable: ``not_indexed`` (run ``repowise update``),``no_such_path`` (a typo), ``excluded`` (repo config), ``not_measured``(indexed, but no stored split for the ``counts`` reading; passed in so it- is not misreported as ``not_indexed``).+ is not misreported as ``not_indexed``), ``language_not_supported`` (health+ has no dialect for the file's language, so it carries no score)."""out = [- {"target": t, "reason": _miss_reason(t, excluded_paths, unscored_paths, repo_root)}+ {+ "target": t,+ "reason": (+ NO_DIALECT_STATUS+ if t in unanalysed_paths+ else _miss_reason(t, excluded_paths, unscored_paths, repo_root)+ ),+ }for t in file_targetsif t not in resolved_paths]diff --git a/packages/server/src/repowise/server/mcp_server/tool_overview/health.py b/packages/server/src/repowise/server/mcp_server/tool_overview/health.pyindex a8a9b48d0..ae094c5bd 100644--- a/packages/server/src/repowise/server/mcp_server/tool_overview/health.py+++ b/packages/server/src/repowise/server/mcp_server/tool_overview/health.py@@ -4,6 +4,7 @@ from __future__ import annotationsfrom typing import Any+from repowise.core.analysis.health.complexity.languages import NO_DIALECT_STATUSfrom repowise.core.analysis.health.grading import (band_for,)@@ -28,6 +29,12 @@ async def _build_code_health(session: Any, repository: Any) -> dict[str, Any]:if not metrics_rows:return {}health_summary = await _get_health_summary(session, repository.id, metrics=metrics_rows)+ if health_summary["average_health"] is None:+ # Every file is in a language health has no dialect for.+ return {+ "analysis_status": NO_DIALECT_STATUS,+ "unanalysed_file_count": health_summary["unanalysed_file_count"],+ }# Hotspot health from its one owner, over the rows already loaded.hotspot_paths = await get_hotspot_file_paths(session, repository.id)return {diff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/enrichment.py b/packages/server/src/repowise/server/mcp_server/tool_risk/enrichment.pyindex 526486304..6740bc79b 100644--- a/packages/server/src/repowise/server/mcp_server/tool_risk/enrichment.py+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/enrichment.py@@ -380,7 +380,7 @@ async def _enrich_health(results: list[dict], ctx: Any, repo_id: str) -> None:for r in results:path = r.get("target")m = metric_map.get(path)- if m is not None:+ if m is not None and m.score is not None:r["health_score"] = round(m.score, 2)c = coverage_map.get(path)if c is not None:diff --git a/packages/server/src/repowise/server/routers/code_health/badge.py b/packages/server/src/repowise/server/routers/code_health/badge.pyindex d4a91f87a..ceb1eef54 100644--- a/packages/server/src/repowise/server/routers/code_health/badge.py+++ b/packages/server/src/repowise/server/routers/code_health/badge.py@@ -84,11 +84,14 @@ async def _badge_average_health(session: AsyncSession, repo_id: str) -> float |if repo is None:raise HTTPException(status_code=404, detail="Repository not found")avg = await crud.get_average_health(session, repo_id)+ if avg is not None:+ return avg# A repo with no metrics has always badged as a perfect 10.0 here, because# ``get_health_summary`` returns 10.0 for an empty table. Preserved rather- # than quietly corrected: the crud helper reports "unmeasured" honestly as- # ``None``, and mapping that to 10.0 is this endpoint's existing contract.- return 10.0 if avg is None else avg+ # than quietly corrected: mapping "unmeasured" to 10.0 is this endpoint's+ # existing contract. Rows with no score are another answer: every file is+ # in a language health has no dialect for, and that badges "no data".+ return None if await crud.get_scored_file_paths(session, repo_id) else 10.0@router.get("/api/repos/{repo_id}/health/badge.json", response_model=HealthBadgeResponse)diff --git a/packages/server/src/repowise/server/routers/code_health/coverage_routes.py b/packages/server/src/repowise/server/routers/code_health/coverage_routes.pyindex f2025a1ed..cd74ac791 100644--- a/packages/server/src/repowise/server/routers/code_health/coverage_routes.py+++ b/packages/server/src/repowise/server/routers/code_health/coverage_routes.py@@ -36,6 +36,11 @@ from repowise.server.schemas.patch_coverage import PatchCoverageResponsefrom ._router import router+def _score(m: Any) -> float | None:+ """A file's health score; ``None`` where health has no dialect for it."""+ return round(m.score, 2) if m.score is not None else None++@router.get("/api/repos/{repo_id}/health/coverage",response_model=CoverageResponse,@@ -128,7 +133,7 @@ async def health_coverage(for f in files:m = metric_by_path.get(f["file_path"])if m is not None:- f["health_score"] = round(m.score, 2)+ f["health_score"] = _score(m)f["nloc"] = m.nloc# Always over the repo-wide read, never over ``files``: this is what the@@ -268,7 +273,7 @@ async def _inferred_coverage({"file_path": m.file_path,"reached": m.file_path in reached,- "health_score": round(m.score, 2),+ "health_score": _score(m),"nloc": m.nloc,}for m in rows[:limit]diff --git a/packages/server/src/repowise/server/routers/code_health/file_filters.py b/packages/server/src/repowise/server/routers/code_health/file_filters.pyindex 0ef6cae15..e20c0c214 100644--- a/packages/server/src/repowise/server/routers/code_health/file_filters.py+++ b/packages/server/src/repowise/server/routers/code_health/file_filters.py@@ -48,6 +48,7 @@ def metric_filter(return Falseif only_untested and m.has_test_file:return False- return not (only_failing and m.score >= GOOD_MIN)+ # A file with no score (no health dialect for its language) is not failing.+ return not (only_failing and (m.score is None or m.score >= GOOD_MIN))return keepdiff --git a/packages/server/src/repowise/server/routers/code_health/files_routes.py b/packages/server/src/repowise/server/routers/code_health/files_routes.pyindex 1808e9740..42aea7d9c 100644--- a/packages/server/src/repowise/server/routers/code_health/files_routes.py+++ b/packages/server/src/repowise/server/routers/code_health/files_routes.py@@ -157,7 +157,13 @@ async def file_score_breakdown(# the findings the page had just said were excluded.metrics, findings, _unscored = project(counts, metrics, findings)metric = metrics[0] if metrics else None- breakdown = _score_breakdown_from_findings(findings)+ # No breakdown of a score the file does not have (no health dialect for+ # its language): one rebuilt from its findings would read 10.0.+ breakdown = (+ None+ if metric is not None and metric.score is None+ else _score_breakdown_from_findings(findings)+ )finding_dicts = await _attach_symbol_ids(session, repo_id, [_finding_to_dict(f) for f in findings])diff --git a/packages/server/src/repowise/server/routers/code_health/refactoring_routes.py b/packages/server/src/repowise/server/routers/code_health/refactoring_routes.pyindex 97b68be42..1a5433bd0 100644--- a/packages/server/src/repowise/server/routers/code_health/refactoring_routes.py+++ b/packages/server/src/repowise/server/routers/code_health/refactoring_routes.py@@ -247,8 +247,9 @@ async def _queue_targets(# Absent means either filtered out above, or a file this reading# cannot score: under ``code_shape``, a row with no recorded split.# Ranking that on a stand-in 10.0 would put an unmeasured file at the- # top of a list ordered by how bad things are.- if m is None:+ # top of a list ordered by how bad things are. The same holds for a+ # file in a language health has no dialect for, stored with no score.+ if m is None or m.score is None:continueif _is_history_only(fs, q, history):history_only += 1diff --git a/packages/server/src/repowise/server/routers/code_health/serializers.py b/packages/server/src/repowise/server/routers/code_health/serializers.pyindex dec36260a..5bda516d1 100644--- a/packages/server/src/repowise/server/routers/code_health/serializers.py+++ b/packages/server/src/repowise/server/routers/code_health/serializers.py@@ -78,7 +78,8 @@ def _metric_to_dict(# Built in the historical key order so the full row stays byte-identical.out: dict = {"file_path": m.file_path,- "score": round(m.score, 2),+ # ``None`` for a language health has no dialect for: nothing measured it.+ "score": _round_opt(m.score),"max_ccn": m.max_ccn,"max_nesting": m.max_nesting,}diff --git a/packages/server/src/repowise/server/routers/files.py b/packages/server/src/repowise/server/routers/files.pyindex ea8949c20..72bf1c833 100644--- a/packages/server/src/repowise/server/routers/files.py+++ b/packages/server/src/repowise/server/routers/files.py@@ -306,7 +306,12 @@ async def file_detail()health = {"metric": _metric_to_dict(metric, _primary_and_magnitude(findings)) if metric else None,- "breakdown": _score_breakdown_from_findings(findings) if findings else None,+ # None for a file with no score: rebuilt from findings it would read 10.0.+ "breakdown": (+ _score_breakdown_from_findings(findings)+ if findings and not (metric is not None and metric.score is None)+ else None+ ),"findings": [_finding_dict(f, slim=slim) for f in findings],"trend": _file_trend_to_dict(file_trend(snapshots, file_path)),"signals": _file_signals_to_dict(file_signals(git_meta, degrees)),diff --git a/packages/server/src/repowise/server/routers/overview.py b/packages/server/src/repowise/server/routers/overview.pyindex 1905ad500..7805bc210 100644--- a/packages/server/src/repowise/server/routers/overview.py+++ b/packages/server/src/repowise/server/routers/overview.py@@ -551,6 +551,8 @@ async def overview_summary(},"health": {"average_health": health_summary.get("average_health"),+ # Files in a language health has no dialect for: in no figure here.+ "unanalysed_file_count": health_summary.get("unanalysed_file_count", 0),"hotspot_health": hotspot_health_value,"worst_performer_path": health_summary.get("worst_performer_path"),"worst_performer_score": health_summary.get("worst_performer_score"),diff --git a/packages/server/src/repowise/server/routers/symbols.py b/packages/server/src/repowise/server/routers/symbols.pyindex c63903c70..24d907449 100644--- a/packages/server/src/repowise/server/routers/symbols.py+++ b/packages/server/src/repowise/server/routers/symbols.py@@ -409,7 +409,11 @@ async def symbol_detail(git_meta = await crud.get_git_metadata(session, repo_id, sym.file_path)file_context = {"file_path": sym.file_path,- "health_score": round(file_metrics[0].score, 2) if file_metrics else None,+ "health_score": (+ round(file_metrics[0].score, 2)+ if file_metrics and file_metrics[0].score is not None+ else None+ ),"is_hotspot": bool(git_meta.is_hotspot) if git_meta else None,"primary_owner": git_meta.primary_owner_name if git_meta else None,"language": sym.language,diff --git a/tests/unit/cli/test_status_storage.py b/tests/unit/cli/test_status_storage.pyindex 4163cb754..025c27e7f 100644--- a/tests/unit/cli/test_status_storage.py+++ b/tests/unit/cli/test_status_storage.py@@ -20,3 +20,16 @@ def test_index_storage_bytes_sums_repowise_files(tmp_path: Path) -> None:def test_index_storage_bytes_missing_dir() -> None:assert status_cmd._index_storage_bytes(Path("/no/such/repowise/dir")) == 0+++def test_health_line_for_a_repo_with_no_scored_file(monkeypatch) -> None:+ """Every file is in a language health has no dialect for: say so, never crash."""+ from repowise.cli.commands import status_cmd++ monkeypatch.setattr(+ status_cmd,+ "_query_health",+ lambda _path: {"average_health": None, "unanalysed_file_count": 2992},+ )+ line = status_cmd._query_health_line(Path("."))+ assert line is not None and "not analysed" in line and "2992" in linediff --git a/tests/unit/health/test_snapshot_writers_agree.py b/tests/unit/health/test_snapshot_writers_agree.pyindex ec179a513..cd1bd96a6 100644--- a/tests/unit/health/test_snapshot_writers_agree.py+++ b/tests/unit/health/test_snapshot_writers_agree.py@@ -61,6 +61,9 @@ def test_every_writer_records_the_depth_as_well_as_the_score() -> None:missing = []for path, call in _snapshot_calls():kwargs = {kw.arg for kw in call.keywords}+ # ``**fields`` is ``trends.snapshot_fields``, which carries both maps.+ if None in kwargs:+ continueif not {"per_file_scores", "per_file_deductions"} <= kwargs:missing.append(f"{path.name}:{call.lineno} passes {sorted(kwargs)}")assert not missing, "snapshot writers that would record a different history: " + "; ".join(diff --git a/tests/unit/health/test_unanalysed_languages.py b/tests/unit/health/test_unanalysed_languages.pynew file mode 100644index 000000000..8d7b58ffe--- /dev/null+++ b/tests/unit/health/test_unanalysed_languages.py@@ -0,0 +1,200 @@+"""A file in a language health has no dialect for carries no score.++Nothing walks such a file, so a 10.0 would read as "perfect" when it means+"nobody looked". It is stored unscored and left out of every figure.+"""++from __future__ import annotations++from types import SimpleNamespace++import pytest++from repowise.core.analysis.health.complexity import FileComplexity, walk_file+from repowise.core.analysis.health.complexity.languages import has_health_dialect+from repowise.core.analysis.health.duplication import DuplicationReport+from repowise.core.analysis.health.engine import HealthAnalyzer+from repowise.core.analysis.health.grading import distribution+from repowise.core.analysis.health.models import HealthFileMetricData+from repowise.core.analysis.health.ranking import worst_metric+from repowise.core.analysis.health.scoring import (+ SCORE_FIELDS,+ compute_kpis,+ file_score_fields,+ hotspot_health,+)+from repowise.core.analysis.health.trends import snapshot_fields+from repowise.core.pipeline.incremental import _numbers_moved++[email protected]("language", ["python", "typescript", "csharp", "razor", "sql"])+def test_languages_health_walks_have_a_dialect(language: str) -> None:+ assert has_health_dialect(language)++[email protected]("language", ["php", "swift", "elixir", "markdown", "", None])+def test_languages_nothing_walks_have_none(language: str | None) -> None:+ assert not has_health_dialect(language)+++def _metric(path: str, score: float | None, nloc: int = 10, **kw) -> HealthFileMetricData:+ return HealthFileMetricData(+ file_path=path,+ score=score,+ max_ccn=None if score is None else 3,+ max_nesting=None if score is None else 1,+ nloc=nloc,+ has_test_file=False,+ defect_score=score,+ **kw,+ )+++def _evaluate(path: str, language: str, source: bytes, tmp_path) -> HealthFileMetricData:+ abs_path = tmp_path / path.rsplit("/", 1)[-1]+ abs_path.write_bytes(source)+ fcx = walk_file(str(abs_path), language, source)+ pf = SimpleNamespace(+ file_info=SimpleNamespace(+ path=path, language=language, abs_path=str(abs_path), is_test=False+ ),+ symbols=[],+ )+ metric, _, _ = HealthAnalyzer(graph=None)._evaluate_file(+ pf, fcx, paired_tests=set(), package_roots=set(), disabled=[], dup_report=DuplicationReport()+ )+ return metric+++def test_a_php_file_is_stored_with_no_score_and_no_complexity(tmp_path) -> None:+ metric = _evaluate("src/Big.php", "php", b"<?php\nfunction f($a) { if ($a) { return 1; } }\n", tmp_path)+ assert metric.score is None+ assert metric.max_ccn is None and metric.max_nesting is None+ assert all(getattr(metric, name) is None for name in SCORE_FIELDS)+ # What is not a measurement of code shape is still recorded.+ assert metric.nloc > 0+++def test_a_python_file_still_scores(tmp_path) -> None:+ """Control: a language with a dialect is scored exactly as before."""+ source = b"def f(a):\n if a:\n return 1\n return 2\n"+ if walk_file("/tmp/x.py", "python", source).file_nloc == 0:+ pytest.skip("python tree-sitter pack missing")+ metric = _evaluate("src/ok.py", "python", source, tmp_path)+ assert metric.score == 10.0+ assert metric.max_ccn == 2+++def test_score_fields_are_all_none_without_a_dialect() -> None:+ scores = {"defect": 7.5, "maintainability": 8.0, "performance": 10.0}+ assert file_score_fields(False, scores, []) == dict.fromkeys(SCORE_FIELDS)+ fields = file_score_fields(True, scores, [])+ assert fields["score"] == 7.5 and fields["maintainability_score"] == 8.0+++def test_kpis_leave_unscored_files_out() -> None:+ rows = [+ _metric("a.py", 4.0, nloc=100),+ _metric("b.py", 8.0, nloc=100),+ # Huge and unscored: counted as 10.0 it would drag the average to ~9.+ _metric("Big.php", None, nloc=10_000),+ ]+ kpis = compute_kpis(rows, {"a.py", "Big.php"})+ assert kpis["average_health"] == 6.0+ assert kpis["hotspot_health"] == 4.0+ assert kpis["file_count"] == 2+ assert kpis["unanalysed_file_count"] == 1+ assert kpis["worst_performer_path"] == "a.py"+++def test_a_repository_of_only_unscored_files_has_no_average() -> None:+ kpis = compute_kpis([_metric("A.php", None), _metric("B.php", None)], {"A.php"})+ assert kpis["average_health"] is None+ assert kpis["hotspot_health"] is None+ assert kpis["unanalysed_file_count"] == 2+ # No trend point for a number nobody measured.+ assert snapshot_fields(kpis, [_metric("A.php", None)], []) is None+++def test_an_empty_repository_keeps_its_old_kpis() -> None:+ """Control: no rows at all is not the same answer as no scored rows."""+ kpis = compute_kpis([], set())+ assert kpis["average_health"] == 10.0+ assert snapshot_fields(kpis, [], []) is not None+++def test_unscored_files_are_never_the_worst_or_a_hotspot() -> None:+ rows = [_metric("Big.php", None), _metric("a.py", 9.0)]+ assert worst_metric(rows, {}).file_path == "a.py"+ assert worst_metric([_metric("Big.php", None)], {}) is None+ assert hotspot_health(rows, {"Big.php"}) is None+++def test_unscored_files_have_no_band() -> None:+ dist = distribution([_metric("Big.php", None), _metric("a.py", 9.0)])+ assert sum(band["files"] for band in dist["bands"].values()) == 1+++def test_snapshot_score_map_skips_unscored_files() -> None:+ rows = [_metric("Big.php", None), _metric("a.py", 9.0)]+ fields = snapshot_fields(compute_kpis(rows, set()), rows, [])+ assert fields is not None+ assert fields["per_file_scores"] == {"a.py": 9.0}+++def test_an_update_clears_a_stored_ten_for_an_unscored_file() -> None:+ """A store written before this kept 10.0; the history refresh replaces it."""+ stored = SimpleNamespace(score=10.0, structure_deduction=0.0, history_deduction=0.0)+ refreshed = SimpleNamespace(score=None, structure_deduction=None, history_deduction=None)+ assert _numbers_moved(refreshed, stored)+ stored_none = SimpleNamespace(score=None, structure_deduction=None, history_deduction=None)+ assert not _numbers_moved(refreshed, stored_none)+++def test_walk_of_an_unsupported_language_is_empty() -> None:+ """Why the score is meaningless: no function is ever measured."""+ fcx = walk_file("/tmp/x.php", "php", b"<?php\nfunction f() { if (1) {} }\n")+ assert isinstance(fcx, FileComplexity)+ assert fcx.functions == []+++def test_get_health_names_an_unscored_target_for_what_it_is(tmp_path) -> None:+ from repowise.server.mcp_server.tool_health.targets import _unresolved_targets++ (tmp_path / "Big.php").write_text("<?php\n")+ out = _unresolved_targets(+ file_targets=["Big.php"],+ module_targets=[],+ matched_modules=set(),+ resolved_paths=set(),+ excluded_paths=set(),+ unscored_paths=set(),+ repo_root=tmp_path,+ unanalysed_paths={"Big.php"},+ )+ assert out == [{"target": "Big.php", "reason": "language_not_supported"}]+++def _refresh(language: str | None, stored_score: float | None):+ from repowise.core.analysis.health.history_refresh import refresh_history++ metric = _metric("src/a.py", stored_score)+ languages = {} if language is None else {"src/a.py": language}+ (out,) = refresh_history(+ metrics=[metric],+ findings_by_path={},+ git_meta_by_path={"src/a.py": {"commit_count_90d": 1}},+ languages=languages,+ )+ return out+++def test_the_history_refresh_nulls_a_language_with_no_dialect() -> None:+ assert _refresh("php", 10.0).score is None+++def test_a_file_with_no_graph_node_keeps_its_score() -> None:+ """A missing language is not evidence the file was never walked."""+ assert _refresh(None, 7.5).score is not None+ assert _refresh(None, None).score is None+ assert _refresh("python", 7.5).score is not Nonediff --git a/tests/unit/persistence/test_actions_loader.py b/tests/unit/persistence/test_actions_loader.pyindex 41142a9c2..c9f2bd009 100644--- a/tests/unit/persistence/test_actions_loader.py+++ b/tests/unit/persistence/test_actions_loader.py@@ -63,8 +63,8 @@ async def _seed(session) -> str:[GitMetadata(repository_id=rid, file_path="src/core.py", commit_count_90d=12,last_commit_at=ANCHOR - timedelta(days=1), bug_magnet=True),- HealthFileMetric(repository_id=rid, file_path="src/core.py", max_ccn=12, nloc=300,- is_test=False),+ HealthFileMetric(repository_id=rid, file_path="src/core.py", score=10.0, max_ccn=12,+ nloc=300, is_test=False),HealthFinding(repository_id=rid, file_path="src/core.py", biomarker_type="change_entropy",severity="high", health_impact=3.0),HealthFinding(repository_id=rid, file_path="src/core.py", biomarker_type="complex_method",diff --git a/tests/unit/persistence/test_health_metric_nullable_rebuild.py b/tests/unit/persistence/test_health_metric_nullable_rebuild.pynew file mode 100644index 000000000..76749c82f--- /dev/null+++ b/tests/unit/persistence/test_health_metric_nullable_rebuild.py@@ -0,0 +1,121 @@+"""A SQLite store made while the score columns were NOT NULL is rebuilt.++Local stores never run Alembic and the reconciler is additive, so without the+rebuild such a store would reject the unscored row of a file in a language+health has no dialect for, and the whole metrics write would fail.+"""++from __future__ import annotations++from sqlalchemy import text++from repowise.core.analysis.health.models import HealthFileMetricData+from repowise.core.persistence.crud import (+ clear_unanalysed_scores,+ get_health_metrics,+ save_health_metrics,+)+from repowise.core.persistence.database import init_db+from repowise.core.persistence.models import GraphNode+from tests.unit.persistence.helpers import insert_repo+++def _row(path: str, score: float | None) -> HealthFileMetricData:+ return HealthFileMetricData(+ file_path=path,+ score=score,+ max_ccn=None if score is None else 4,+ max_nesting=None if score is None else 2,+ nloc=12,+ has_test_file=False,+ )+++async def _not_null(session, column: str) -> bool:+ rows = (await session.execute(text("PRAGMA table_info(health_file_metrics)"))).all()+ return next(bool(r[3]) for r in rows if r[1] == column)+++async def test_a_not_null_store_is_rebuilt_and_keeps_its_rows(async_engine, async_session):+ ddl = (+ await async_session.execute(+ text("SELECT sql FROM sqlite_master WHERE name = 'health_file_metrics'")+ )+ ).scalar_one()+ for column, kind in (("score", "FLOAT"), ("max_ccn", "INTEGER"), ("max_nesting", "INTEGER")):+ # Anchored on the leading tab: ``score`` is also the tail of ``defect_score``.+ assert f"\t{column} {kind}," in ddl+ ddl = ddl.replace(f"\t{column} {kind},", f"\t{column} {kind} NOT NULL,")+ await async_session.execute(text("DROP TABLE health_file_metrics"))+ await async_session.execute(text(ddl))+ repo = await insert_repo(async_session)+ await save_health_metrics(async_session, repo.id, [_row("a.py", 7.5)])+ await async_session.commit()+ assert await _not_null(async_session, "score")++ await init_db(async_engine)++ assert not await _not_null(async_session, "score")+ assert not await _not_null(async_session, "max_ccn")+ await save_health_metrics(async_session, repo.id, [_row("a.py", 7.5), _row("B.php", None)])+ await async_session.commit()+ by_path = {m.file_path: m for m in await get_health_metrics(async_session, repo.id)}+ assert by_path["a.py"].score == 7.5 and by_path["a.py"].max_ccn == 4+ assert by_path["B.php"].score is None and by_path["B.php"].max_ccn is None+ # Still one row per file: the unique constraint came back with the table.+ ddl_after = (+ await async_session.execute(+ text("SELECT sql FROM sqlite_master WHERE name = 'health_file_metrics'")+ )+ ).scalar_one()+ assert "uq_health_file_metrics" in ddl_after+++async def test_a_current_store_is_left_alone(async_engine, async_session):+ """Control: nothing to relax means no rebuild, and the rows are untouched."""+ repo = await insert_repo(async_session)+ await save_health_metrics(async_session, repo.id, [_row("a.py", 7.5)])+ await async_session.commit()+ before = (await async_session.execute(text("SELECT id FROM health_file_metrics"))).all()+ await init_db(async_engine)+ after = (await async_session.execute(text("SELECT id FROM health_file_metrics"))).all()+ assert before == after+ assert not await _not_null(async_session, "score")+++async def _with_languages(session, repo_id: str, languages: dict[str, str]) -> None:+ session.add_all(+ GraphNode(repository_id=repo_id, node_id=p, node_type="file", language=lang)+ for p, lang in languages.items()+ )+ await session.flush()+++async def test_an_update_clears_a_stored_ten_for_a_language_with_no_dialect(async_session):+ """A store written before this kept 10.0 / CCN 1 for every PHP file."""+ repo = await insert_repo(async_session)+ await save_health_metrics(+ async_session,+ repo.id,+ [_row("Big.php", 10.0), _row("ok.py", 7.5), _row("orphan.py", 6.0)],+ )+ # ``orphan.py`` has no graph node: no language, so it is left alone.+ await _with_languages(async_session, repo.id, {"Big.php": "php", "ok.py": "python"})+ assert await clear_unanalysed_scores(async_session, repo.id) == 1+ by_path = {m.file_path: m for m in await get_health_metrics(async_session, repo.id)}+ assert by_path["Big.php"].score is None and by_path["Big.php"].max_ccn is None+ assert by_path["ok.py"].score == 7.5+ assert by_path["orphan.py"].score == 6.0+ assert await clear_unanalysed_scores(async_session, repo.id) == 0+++async def test_the_badge_says_no_data_when_no_file_is_scored(async_session):+ from repowise.server.routers.code_health.badge import _badge_average_health++ repo = await insert_repo(async_session)+ # No rows at all keeps the endpoint's historical 10.0.+ assert await _badge_average_health(async_session, repo.id) == 10.0+ await save_health_metrics(async_session, repo.id, [_row("Big.php", None)])+ assert await _badge_average_health(async_session, repo.id) is None+ await save_health_metrics(async_session, repo.id, [_row("Big.php", None), _row("a.py", 8.0)])+ assert await _badge_average_health(async_session, repo.id) == 8.0diff --git a/tests/unit/server/test_health_excludes.py b/tests/unit/server/test_health_excludes.pyindex bfb54ce08..57af62829 100644--- a/tests/unit/server/test_health_excludes.py+++ b/tests/unit/server/test_health_excludes.py@@ -88,6 +88,7 @@ async def test_health_reads_honor_repo_settings_excludes(session, tmp_path) -> Nassert await get_health_findings(session, repo.id, file_path="tools/gen.py") == []assert summary == {"file_count": 1,+ "unanalysed_file_count": 0,"average_health": 8.5,"worst_performer_path": "src/app.py","worst_performer_score": 8.5,diff --git a/tests/unit/test_no_hotspot_health_copies.py b/tests/unit/test_no_hotspot_health_copies.pyindex 6a4979eb9..ed3526bca 100644--- a/tests/unit/test_no_hotspot_health_copies.py+++ b/tests/unit/test_no_hotspot_health_copies.py@@ -47,12 +47,10 @@ _PLUMBING: dict[str, str] = {"repowise/server/schemas/repository.py": "the response field","repowise/server/schemas/code_health.py": "the trend response fields","alembic/versions/0019_code_health.py": "the migration that adds the column",- # --- writers: hand ``compute_kpis`` output to the snapshot ---------------- "repowise/core/pipeline/persist.py": "persists the KPI dict from the health report",- "repowise/cli/commands/health_cmd/persist.py": "same, for `repowise health`",- "repowise/cli/commands/upgrade_flow.py": "same, for `repowise upgrade`",# --- trend surfaces: diff recorded snapshots, no current value ------------ "repowise/core/analysis/health/trends.py": "diffs snapshots; owns no current value",+ "repowise/core/analysis/health/trends.py": (+ "diffs snapshots and builds the snapshot writers' arguments; owns no current value"+ ),"repowise/server/routers/code_health/trends_routes.py": "serves the snapshot series","repowise/cli/commands/health_cmd/trends.py": "prints the snapshot series","repowise/server/mcp_server/tool_health/blocks.py": "renders get_health's snapshot diff",