import pytest
from pathlib import Path
from domin8.tools.diff_utils import normalize_diff
from domin8.tools.api_impact import analyze_changes
from domin8.git_ops import create_diff
def test_api_impact_detects_modified_symbol():
target = Path('src/domin8/config.py')
assert target.exists()
orig = target.read_text()
# Modify a function signature or add a def
if 'def load_request_change_config' in orig:
new = orig.replace('def load_request_change_config(repo_root: Path) -> RequestChangeConfig:',
'def load_request_change_config(repo_root: Path, verbose: bool=False) -> RequestChangeConfig:')
else:
new = orig + '\n\ndef new_helper(x):\n return x\n'
diff = create_diff(orig, new, str(target))
normalized = normalize_diff(diff)
analysis = analyze_changes(normalized)
assert 'per_file' in analysis
# At least one file should show some symbol changes or no-op; ensure structure present
assert isinstance(analysis['per_file'], list)
# If we modified function signature, expect public_api_impact possibly True
assert 'total_public_api_impacts' in analysis
def test_api_impact_detects_added_function():
target = Path('src/domin8/tools/api_impact.py')
assert target.exists()
orig = target.read_text()
new = orig + '\n\ndef public_new_function(a, b):\n return a + b\n'
diff = create_diff(orig, new, str(target))
normalized = normalize_diff(diff)
analysis = analyze_changes(normalized)
per = analysis['per_file'][0]
assert per['public_api_impact'] is True or isinstance(per['symbols_added'], list)