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(generation): a file page drops the sections it cannot fill (#1206)

Swati Ahujadc857ca32196
diff --git a/packages/core/src/repowise/core/generation/templates/file_page.j2 b/packages/core/src/repowise/core/generation/templates/file_page.j2
index c5de7c116..f3688fc57 100644
--- a/packages/core/src/repowise/core/generation/templates/file_page.j2
+++ b/packages/core/src/repowise/core/generation/templates/file_page.j2
@@ -9,6 +9,14 @@
symbols, its neighbours' file paths and its layer in full, because those
are the identifiers a question embeds near. Nobody reads a file page end
to end, so where readability and retrieval disagree, retrieval wins.
+
+ Every section below the Overview is conditional. A heading with nothing
+ under it costs a reader a stop and puts the same stock sentence into the
+ search index on thousands of pages, where it matches every query and
+ distinguishes none of them. The Overview is the one exception: it is
+ generated rather than looked up, so it always has something to say, and
+ ``_extract_summary`` reads it back as the summary shown in search results
+ and the wiki list.
-#}
{%- set public_syms = ctx.symbols | selectattr("visibility", "equalto", "public") | list -%}
# {{ ctx.file_path }}
@@ -16,35 +24,51 @@
## Overview
{% if ctx.docstring %}{{ ctx.docstring | as_markdown }}{% else %}`{{ ctx.file_path }}` is a {{ ctx.language }} {% if ctx.is_entry_point %}entry-point {% endif %}{% if ctx.is_test %}test {% endif %}source file{% if ctx.kg_layer_name %} in the {{ ctx.kg_layer_name }} layer{% endif %}{% if ctx.community_label %}, part of the {{ ctx.community_label }} module cluster{% endif %}.{% endif %}
+{%- if public_syms %}
-{% if public_syms %}It exposes {{ public_syms | length }} public symbol{{ "s" if public_syms | length != 1 else "" }}{% if ctx.dependencies %} and depends on {{ ctx.dependencies | length }} other file{{ "s" if ctx.dependencies | length != 1 else "" }}{% endif %}.{% endif %}
+It exposes {{ public_syms | length }} public symbol{{ "s" if public_syms | length != 1 else "" }}{% if ctx.dependencies %} and depends on {{ ctx.dependencies | length }} other file{{ "s" if ctx.dependencies | length != 1 else "" }}{% endif %}.
## Public API
-{% if public_syms %}| Symbol | Kind | Signature |
+| Symbol | Kind | Signature |
| --- | --- | --- |
-{% for s in public_syms %}| `{{ s.name }}` | {{ s.kind }} | {{ (s.signature or "") | signature | replace("|", "\\|") }} |
-{% endfor %}{% else %}_No public symbols were extracted from this file._
-{% endif %}
+{%- for s in public_syms %}
+| `{{ s.name }}` | {{ s.kind }} | {{ (s.signature or "") | signature | replace("|", "\\|") }} |
+{%- endfor %}
+{%- endif %}
+{%- if ctx.dependencies %}
+
## Depends on
+{% for dep in ctx.dependencies[:25] %}
+- `{{ dep }}`
+{%- endfor %}
+{%- if ctx.dependencies | length > 25 %}
-{% if ctx.dependencies %}{% for dep in ctx.dependencies[:25] %}- `{{ dep }}`
-{% endfor %}{% if ctx.dependencies | length > 25 %}
_and {{ ctx.dependencies | length - 25 }} more._
-{% endif %}{% else %}_No internal dependencies resolved._
-{% endif %}
+{%- endif %}
+{%- endif %}
+{%- if ctx.dependents %}
+
## Used by
-{% if ctx.dependents %}Imported by {{ ctx.dependents | length }} file{{ "s" if ctx.dependents | length != 1 else "" }} in this repository.
+Imported by {{ ctx.dependents | length }} file{{ "s" if ctx.dependents | length != 1 else "" }} in this repository.
+{% for dep in ctx.dependents[:25] %}
+- `{{ dep }}`
+{%- endfor %}
+{%- if ctx.dependents | length > 25 %}
-{% for dep in ctx.dependents[:25] %}- `{{ dep }}`
-{% endfor %}{% if ctx.dependents | length > 25 %}
_and {{ ctx.dependents | length - 25 }} more._
-{% endif %}{% else %}_No internal callers were resolved for this file._
-{% endif %}
-{% if ctx.community_label or ctx.kg_layer_name %}## Usage Notes
-
-{% if ctx.community_label %}Part of the **{{ ctx.community_label }}** module cluster.
-{% endif %}{% if ctx.kg_layer_name %}**Layer:** {{ ctx.kg_layer_name }}{% if ctx.kg_layer_role %} | **Role:** {{ ctx.kg_layer_role }}{% endif %}
-{% endif %}
-{% endif %}{% include "_footer.j2" %}
+{%- endif %}
+{%- endif %}
+{%- if ctx.community_label or ctx.kg_layer_name %}
+
+## Usage Notes
+{% if ctx.community_label %}
+Part of the **{{ ctx.community_label }}** module cluster.
+{%- endif %}
+{%- if ctx.kg_layer_name %}
+**Layer:** {{ ctx.kg_layer_name }}{% if ctx.kg_layer_role %} | **Role:** {{ ctx.kg_layer_role }}{% endif %}
+{%- endif %}
+{%- endif %}
+
+{% include "_footer.j2" %}
diff --git a/tests/unit/generation/test_templates.py b/tests/unit/generation/test_templates.py
index 7af65e046..c06685751 100644
--- a/tests/unit/generation/test_templates.py
+++ b/tests/unit/generation/test_templates.py
@@ -118,6 +118,85 @@ def test_file_page_contains_file_path(jinja_env, file_page_ctx):
assert file_page_ctx.file_path in result
[email protected](scope="module")
+def bare_file_page_ctx() -> FilePageContext:
+ """A file the graph knows nothing about: no symbols, no edges, no docstring.
+
+ Config files, data files and the unparsed tail of a large repo all land
+ here, so this is not a corner case — it is a large share of the file pages
+ a real wiki contains.
+ """
+ return FilePageContext(
+ file_path="python_pkg/settings.py",
+ language="python",
+ docstring=None,
+ symbols=[],
+ imports=[],
+ exports=[],
+ file_source_snippet="DEBUG = False",
+ pagerank_score=0.0,
+ betweenness_score=0.0,
+ community_id=0,
+ dependents=[],
+ dependencies=[],
+ is_api_contract=False,
+ is_entry_point=False,
+ is_test=False,
+ parse_errors=[],
+ estimated_tokens=10,
+ )
+
+
+def test_file_page_omits_a_section_it_cannot_fill(jinja_env, bare_file_page_ctx):
+ """A heading with nothing under it is worse than no heading.
+
+ An empty section still costs a reader a stop and still puts its words into
+ the search index, where the same four sentences repeated across thousands
+ of pages are noise that matches everything and distinguishes nothing.
+ """
+ result = render(jinja_env, "file_page.j2", bare_file_page_ctx)
+ assert "## Public API" not in result
+ assert "## Depends on" not in result
+ assert "## Used by" not in result
+
+
+def test_file_page_keeps_the_sections_it_can_fill(jinja_env, file_page_ctx):
+ """The other half of the rule: a populated file still renders everything."""
+ result = render(jinja_env, "file_page.j2", file_page_ctx)
+ assert "## Overview" in result
+ assert "## Public API" in result
+ assert "## Depends on" in result
+ assert "## Used by" in result
+
+
+def test_file_page_leaves_no_gap_where_a_section_was_dropped(
+ jinja_env, file_page_ctx, bare_file_page_ctx
+):
+ """Dropping a section must not leave the blank lines that framed it.
+
+ Every section is conditional, so the run of blank lines between two of them
+ depends on which ones rendered. Asserting the invariant here is what stops
+ a later edit from silently reintroducing the gaps.
+ """
+ for ctx in (file_page_ctx, bare_file_page_ctx):
+ result = render(jinja_env, "file_page.j2", ctx)
+ assert "\n\n\n" not in result
+ assert not result.startswith("\n")
+
+
+def test_file_page_always_says_what_the_file_is(jinja_env, bare_file_page_ctx):
+ """Overview stays unconditional — it is generated, so it is never empty.
+
+ It is also what ``_extract_summary`` reads back as the page summary shown
+ in search results and the wiki list, so a file page without it would be a
+ blank row there.
+ """
+ result = render(jinja_env, "file_page.j2", bare_file_page_ctx)
+ assert "## Overview" in result
+ assert bare_file_page_ctx.file_path in result
+ assert "_No " not in result
+
+
# ---------------------------------------------------------------------------
# module_page.j2
# ---------------------------------------------------------------------------