from pathlib import Path
from domin8.tools.import_graph import ImportGraph
from domin8 import storage
def test_import_index_dir_is_excluded(tmp_path, monkeypatch):
# Create a small repo with one normal module and one file under the import_index
repo_root = tmp_path / "repo"
repo_root.mkdir()
(repo_root / "pkg").mkdir()
(repo_root / "pkg" / "mod.py").write_text("def public():\n return 1\n")
# Monkeypatch agent data root to a temp directory so we don't touch real home
agent_root = tmp_path / "agent_data"
agent_root.mkdir()
monkeypatch.setattr(storage, 'get_agent_data_root', lambda: agent_root)
# Create the internal import_index dir and add a Python file that would otherwise be indexed
import_index = agent_root / 'import_index'
import_index.mkdir()
(import_index / 'should_not_index.py').write_text("def oops():\n return 2\n")
g = ImportGraph(repo_root)
g.build(use_cache=False)
# Ensure the symbol from the import_index file is NOT present
assert 'oops' not in g.symbol_to_files
# Ensure the symbol from the real package IS present
assert 'public' in g.symbol_to_files
def test_sqlite_db_path_is_excluded(tmp_path, monkeypatch):
repo_root = tmp_path / "repo2"
repo_root.mkdir()
(repo_root / "pkg").mkdir()
(repo_root / "pkg" / "mod.py").write_text("def public2():\n return 1\n")
# Monkeypatch agent data root so get_index_path returns tmp_path / 'index.sqlite'
agent_root = tmp_path / 'agent_data2'
agent_root.mkdir()
monkeypatch.setattr(storage, 'get_agent_data_root', lambda: agent_root)
# Create a fake sqlite file at get_index_path(). This should not be treated as a source file.
from domin8.storage.index import get_index_path
db_path = get_index_path()
db_path.parent.mkdir(parents=True, exist_ok=True)
db_path.write_text('SQLITE')
g = ImportGraph(repo_root)
g.build(use_cache=False)
assert 'public2' in g.symbol_to_files
# The sqlite file shouldn't have caused parsing errors or been indexed
assert not any(str(db_path) in str(p) for ps in g.symbol_to_files.values() for p in ps)