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 #2379: Classify `.env` dotfiles as config paths (#2381)

P A M O Dca174d33c259
diff --git a/packages/core/src/repowise/core/analysis/knowledge_graph.py b/packages/core/src/repowise/core/analysis/knowledge_graph.py
index 4c73ad982..cf9889ad5 100644
--- a/packages/core/src/repowise/core/analysis/knowledge_graph.py
+++ b/packages/core/src/repowise/core/analysis/knowledge_graph.py
@@ -17,7 +17,7 @@ from pathlib import Path, PurePosixPath
from typing import Any
from repowise.core.generation.entry_points import orientation_entry_points
-from repowise.core.support_paths import CONFIG_EXTENSIONS, DOC_EXTENSIONS
+from repowise.core.support_paths import CONFIG_EXTENSIONS, DOC_EXTENSIONS, classification_token
_log = logging.getLogger(__name__)
@@ -165,10 +165,13 @@ _DOC_EXTENSIONS = DOC_EXTENSIONS
def _classify_file_type(path: str, language: str, is_config: bool) -> str:
- ext = PurePosixPath(path).suffix.lower()
- stem = PurePosixPath(path).stem.lower()
+ p = PurePosixPath(path)
+ ext = p.suffix.lower()
+ stem = p.stem.lower()
- if is_config or ext in _CONFIG_EXTENSIONS:
+ # `classification_token` covers dotfiles: `.env` has no suffix, so the
+ # suffix-only check below never matched the entry that names it (#2379).
+ if is_config or classification_token(path) in _CONFIG_EXTENSIONS:
return "config"
# Infra names only count for extension-less files (Dockerfile, Makefile)
# or when ingestion parsed the file as an infra language — a Python module
diff --git a/packages/core/src/repowise/core/support_paths.py b/packages/core/src/repowise/core/support_paths.py
index 756263539..8c8f773dc 100644
--- a/packages/core/src/repowise/core/support_paths.py
+++ b/packages/core/src/repowise/core/support_paths.py
@@ -18,6 +18,7 @@ __all__ = [
"CONFIG_EXTENSIONS",
"DOC_EXTENSIONS",
"FilePopulation",
+ "classification_token",
"file_population",
"is_doc_or_config_path",
"is_example_path",
@@ -81,10 +82,24 @@ CONFIG_EXTENSIONS = frozenset(
DOC_EXTENSIONS = frozenset({".md", ".mdx", ".rst", ".txt", ".adoc"})
+def classification_token(path: str) -> str:
+ """The lowercased token *path* is classified by.
+
+ The extension in almost every case. Pathlib reports **no** suffix for a
+ dotfile whose only dot is the leading one — ``PurePosixPath(".env").suffix
+ == ""`` — and the sets above name exactly such files (``".env"`` is an
+ entry of ``CONFIG_EXTENSIONS``). The whole name is the token there, so
+ falling back to it keeps entries that name a file rather than an extension
+ working (#2379).
+ """
+ parsed = PurePosixPath(path)
+ return (parsed.suffix or parsed.name).lower()
+
+
def is_doc_or_config_path(path: str) -> bool:
"""Whether *path* is documentation or configuration rather than code."""
- ext = PurePosixPath(path).suffix.lower()
- return ext in CONFIG_EXTENSIONS or ext in DOC_EXTENSIONS
+ token = classification_token(path)
+ return token in CONFIG_EXTENSIONS or token in DOC_EXTENSIONS
FilePopulation = Literal["production", "test", "example", "doc"]
diff --git a/tests/unit/analysis/test_knowledge_graph.py b/tests/unit/analysis/test_knowledge_graph.py
index 96676a338..e0687437c 100644
--- a/tests/unit/analysis/test_knowledge_graph.py
+++ b/tests/unit/analysis/test_knowledge_graph.py
@@ -311,6 +311,11 @@ class TestFileTypeClassification:
def test_config_by_extension(self):
assert _classify_file_type("config.yaml", "yaml", False) == "config"
+ def test_config_by_dotfile_name(self):
+ """#2379: `.env` has no suffix, but its whole name is the set's entry."""
+ assert _classify_file_type(".env", "", False) == "config"
+ assert _classify_file_type("proj/.env", "", False) == "config"
+
def test_config_by_flag(self):
assert _classify_file_type("settings.py", "python", True) == "config"
diff --git a/tests/unit/test_support_paths.py b/tests/unit/test_support_paths.py
index 745c98be8..5049080a6 100644
--- a/tests/unit/test_support_paths.py
+++ b/tests/unit/test_support_paths.py
@@ -4,7 +4,13 @@ from __future__ import annotations
import pytest
-from repowise.core.support_paths import is_example_path, is_support_path
+from repowise.core.support_paths import (
+ classification_token,
+ file_population,
+ is_doc_or_config_path,
+ is_example_path,
+ is_support_path,
+)
@pytest.mark.parametrize(
@@ -60,3 +66,58 @@ def test_doc_dirs_are_support_but_not_examples(path: str):
def test_matching_is_case_insensitive():
assert is_example_path("Examples/Demo.cs")
assert is_support_path("Docs/Guide.md")
+
+
+class TestClassificationToken:
+ """classification_token picks the right token for suffix vs dotfile."""
+
+ def test_regular_extension(self):
+ assert classification_token("config.yaml") == ".yaml"
+
+ def test_dotfile_returns_name(self):
+ """`.env` has no suffix — the whole name is the token."""
+ assert classification_token(".env") == ".env"
+
+ def test_nested_dotfile(self):
+ assert classification_token("proj/.env") == ".env"
+
+ def test_non_dotfile_without_suffix(self):
+ """A file like `Makefile` has no suffix and is not a dotfile — its
+ name is returned, but that is fine since it is not in CONFIG_EXTENSIONS."""
+ assert classification_token("Makefile") == "makefile"
+
+
+ "path",
+ [
+ ".env",
+ "proj/.env",
+ "packages/core/.env",
+ "foo.env",
+ "config.yaml",
+ "docs/guide.md",
+ ],
+)
+def test_config_and_doc_paths(path: str):
+ assert is_doc_or_config_path(path)
+
+
+ "path", ["src/parser.rs", "src/env.py", ".gitignore", "Makefile"]
+)
+def test_production_paths_are_not_doc_or_config(path: str):
+ assert not is_doc_or_config_path(path)
+
+
+def test_dotenv_dotfile_is_not_production():
+ """#2379: `.env` is the file CONFIG_EXTENSIONS names by name.
+
+ PurePosixPath('.env').suffix is empty, so the suffix-only check never
+ matched the ".env" entry, and every surface that hides non-production
+ code treated a checked-in .env as production source.
+ """
+ assert file_population(".env", is_test=False) == "doc"
+ assert file_population("proj/.env", is_test=False) == "doc"
+ # The fallback matches the dotfile name against the sets; it does not
+ # promote every dotfile, so an unnamed one stays production.
+ assert file_population(".gitignore", is_test=False) == "production"