#!/usr/bin/env python3
"""
Focused tests for web-server guardrails.
"""

import os
import sys

import pytest
from fastapi import HTTPException

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))

from ft991a.web import ensure_cw_copy_dependencies


def test_ensure_cw_copy_dependencies_passes_when_all_tools_present(monkeypatch):
    monkeypatch.setattr("ft991a.web.shutil.which", lambda _name: "/usr/bin/tool")
    ensure_cw_copy_dependencies()


def test_ensure_cw_copy_dependencies_lists_missing_tools(monkeypatch):
    present = {"arecord": "/usr/bin/arecord", "sox": None, "multimon-ng": None}
    monkeypatch.setattr("ft991a.web.shutil.which", lambda name: present.get(name))

    with pytest.raises(HTTPException) as excinfo:
        ensure_cw_copy_dependencies()

    assert excinfo.value.status_code == 503
    assert excinfo.value.detail == "Missing CW copy dependencies: sox, multimon-ng"
