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(ingestion): skip Unity state dirs only inside a Unity project (#3866)
Wade74585041e215
diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.pyindex e69acf347..781085574 100644--- a/packages/core/src/repowise/core/ingestion/traverser.py+++ b/packages/core/src/repowise/core/ingestion/traverser.py@@ -240,13 +240,6 @@ _BLOCKED_DIRS: frozenset[str] = frozenset(".eggs","site-packages",".cache",- # Unity generated state / editor data- "Library",- "Temp",- "Logs",- "UserSettings",- "MemoryCaptures",- "Builds",".idea",".vscode",# Test dirs (tests/, spec/, __tests__/, e2e/) are indexed on purpose@@ -352,6 +345,13 @@ _SKIP_GENERATED_CHECK: frozenset[str] = _LANG_REGISTRY.unparseable_data_language#: no evidence: bundlers write one beside their output._OUTPUT_DIR_NAMES: frozenset[str] = frozenset({"build", "coverage", "dist", "target"})+#: Unity generated state and editor data. Pruned only directly inside a Unity+#: project root (see :func:`is_unity_state_dir`): .NET and C++ repos keep+#: source in ``Library/``, ``Logs/`` and ``Builds/`` folders.+_UNITY_STATE_DIR_NAMES: frozenset[str] = frozenset(+ {"Library", "Temp", "Logs", "UserSettings", "MemoryCaptures", "Builds"}+)+#: Languages a build or report writes (bundles, generated C, HTML reports),#: so their files are no evidence that an output-named directory is source._EMITTED_LANGUAGES: frozenset[str] = _SKIP_GENERATED_CHECK | {"c", "cpp", "javascript", "objectivec"}@@ -674,7 +674,7 @@ class FileTraverser:return self._in_blocked_dir(rel_str, dir_ignore)if self._is_dir_ignored(dirname, rel_str, dir_ignore):return True- if dirname in _OUTPUT_DIR_NAMES:+ if dirname in _OUTPUT_DIR_NAMES or dirname in _UNITY_STATE_DIR_NAMES:return self._in_blocked_dir(rel_str, dir_ignore)return False@@ -1480,6 +1480,21 @@ def is_output_dir(abs_dir: Path) -> bool:return False+def is_unity_state_dir(abs_dir: Path) -> bool:+ """Whether *abs_dir* is a Unity state directory (see ``_UNITY_STATE_DIR_NAMES``).++ Its parent must be a Unity project root: ``ProjectSettings/ProjectVersion.txt``,+ or ``ProjectSettings/`` beside ``Assets/``. Checking the parent, not the+ repo root, also covers a Unity project nested in a monorepo.+ """+ if abs_dir.name not in _UNITY_STATE_DIR_NAMES:+ return False+ settings = abs_dir.parent / "ProjectSettings"+ return (settings / "ProjectVersion.txt").is_file() or (+ settings.is_dir() and (abs_dir.parent / "Assets").is_dir()+ )++def _compile_reincluded_patterns(lines: Iterable[str]) -> tuple[re.Pattern[str], ...]:"""Compile '!' gitignore patterns to exact directory matchers.@@ -1600,7 +1615,8 @@ def _is_segment_blocked("""Whether directory segment *part* at *depth* within *dirs* is blocked."""is_blocked_name = part in _BLOCKED_DIRSis_output_name = part in _OUTPUT_DIR_NAMES- if not is_blocked_name and not is_output_name:+ is_unity_name = part in _UNITY_STATE_DIR_NAMES+ if not (is_blocked_name or is_output_name or is_unity_name):return Falsecur_rel = "/".join(dirs[:depth])@@ -1617,6 +1633,8 @@ def _is_segment_blocked(return Trueabs_dir = repo_root.joinpath(*dirs[:depth])+ if is_unity_name:+ return is_unity_state_dir(abs_dir)is_leaf = not is_dir and depth == len(dirs)return _check_output_dir_cached(abs_dir, is_leaf, leaf_name, cache)diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.pyindex 11e193eb4..64ea6f467 100644--- a/tests/unit/ingestion/test_traverser.py+++ b/tests/unit/ingestion/test_traverser.py@@ -16,6 +16,7 @@ from repowise.core.ingestion.traverser import (_detect_language,_is_generated,_scan_package_dir,+ in_blocked_dir,)@@ -179,6 +180,10 @@ class TestFileTraverser:assert not any("__pycache__" in p for p in paths)def test_skips_unity_generated_dirs(self, tmp_path: Path) -> None:+ (tmp_path / "ProjectSettings").mkdir()+ (tmp_path / "ProjectSettings" / "ProjectVersion.txt").write_text(+ "m_EditorVersion: 6000.0.0f1\n"+ )(tmp_path / "Assets" / "Scripts").mkdir(parents=True)(tmp_path / "Assets" / "Scripts" / "Game.cs").write_text("class Game {}")(tmp_path / "Library" / "PackageCache").mkdir(parents=True)@@ -191,6 +196,39 @@ class TestFileTraverser:assert not any(p.startswith("Library/") for p in paths)assert not any(p.startswith("Temp/") for p in paths)+ def test_unity_dir_names_outside_unity_projects_are_indexed(self, tmp_path: Path) -> None:+ files = {+ "MediaBrowser.Controller/Library/ILibraryManager.cs": "interface ILibraryManager {}",+ "MediaBrowser.Controller/Entities/Folder.cs": "class Folder {}",+ "Tools/Builds/BuildInfo.cs": "class BuildInfo {}",+ "Server/Logs/LogFileTask.cs": "class LogFileTask {}",+ }+ for rel, text in files.items():+ (tmp_path / rel).parent.mkdir(parents=True, exist_ok=True)+ (tmp_path / rel).write_text(text, encoding="utf-8")++ paths = {f.path for f in FileTraverser(tmp_path).traverse()}+ assert paths == set(files)+ assert not in_blocked_dir("Tools/Builds/BuildInfo.cs", tmp_path)++ def test_skips_unity_generated_dirs_in_a_nested_unity_project(self, tmp_path: Path) -> None:+ files = {+ "game/ProjectSettings/ProjectVersion.txt": "m_EditorVersion: 6000.0.0f1\n",+ "game/Assets/Player.cs": "class Player {}",+ "game/Library/x.cs": "class X {}",+ "src/Library/y.cs": "class Y {}",+ }+ for rel, text in files.items():+ (tmp_path / rel).parent.mkdir(parents=True, exist_ok=True)+ (tmp_path / rel).write_text(text, encoding="utf-8")++ paths = {f.path for f in FileTraverser(tmp_path).traverse()}+ assert "game/Assets/Player.cs" in paths+ assert "src/Library/y.cs" in paths+ assert "game/Library/x.cs" not in paths+ assert in_blocked_dir("game/Library/x.cs", tmp_path)+ assert not in_blocked_dir("src/Library/y.cs", tmp_path)+def test_source_packages_named_like_output_dirs_are_indexed(self, tmp_path: Path) -> None:files = {"src/pkg/analysis/coverage/__init__.py": "",