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(generation): a symbol spotlight drops the importers section when empty (#1207)
Swati Ahujac76b2f5ba926
diff --git a/packages/core/src/repowise/core/generation/templates/symbol_spotlight.j2 b/packages/core/src/repowise/core/generation/templates/symbol_spotlight.j2index 4903e2e7f..f7a0ef5ce 100644--- a/packages/core/src/repowise/core/generation/templates/symbol_spotlight.j2+++ b/packages/core/src/repowise/core/generation/templates/symbol_spotlight.j2@@ -4,47 +4,53 @@the containing module, not verified call sites. The LLM template hedgesthe same way; a template that claimed otherwise would over-state what thegraph actually knows.++ Every section but the Overview is conditional: a heading with nothing+ under it costs a reader a stop and repeats a stock sentence across+ thousands of pages, where it matches every query and distinguishes none.++ The Overview is the exception, and its no-docstring sentence stays even+ though it reads like a placeholder. It is what ``_extract_summary`` reads+ back as the page summary, and it names the symbol, its kind and its file —+ the identifiers this page exists to carry. Deleting it would blank the+ summary for every undocumented symbol.-#}# {{ ctx.qualified_name }}**Kind:** {{ ctx.kind }}{% if ctx.is_async %} (async){% endif %} | **Defined in:** `{{ ctx.file_path }}`{% if ctx.complexity_estimate %} | **Estimated complexity:** {{ ctx.complexity_estimate }}{% endif %}+{%- if ctx.signature %}-{% if ctx.signature %}```{{ ctx.signature }}```-{% endif %}+{%- endif %}## Overview-{% if ctx.docstring %}{{ ctx.docstring | as_markdown }}-{% else %}`{{ ctx.symbol_name }}` is {{ "an" if ctx.kind and ctx.kind[0] in "aeiou" else "a" }} {{ ctx.kind or "symbol" }} defined in `{{ ctx.file_path }}`. It carries no docstring.{% endif %}+{% if ctx.docstring %}{{ ctx.docstring | as_markdown }}{% else %}`{{ ctx.symbol_name }}` is {{ "an" if ctx.kind and ctx.kind[0] in "aeiou" else "a" }} {{ ctx.kind or "symbol" }} defined in `{{ ctx.file_path }}`. It carries no docstring.{% endif %}+{%- if ctx.decorators %}-{% if ctx.decorators %}## Decorators{% for d in ctx.decorators %}- `{{ d }}`-{% endfor %}-{% endif %}+{%- endfor %}+{%- endif %}+{%- if ctx.callers %}-{% if ctx.callers %}## Where it is used-{{ ctx.callers | length }} file{{ "s" if ctx.callers | length != 1 else "" }} import the module that defines it. These are import-level references, not confirmed call sites.+{{ ctx.callers | length }} file{{ "s" if ctx.callers | length != 1 else "" }} import{{ "" if ctx.callers | length != 1 else "s" }} the module that defines it. These are import-level references, not confirmed call sites.{% for c in ctx.callers %}- `{{ c }}`-{% endfor %}-{% else %}-## Where it is used+{%- endfor %}+{%- endif %}+{%- if ctx.source_body %}-No importers of the defining module were resolved.-{% endif %}--{% if ctx.source_body %}## Implementation```{{ ctx.source_body }}```-{% endif %}+{%- endif %}+{% include "_footer.j2" %}diff --git a/tests/unit/generation/test_templates.py b/tests/unit/generation/test_templates.pyindex c06685751..2865c0fc4 100644--- a/tests/unit/generation/test_templates.py+++ b/tests/unit/generation/test_templates.py@@ -318,6 +318,78 @@ def test_symbol_spotlight_contains_symbol_name(jinja_env, symbol_spotlight_ctx):assert symbol_spotlight_ctx.symbol_name in result[email protected](scope="module")+def unimported_spotlight_ctx() -> SymbolSpotlightContext:+ """A symbol nothing in the repository imports, and with no docstring.++ Both halves matter: the importer list is what the dropped section was+ reporting on, and the missing docstring is what the Overview has to cover+ for on its own.+ """+ return SymbolSpotlightContext(+ symbol_name="_normalise",+ qualified_name="python_pkg.calculator._normalise",+ kind="function",+ signature="def _normalise(value: str) -> str:",+ docstring=None,+ file_path="python_pkg/calculator.py",+ decorators=[],+ is_async=False,+ complexity_estimate=1,+ callers=[],+ )+++def test_spotlight_omits_the_importers_section_when_nothing_imports_it(+ jinja_env, unimported_spotlight_ctx+):+ """No importers is not a fact worth a heading of its own."""+ result = render(jinja_env, "symbol_spotlight.j2", unimported_spotlight_ctx)+ assert "## Where it is used" not in result+ assert "No importers" not in result+++def test_spotlight_keeps_the_importers_section_when_it_has_importers(+ jinja_env, symbol_spotlight_ctx+):+ """The other half: a symbol with importers still lists them, still hedged.++ The hedge is load-bearing. ``callers`` holds files importing the defining+ module, not verified call sites, and the sentence has to keep saying so.+ """+ result = render(jinja_env, "symbol_spotlight.j2", symbol_spotlight_ctx)+ assert "## Where it is used" in result+ assert "`main.py`" in result+ assert "not confirmed call sites" in result+ # The count and its verb have to agree; one importer is the common case.+ assert "1 file imports the module" in result+++def test_spotlight_still_describes_a_symbol_that_has_no_docstring(+ jinja_env, unimported_spotlight_ctx+):+ """The Overview sentence stays even though it reads like a placeholder.++ It is the page summary — ``_extract_summary`` skips the metadata line and+ the signature fence and lands on it — and it names the symbol, its kind and+ its file, which is the identifier-bearing text the page exists to carry.+ Deleting it would blank the summary for every undocumented symbol.+ """+ result = render(jinja_env, "symbol_spotlight.j2", unimported_spotlight_ctx)+ assert "## Overview" in result+ assert "_normalise" in result+ assert "python_pkg/calculator.py" in result+++def test_spotlight_leaves_no_gap_where_a_section_was_dropped(+ jinja_env, symbol_spotlight_ctx, unimported_spotlight_ctx+):+ for ctx in (symbol_spotlight_ctx, unimported_spotlight_ctx):+ result = render(jinja_env, "symbol_spotlight.j2", ctx)+ assert "\n\n\n" not in result+ assert not result.startswith("\n")++# ---------------------------------------------------------------------------# architecture_diagram.j2# ---------------------------------------------------------------------------