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

def test_compose_has_core_services():
    text = (ROOT / 'docker-compose.yml').read_text()
    for service in ('postgres:', 'redis:', 'api:', 'bot:', 'dashboard:'):
        assert service in text

def test_sql_contains_required_core_tables():
    text = (ROOT / 'db/schema.sql').read_text().lower()
    for table in ('users', 'tickets', 'ticket_messages', 'audit_logs', 'applications', 'salary_runs', 'threat_events'):
        assert f'create table if not exists {table}' in text

def test_frontend_has_command_center():
    text = (ROOT / 'apps/dashboard/src/ui/App.tsx').read_text()
    assert 'Command' in text and 'Ticket command' in text and 'Operator sign in' in text


def test_admin_access_controls_exist():
    routes = (ROOT / "apps/api/app/api/routes.py").read_text()
    assert '/admin/users/{user_id}/reset-password' in routes
    assert '/auth/change-password' in routes
    assert '/admin/users/{user_id}/permissions' in routes
    schema = (ROOT / "db/schema.sql").read_text().lower()
    assert 'user_permission_overrides' in schema
    assert 'token_version integer not null default 0' in schema
