import pytest
from pathlib import Path
from domin8.tools.diff_utils import normalize_diff
from domin8.tools.blast_radius import compute_blast_radius
from domin8.git_ops import create_diff
def test_blast_radius_basic_single_file():
# Use a small edit to docs to keep deterministic
target = Path('docs/refactor_plan.md')
assert target.exists()
orig = target.read_text()
new = orig.replace('Phase 1 – Single Tool Contract', 'Phase 1 — Single Tool Contract')
diff = create_diff(orig, new, str(target))
normalized = normalize_diff(diff)
repo_root = Path('.').resolve()
metrics = compute_blast_radius(normalized, repo_root)
assert isinstance(metrics, dict)
assert metrics['files_touched'] == 1
assert 0 <= metrics['score'] <= 100
assert 'per_file' in metrics
def test_blast_radius_source_fanout():
# Use an actual source file to test fan-out heuristic
target = Path('src/domin8/config.py')
assert target.exists()
orig = target.read_text()
# Append a harmless comment to ensure the diff is non-empty
new = orig + "\n# _test_change: fanout heuristic\n"
diff = create_diff(orig, new, str(target))
normalized = normalize_diff(diff)
repo_root = Path('.').resolve()
metrics = compute_blast_radius(normalized, repo_root)
# For a source file, fan_out should be present and be an int >= 0
assert metrics['files_touched'] >= 1
per = metrics['per_file'][0]
assert isinstance(per['fan_out'], int) and per['fan_out'] >= 0