import ast
from pathlib import Path
ROOT=Path(__file__).parents[1]

def test_studio_router_exists_and_is_mounted():
    main=(ROOT/'app/main.py').read_text()
    studio=(ROOT/'app/api/studio.py').read_text()
    assert 'studio_router' in main and "'/studio'" in main
    for route in ['/dashboards','/widgets/{widget_id}/execute','/calculated-fields','/reports/{report_id}/schedules']:
        assert route in studio

def test_studio_frontend_calls_real_endpoints():
    html=(ROOT/'app/static/studio.html').read_text()
    assert '/studio/widgets/' in html
    assert '/studio/dashboards/' in html
    assert '/studio/calculated-fields' in html
    assert 'runAll()' in html and 'saveWidget()' in html

def test_models_for_v005_exist():
    text=(ROOT/'app/models/entities.py').read_text()
    for model in ['DashboardRevision','CalculatedField','ReportSchedule','ReportDelivery']:
        assert f'class {model}' in text

def test_python_syntax():
    for path in (ROOT/'app').rglob('*.py'):
        ast.parse(path.read_text(),filename=str(path))
