From 955e486185f78c107fa0192fba4cf2ca72f301fc Mon Sep 17 00:00:00 2001 From: v01dst Date: Sun, 6 Sep 2026 10:02:39 +0000 Subject: [PATCH] test: pin generated-directory exclusion in inventory discovery Issue #3 asks that generated directories (.git, node_modules, .venv, caches, build, dist) be excluded from repository analysis and that the behavior be covered by regression tests. The os.walk pruning in discover_files already applies settings.exclude_patterns to dirnames, but nothing pinned it. Two tests: a fixture tree with generated directories alongside real sources asserts no discovered path touches any generated directory, and that legitimate sources remain discoverable. --- tests/unit/test_inventory.py | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_inventory.py b/tests/unit/test_inventory.py index b836292..4859893 100644 --- a/tests/unit/test_inventory.py +++ b/tests/unit/test_inventory.py @@ -1 +1,38 @@ -def test_dummy(): pass +"""Inventory discovery must never traverse generated directories.""" + +from pathlib import Path + +from skillfoundry.analysis.inventory import discover_files +from skillfoundry.config.settings import AnalysisSettings + + +def test_discovery_skips_generated_directories(tmp_path: Path): + settings = AnalysisSettings() + (tmp_path / "src").mkdir() + (tmp_path / "src" / "main.py").write_text("print('x')\n") + (tmp_path / "README.md").write_text("readme\n") + + for generated in (".git", "node_modules", ".venv", "__pycache__", "dist", "build"): + d = tmp_path / generated + d.mkdir() + (d / "junk.js").write_text("generated\n") + + found = discover_files(tmp_path, settings) + paths = [f.path for f in found] + + assert (tmp_path / "src" / "main.py") in [tmp_path / p for p in paths] + assert (tmp_path / "README.md") in [tmp_path / p for p in paths] + assert all("node_modules" not in str(p) for p in paths) + assert all(".git" not in str(p) for p in paths) + assert all(".venv" not in str(p) for p in paths) + assert all("__pycache__" not in str(p) for p in paths) + assert all("dist" not in str(p) for p in paths) + assert all("build" not in str(p) for p in paths) + + +def test_discovery_still_finds_normal_sources(tmp_path: Path): + settings = AnalysisSettings() + (tmp_path / "lib").mkdir() + (tmp_path / "lib" / "core.py").write_text("x = 1\n") + found = discover_files(tmp_path, settings) + assert any("lib/core.py" in str(f.path) for f in found)