from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
def read(p): return (ROOT/p).read_text(encoding='utf-8')
def test_v013_router_and_ui():
    main=read('app/main.py'); api=read('app/api/v013.py')
    assert 'v013_router' in main and '/observability' in main
    for route in ['/summary','/health/check','/incidents','/policies','/metrics']: assert route in api
    assert (ROOT/'app/static/observability.html').exists()
def test_observability_models_and_migration():
    entities=read('app/models/entities.py'); migration=read('migrations/013_enterprise_observability.sql')
    for name in ['ServiceHealthSnapshot','OperationalIncident','ObservabilityAlertPolicy','OperationalLogEvent']: assert f'class {name}' in entities
    for table in ['service_health_snapshots_v013','operational_incidents_v013','observability_alert_policies_v013','operational_log_events_v013']: assert table in migration
def test_telemetry_and_workers():
    telemetry=read('app/core/telemetry.py'); tasks=read('app/workers/tasks.py'); celery=read('app/workers/celery_app.py')
    assert 'X-Request-ID' in telemetry and 'JsonFormatter' in telemetry
    assert 'collect-platform-health' in tasks and 'evaluate-observability-policies' in tasks
    assert 'collect-platform-health-every-minute' in celery
def test_prometheus_grafana_stack():
    compose=read('docker-compose.yml')
    assert 'prom/prometheus' in compose and 'grafana/grafana' in compose
    assert (ROOT/'observability/prometheus/prometheus.yml').exists()
