from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]

def test_reactivation_happens_before_insert_for_controlled_sources():
    src=(ROOT/'app'/'opportunity_action_task_materializer.py').read_text()
    assert 'allowed_reactivation_sources' in src
    assert 'explicit_blocker_cleared_preinsert' in src
    assert 'reactivated_version": "v4928.1.5.132.2' in src
    assert src.index('allowed_reactivation_sources') < src.index('INSERT INTO tasks')

def test_post_review_result_is_persisted_for_diagnostics():
    src=(ROOT/'app'/'opportunity_service.py').read_text()
    assert 'post_review_task_materialization' in src
    assert 'post_review_result = ensure_pending_task_for_next_action' in src

def test_guarded_repair_script_is_dry_run_by_default():
    src=(ROOT/'scripts'/'repair_v132_2_post_review_task_reactivation.py').read_text()
    assert 'Dry-run only. Use --apply.' in src
    assert 'manual_v132_2_reactivation_repair' in src
    assert 'revisão não está validated' in src
