from pathlib import Path

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


def test_materializer_can_reactivate_blocked_terminal_task():
    src = (ROOT / "app" / "opportunity_action_task_materializer.py").read_text(encoding="utf-8")
    assert "reactivate_skipped: bool = False" in src
    assert "status IN ('skipped', 'ignored')" in src
    assert "task_reactivated" in src
    assert '"reactivated_version": "v4928.1.5.132.2.1"' in src


def test_review_and_physical_completion_enable_controlled_reactivation():
    src = (ROOT / "app" / "opportunity_service.py").read_text(encoding="utf-8")
    assert 'source="reconstructed_review_completion",\n                actor=created_by,\n                reactivate_skipped=True' in src
    assert 'source="physical_validation_completion",\n                actor=created_by,\n                reactivate_skipped=True' in src


def test_assigned_picking_does_not_synthesize_validation():
    src = (ROOT / "app" / "admin_dashboard.py").read_text(encoding="utf-8")
    assert 'if "assigned" in states and "done" not in states:' in src
    assert 'if physical_validated or whout_done:' in src
    assert 'or "assigned" in states' not in src
    assert 'or invoice_document or whout_done or whout_ready' not in src
