|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
| 6 | +import builtins |
6 | 7 | import json |
7 | 8 | from pathlib import Path |
8 | 9 | from types import SimpleNamespace |
@@ -191,6 +192,53 @@ def test_capped_artifact_does_not_hide_symbol_free_source_code(tmp_path): |
191 | 192 | assert get_module_token_count(components) >= count_tokens(source) |
192 | 193 |
|
193 | 194 |
|
| 195 | +@pytest.mark.parametrize( |
| 196 | + ("language", "included", "excluded"), |
| 197 | + [ |
| 198 | + ("go", "source.go", "vendor/source.go"), |
| 199 | + ("zig", "source.zig", "zig-out/source.zig"), |
| 200 | + ("php", "source.php", "templates/source.php"), |
| 201 | + ], |
| 202 | +) |
| 203 | +def test_file_exclusions_do_not_import_parsers(monkeypatch, language, included, excluded): |
| 204 | + from codewiki.src.be.dependency_analyzer.utils.file_selection import is_skipped_source_file |
| 205 | + |
| 206 | + original_import = builtins.__import__ |
| 207 | + |
| 208 | + def without_grammars(name, *args, **kwargs): |
| 209 | + if name.startswith(("tree_sitter", "codewiki.src.be.dependency_analyzer.analyzers")): |
| 210 | + raise ModuleNotFoundError(name) |
| 211 | + return original_import(name, *args, **kwargs) |
| 212 | + |
| 213 | + monkeypatch.setattr(builtins, "__import__", without_grammars) |
| 214 | + assert not is_skipped_source_file({"language": language, "path": included}, "/repo") |
| 215 | + assert is_skipped_source_file({"language": language, "path": excluded}, "/repo") |
| 216 | + |
| 217 | + |
| 218 | +def test_symbol_free_file_survives_missing_php_grammar(tmp_path, monkeypatch): |
| 219 | + repo = tmp_path / "repo" |
| 220 | + repo.mkdir() |
| 221 | + source = "<?php\nconst CAPACITY = 16;\n" |
| 222 | + (repo / "source.php").write_text(source) |
| 223 | + templates = repo / "templates" |
| 224 | + templates.mkdir() |
| 225 | + (templates / "view.php").write_text("<?php echo 'view';\n") |
| 226 | + original_import = builtins.__import__ |
| 227 | + |
| 228 | + def without_php(name, *args, **kwargs): |
| 229 | + if name in ("tree_sitter_php", "codewiki.src.be.dependency_analyzer.analyzers.php"): |
| 230 | + raise ModuleNotFoundError(name) |
| 231 | + return original_import(name, *args, **kwargs) |
| 232 | + |
| 233 | + monkeypatch.setattr(builtins, "__import__", without_php) |
| 234 | + components, leaves = DependencyGraphBuilder( |
| 235 | + _config(repo, tmp_path / "out") |
| 236 | + ).build_dependency_graph() |
| 237 | + assert component_files(list(components), components) == {"source.php"} |
| 238 | + assert components["source.php::__file__"].source_code == source |
| 239 | + assert complete_file_candidates(leaves, components) == ["source.php::__file__"] |
| 240 | + |
| 241 | + |
194 | 242 | def test_recursive_size_uses_child_files_not_whole_graph(tmp_path): |
195 | 243 | components = { |
196 | 244 | cid: _node(cid, source) |
|
0 commit comments