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(ingestion): only treat a generated-file banner as generated (#1731)

Sloe2ea539bc46ca
diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.py
index cb02ab88c..b10bed964 100644
--- a/packages/core/src/repowise/core/ingestion/traverser.py
+++ b/packages/core/src/repowise/core/ingestion/traverser.py
@@ -978,17 +978,26 @@ def _looks_minified(abs_path: Path) -> bool | None:
def _is_generated(abs_path: Path) -> bool:
- """Return True if the file appears to be auto-generated."""
+ """Return True if the file appears to be auto-generated.
+
+ A generated-file banner is a header convention: it sits on the first line
+ or two, never buried in a paragraph. Requiring the marker within the first
+ two lines keeps the check off ordinary prose — ``AUTO-GENERATED`` (and the
+ other markers) occur naturally in docblocks that explain a routing or
+ build convention, and substring-matching the whole 512-byte header silently
+ dropped hand-written files from the index.
+ """
name = abs_path.name
if any(name.endswith(sfx) for sfx in _GENERATED_SUFFIXES):
return True
try:
with open(abs_path, encoding="utf-8", errors="ignore") as f:
header = f.read(512)
- header_upper = header.upper()
- return any(marker.upper() in header_upper for marker in _GENERATED_MARKERS)
except OSError:
return False
+ # Only the first two lines count as a banner. A marker on line 3+ is prose.
+ banner = "\n".join(header.splitlines()[:2]).upper()
+ return any(marker.upper() in banner for marker in _GENERATED_MARKERS)
def _is_config_file(language: LanguageTag) -> bool:
diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.py
index 64cac3f31..6eeb0d5a0 100644
--- a/tests/unit/ingestion/test_traverser.py
+++ b/tests/unit/ingestion/test_traverser.py
@@ -11,6 +11,7 @@ from repowise.core.ingestion.traverser import (
FileTraverser,
_compile_gitignore,
_detect_language,
+ _is_generated,
)
@@ -158,7 +159,7 @@ class TestFileTraverser:
) -> None:
(tmp_path / "Assets").mkdir()
(tmp_path / "Assets" / "Scene.unity").write_text("%YAML 1.1\n")
- (tmp_path / "Assets" / "Main.cs").write_text("class Main {}")
+ (tmp_path / "Assets" / "Main.cs").write_text("class Main {}\n")
def _fail_binary(_path: Path) -> bool:
raise AssertionError("Unity asset hit binary detection")
@@ -1069,3 +1070,42 @@ class TestUnknownLanguageFileRecording:
assert traverser.stats.unknown_language_files_truncated is True
# The count stays exact whatever the cap does to the names.
assert traverser.stats.skipped_unknown_language == 6
+
+
+class TestIsGenerated:
+ """The generated-file banner check must not match ordinary prose.
+
+ ``AUTO-GENERATED`` (and the other markers) occur naturally in docblocks
+ that explain a routing or build convention. A banner is a header
+ convention — it sits on the first line or two — so a marker buried in a
+ paragraph must not drop a hand-written file from the index.
+ """
+
+ def test_banner_on_first_line_is_generated(self, tmp_path: Path) -> None:
+ p = tmp_path / "gen.ts"
+ p.write_text("// Code generated by protoc. DO NOT EDIT.\n\nexport const x = 1;\n")
+ assert _is_generated(p) is True
+
+ def test_marker_on_second_line_is_generated(self, tmp_path: Path) -> None:
+ p = tmp_path / "gen.py"
+ p.write_text("#!/usr/bin/env python\n# AUTO-GENERATED — do not edit.\n\nx = 1\n")
+ assert _is_generated(p) is True
+
+ def test_marker_buried_in_prose_is_not_generated(self, tmp_path: Path) -> None:
+ # The exact false positive from the issue: a hand-written endpoint
+ # whose docblock mentions the framework's auto-generated routes.
+ p = tmp_path / "handwritten.ts"
+ p.write_text(
+ "/**\n"
+ " * Widget endpoint.\n"
+ " * Uses a /widget-ops/ prefix to avoid colliding with the\n"
+ " * framework's auto-generated collection routes.\n"
+ " */\n"
+ "export function widgetEndpoint() { return 1 }\n"
+ )
+ assert _is_generated(p) is False
+
+ def test_generated_suffix_still_wins(self, tmp_path: Path) -> None:
+ p = tmp_path / "api_pb2.py"
+ p.write_text("x = 1\n")
+ assert _is_generated(p) is True