Skip to content

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

fix(change-risk): treat text templates as data, not unanalysed code (#3767)

Swati Ahuja2e69e3243ed4
diff --git a/docs/reference/MCP_RESPONSE_FIELDS.md b/docs/reference/MCP_RESPONSE_FIELDS.md
index 9be9c814c..e5665332b 100644
--- a/docs/reference/MCP_RESPONSE_FIELDS.md
+++ b/docs/reference/MCP_RESPONSE_FIELDS.md
@@ -260,7 +260,7 @@ Every float is rounded to 4 significant digits. Direct rows' `structural_score`
`include=["diagnostics"]` adds `score` (the raw 0 to 10 number), `fallback_band`, `risk_authority`, `score_measures`, `score_unit`, `baseline_sample_size`, `features` and `drivers`, plus `health_delta.analyzer` (analyzer and rules fingerprint), `health_delta.base` and `health_delta.head` (the two resolved revisions) and `health_delta.limits`. `include=["scales"]` adds each field's unit, range and calibration.
-**health_delta.** Both revisions are analysed from their own content, and a finding at head is reported only when the diff explains it. `scope` counts changed, eligible, analysed, skipped and failed files; `status` is `available`, `partial` or `unavailable`, and `partial` is never a clean bill. Documentation and configuration files (Markdown, JSON, YAML, TOML and the other doc or config extensions) are skipped with reason `not_code` and never make a run `partial`; a change made only of them reads `clear_in_analyzed_scope` with a headline saying health analysis does not cover them. Tree-sitter query files (`.scm` under a `queries` directory) are skipped with reason `not_analyzable_data`, which also never makes a run `partial`; a change made only of them reads `clear_in_analyzed_scope` with its own headline, since they can still change behaviour. HTML, schema and other files with no health dialect still make a run `partial`. `introduced`, `worsened` and `resolved` are totals; `top_findings` holds the three most actionable, with `findings_total`. Each finding names `dimension`, `biomarker`, `severity`, `path`, `symbol`, head-side `lines`, a `reason`, and an `attribution` (`basis` of `added_lines`, `changed_symbol`, `changed_call_edge`, `new_file`, `file_change`, `context_change` or `unknown`, with a `confidence`). Identity ignores line numbers, so moved code introduces nothing. `inspect` gives the `finding_id` call that expands one; ids are bound to the two revisions. A finding that matches a stored one carries `health_reference` for `get_health(finding_id=...)`. Performance findings carry `opportunity_id` and are ordered by opportunity rank.
+**health_delta.** Both revisions are analysed from their own content, and a finding at head is reported only when the diff explains it. `scope` counts changed, eligible, analysed, skipped and failed files; `status` is `available`, `partial` or `unavailable`, and `partial` is never a clean bill. Documentation and configuration files (Markdown, JSON, YAML, TOML and the other doc or config extensions) are skipped with reason `not_code` and never make a run `partial`; a change made only of them reads `clear_in_analyzed_scope` with a headline saying health analysis does not cover them. Tree-sitter query files (`.scm` under a `queries` directory) and text templates (`.j2`, `.jinja`, `.jinja2`, `.tmpl`, `.tpl`, `.hbs`, `.mustache`, `.ejs`, `.njk`) are skipped with reason `not_analyzable_data`, which also never makes a run `partial`; a change made only of them reads `clear_in_analyzed_scope` with its own headline, since they can still change behaviour. HTML, schema and other files with no health dialect still make a run `partial`. `introduced`, `worsened` and `resolved` are totals; `top_findings` holds the three most actionable, with `findings_total`. Each finding names `dimension`, `biomarker`, `severity`, `path`, `symbol`, head-side `lines`, a `reason`, and an `attribution` (`basis` of `added_lines`, `changed_symbol`, `changed_call_edge`, `new_file`, `file_change`, `context_change` or `unknown`, with a `confidence`). Identity ignores line numbers, so moved code introduces nothing. `inspect` gives the `finding_id` call that expands one; ids are bound to the two revisions. A finding that matches a stored one carries `health_reference` for `get_health(finding_id=...)`. Performance findings carry `opportunity_id` and are ordered by opportunity rank.
**impacted_tests.** The same selection `repowise impacted-tests` makes over the whole change (every touched path, whatever the score's filters). `status` is `selected` or `run_all` (or `no_index`, `unknown`, `config_invalid`, `timeout`, `busy`, `no_source_line_changes` when nothing was selected, each with `run_all` true; `timeout` means the selection took over 30 seconds and `busy` that one for this repository is still running, and `repowise impacted-tests` gives the answer); `run_all` true means no subset can be vouched for, with up to three `reasons` (`reasons_total` counts them all). `tests_to_run` (capped at ten, `total` and `truncated`) is in `repowise impacted-tests`' [run order](CLI_REFERENCE.md#repowise-impacted-tests-revspec), the `always_run_total` tests that run with every subset last; `why` gives each listed file's reason. With `run_all` the list is what to run first. `tests_to_run_kind` is `test_id` when a coverage node id is listed, else `test_file`. `basis` is `measured` when coverage decided a changed file, `inferred` when only the graph or a rule did, `none` when nothing named a test; `basis_by_file` names the evidence per changed file (`coverage`, `changed-test`, `call-graph`, `import-graph`, `conftest`, `full-run`, `no-tests-needed`, ...). With a coverage map, `map_present` is true and `line_coverage` buckets the scored files' changed lines, matched on the side of the diff the map was measured at (by file when it was measured at neither): `untested_changes`, `stale_test_candidates` (covered lines whose test file is absent from the diff), `covered`, `no_coverage_data`. Build the measured map with `coverage run --contexts=test` and `repowise coverage add`.
diff --git a/packages/core/src/repowise/core/analysis/change_health/models.py b/packages/core/src/repowise/core/analysis/change_health/models.py
index 2de2b8cbf..19a816424 100644
--- a/packages/core/src/repowise/core/analysis/change_health/models.py
+++ b/packages/core/src/repowise/core/analysis/change_health/models.py
@@ -46,8 +46,8 @@ SEVERITY_RANK: dict[str, int] = {"low": 0, "medium": 1, "high": 2, "critical": 3
#: Documentation or configuration: skipped, but no code went unexamined.
NOT_CODE = "not_code"
-#: Tree-sitter queries and similar data: no detector reads them, yet they can
-#: change behaviour, so they are named apart from docs and config.
+#: Tree-sitter queries, text templates and similar data: no detector reads
+#: them, yet they can change behaviour, so they are named apart from docs and config.
NOT_ANALYZABLE_DATA = "not_analyzable_data"
#: Skip reasons that leave no code unexamined.
diff --git a/packages/core/src/repowise/core/analysis/change_health/service.py b/packages/core/src/repowise/core/analysis/change_health/service.py
index cebaf3d9a..eb5bf0c2d 100644
--- a/packages/core/src/repowise/core/analysis/change_health/service.py
+++ b/packages/core/src/repowise/core/analysis/change_health/service.py
@@ -14,7 +14,7 @@ from collections import OrderedDict
from dataclasses import dataclass
from pathlib import PurePosixPath
-from ...support_paths import is_doc_or_config_path
+from ...support_paths import TEMPLATE_EXTENSIONS, is_doc_or_config_path
from ...test_paths import is_test_related_path
from ..finding_registry import excluded_types, gate_for, is_served, language_label
from ..health import HEALTH_ANALYZER_VERSION, HealthFindingData
@@ -402,7 +402,10 @@ def _nothing_compared(changes: list[FileChange], skipped: dict[str, str]) -> str
"health analysis does not cover them."
)
if all(r in NO_CODE_GAP for r in skipped.values()):
- return "Only query or other data files changed; health analysis does not cover them."
+ return (
+ "Only query, template or other data files changed; "
+ "health analysis does not cover them."
+ )
return "No changed file is health-analyzable, so nothing was compared."
@@ -415,7 +418,10 @@ def _skip_reason(change: FileChange) -> str:
return NOT_CODE
if language is None:
path = PurePosixPath(change.head_path)
- if path.suffix.lower() == _QUERY_SUFFIX and _QUERY_DIR in path.parts[:-1]:
+ suffix = path.suffix.lower()
+ if suffix in TEMPLATE_EXTENSIONS or (
+ suffix == _QUERY_SUFFIX and _QUERY_DIR in path.parts[:-1]
+ ):
return NOT_ANALYZABLE_DATA
return "unsupported_language"
return "not_health_analyzable"
diff --git a/packages/core/src/repowise/core/analysis/review_directive.py b/packages/core/src/repowise/core/analysis/review_directive.py
index 6b3200e68..0b9128002 100644
--- a/packages/core/src/repowise/core/analysis/review_directive.py
+++ b/packages/core/src/repowise/core/analysis/review_directive.py
@@ -123,7 +123,7 @@ def _plural(word: str, count: int) -> str:
def _no_code_headline(delta: ChangeHealthDelta) -> str:
if NOT_ANALYZABLE_DATA in delta.skipped.values():
return (
- "No code changed: only query or other data files, which health analysis "
+ "No code changed: only query, template or other data files, which health analysis "
"does not cover. They can still change behaviour, so test selection still applies."
)
return (
diff --git a/packages/core/src/repowise/core/analysis/selection_scopes.py b/packages/core/src/repowise/core/analysis/selection_scopes.py
index b36f1a9d0..e411e9782 100644
--- a/packages/core/src/repowise/core/analysis/selection_scopes.py
+++ b/packages/core/src/repowise/core/analysis/selection_scopes.py
@@ -42,7 +42,7 @@ from pathlib import PurePosixPath
import pathspec
-from ..support_paths import DOC_EXTENSIONS
+from ..support_paths import DOC_EXTENSIONS, TEMPLATE_EXTENSIONS
from ..test_paths import is_test_related_path
from .test_selection import (
JS_SUFFIXES,
@@ -113,7 +113,7 @@ _ECOSYSTEM_SPECS = tuple(
# it may be a pinned dependency list.
_OWNED = frozenset(
{".md", ".mdx", ".rst", ".adoc", ".markdown", ".html", ".htm"}
- | {".j2", ".jinja", ".jinja2", ".tmpl", ".tpl", ".hbs", ".mustache", ".ejs", ".njk"}
+ | TEMPLATE_EXTENSIONS
| {".css", ".scss", ".sass", ".less"}
| {".svg", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico"}
)
diff --git a/packages/core/src/repowise/core/support_paths.py b/packages/core/src/repowise/core/support_paths.py
index eadae58b0..2c32a5dcd 100644
--- a/packages/core/src/repowise/core/support_paths.py
+++ b/packages/core/src/repowise/core/support_paths.py
@@ -93,6 +93,11 @@ CONFIG_EXTENSIONS = frozenset(
}
)
DOC_EXTENSIONS = frozenset({".md", ".mdx", ".rst", ".txt", ".adoc"})
+# Text templates (Jinja, Handlebars, Mustache, EJS, Nunjucks, Go and generic
+# ``.tmpl``/``.tpl``): rendered by code, never parsed as code here.
+TEMPLATE_EXTENSIONS = frozenset(
+ {".j2", ".jinja", ".jinja2", ".tmpl", ".tpl", ".hbs", ".mustache", ".ejs", ".njk"}
+)
def classification_token(path: str) -> str:
diff --git a/tests/unit/change_health/test_comparison.py b/tests/unit/change_health/test_comparison.py
index e162472c2..9623b727c 100644
--- a/tests/unit/change_health/test_comparison.py
+++ b/tests/unit/change_health/test_comparison.py
@@ -634,3 +634,27 @@ def test_a_scheme_file_outside_queries_is_still_a_gap(make_repo):
assert delta.skipped == {"src/main.scm": "unsupported_language"}
assert delta.code_skipped == {"src/main.scm": "unsupported_language"}
+
+
[email protected]("path", ["templates/page.j2", "views/card.hbs", "tpl/email.tmpl"])
+def test_a_template_change_is_data_not_a_gap(make_repo, path):
+ repo = make_repo()
+ repo.commit("seed", {path: "Hello {{ name }}\n"})
+ repo.commit("edit", {path: "Hi {{ name }}\n"})
+
+ delta = compare(repo)
+
+ assert delta.skipped == {path: "not_analyzable_data"}
+ assert delta.code_skipped == {}
+ assert "template" in delta.explanation
+
+
+def test_a_template_beside_code_does_not_make_the_run_partial(make_repo):
+ repo = make_repo()
+ repo.commit("seed", {"app.py": "x = 1\n", "templates/page.j2": "{{ a }}\n"})
+ repo.commit("edit", {"app.py": "x = 2\n", "templates/page.j2": "{{ b }}\n"})
+
+ delta = compare(repo)
+
+ assert delta.status == "available"
+ assert delta.code_skipped == {}