from pathlib import Path
from domin8.tools.import_graph import build_import_graph
def test_persistence(tmp_path):
# Create a tiny repo in tmp_path to keep test fast and deterministic
repo_root = tmp_path
(repo_root / "pkg").mkdir()
# Add a source file that defines a symbol
(repo_root / "pkg" / "module.py").write_text("""
def public_func():
return 42
""")
# Add a test that references the symbol
(repo_root / "tests").mkdir()
(repo_root / "tests" / "test_module.py").write_text("""
from pkg.module import public_func
def test_it():
assert public_func() == 42
""")
# Build graph (will create index file in agent data root)
g = build_import_graph(repo_root)
assert hasattr(g, 'symbol_to_tests')
# Force reload using a new instance to ensure persistence is read
g2 = build_import_graph(repo_root)
g2.build(use_cache=True)
assert hasattr(g2, 'symbol_to_tests')
# The symbol should map to the test file we created
assert any('test_module.py' in str(p) for p in g2.symbol_to_tests.get('public_func', []))