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(code-origin): classify Visual C++ resource headers as generated (#3842)

Yushu Lic4618130fc34
diff --git a/packages/core/src/repowise/core/code_origin.py b/packages/core/src/repowise/core/code_origin.py
index fdf089745..46f7fc6ee 100644
--- a/packages/core/src/repowise/core/code_origin.py
+++ b/packages/core/src/repowise/core/code_origin.py
@@ -117,6 +117,8 @@ _GENERATED_SENTENCE_RE = re.compile(
# lines. Only the whole line counts: "Do not modify by hand without ..." or
# "Generated code: see docs" in a hand-written file says something else.
_GENERATED_BANNER_LINE_RE = re.compile(r"^GENERATED CODE - DO NOT MODIFY BY HAND\s*$")
+# Visual Studio rewrites resource headers, but ingestion must keep their include edges.
+_VISUAL_CPP_BANNER_LINE_RE = re.compile(r"^MICROSOFT VISUAL C\+\+ GENERATED INCLUDE FILE\.?\s*$")
_GENERATED_SENTENCE_LINES = 40
_PREAMBLE_PREFIXES = ("package ", "import ", "from ", "using ")
@@ -188,7 +190,11 @@ def _leading_generated_sentence(header: str) -> bool:
def _says_generated(text: str) -> bool:
- return bool(_GENERATED_SENTENCE_RE.search(text) or _GENERATED_BANNER_LINE_RE.search(text))
+ return bool(
+ _GENERATED_SENTENCE_RE.search(text)
+ or _GENERATED_BANNER_LINE_RE.search(text)
+ or _VISUAL_CPP_BANNER_LINE_RE.search(text)
+ )
def _above_import(lines: list[str], i: int) -> bool:
diff --git a/tests/unit/test_code_origin.py b/tests/unit/test_code_origin.py
index fce438dc4..20f92b4f0 100644
--- a/tests/unit/test_code_origin.py
+++ b/tests/unit/test_code_origin.py
@@ -177,6 +177,42 @@ def test_generated_banner_negatives() -> None:
assert not is_generated_header("a = 1\nb = 2\n# DO NOT EDIT\n")
[email protected]("period", [".", ""])
[email protected]("path", ["src/modules/ZoomIt/ZoomIt/resource.h", "src/app/resource.h"])
+def test_visual_cpp_resource_header_is_generated_without_skipping_ingestion(
+ path: str, period: str
+) -> None:
+ text = (
+ "//{{NO_DEPENDENCIES}}\n"
+ f"// Microsoft Visual C++ generated include file{period}\n"
+ "// Used by ZoomIt.rc\n"
+ "//\n"
+ "//////////////////////////////\n"
+ "// Non-localizable\n"
+ "\n"
+ '#define FILE_DESCRIPTION "Sysinternals Screen Magnifier"\n'
+ '#define INTERNAL_NAME "ZoomIt"\n'
+ '#define ORIGINAL_FILENAME "PowerToys.ZoomIt.exe"\n'
+ )
+ assert code_origin(path, text) == "generated"
+ # The resource IDs must remain in the graph for their includers.
+ assert not is_generated_header(text)
+
+
+ "comment",
+ [
+ "Workaround for a Microsoft Visual C++ generated warning",
+ "Workaround for Microsoft Visual C++ generated include file.",
+ "Microsoft Visual C++ generated include file. See the workaround below.",
+ ],
+)
+def test_visual_cpp_banner_like_prose_stays_production(comment: str) -> None:
+ text = f"//{{{{NO_DEPENDENCIES}}}}\n// {comment}\n#define RESOURCE_ID 101\n"
+ assert code_origin("src/app/resource.h", text) == "production"
+ assert not is_generated_header(text)
+
+
_ES_EVALUATOR = (
"// Copyright Elasticsearch B.V. Licensed under the Elastic License 2.0.\n"
"package org.elasticsearch.xpack.esql.expression;\n"