from pathlib import Path


def test_evidence_treats_odoo_done_as_shipped_before_production():
    src = Path('app/domain/opportunity_flow/evidence.py').read_text()
    assert 'physical_done =' in src
    assert 'outgoing_pickings' in src
    assert 'order_shipped=physical_done' in src
    assert 'odoo_in_production=(not physical_done)' in src


def test_rules_prioritize_shipped_over_wait_production():
    src = Path('app/domain/opportunity_flow/rules.py').read_text()
    decision_src = src[src.index('def decide_blif_next_action'):]
    shipped_idx = decision_src.index('e.has_invoice and e.payment_confirmed and e.order_shipped')
    production_idx = decision_src.index('e.has_invoice and e.payment_confirmed and e.odoo_in_production')
    assert shipped_idx < production_idx
    assert 'Confirmar entrega/tracking' in src


def test_repair_script_is_conservative_and_safe():
    src = Path('scripts/repair_operator_page_consistency_findings.py').read_text()
    assert 'dry-run' in src or 'dry_run=True' in src
    assert 'CRITICAL_DELIVERED_WITHOUT_PAYMENT_CONFIRMED' in src
    assert 'Never auto-fixes' in src
    assert 'after_delivery' in src
    assert "status = 'ignored'" in src
