"""验证 middleware/ 统一导入结构。

合并策略：
- app/middleware/ 作为统一目录
- monitoring/metrics.py (Prometheus指标定义) -> middleware/prometheus_metrics.py
- monitoring/middleware.py (MonitoringMiddleware) -> 合并到 middleware/metrics.py
- monitoring/agent_hooks.py -> middleware/agent_hooks.py
- monitoring/llm_metrics.py -> middleware/llm_metrics.py
- monitoring/ 目录已删除
"""
import pytest


class TestUnifiedMiddlewareImports:
    """测试统一后的 app.middleware 导入路径是否可用。"""

    def test_import_logging_filter(self):
        from app.middleware.logging_filter import APIKeyFilter
        assert APIKeyFilter is not None

    def test_import_logging_middleware(self):
        from app.middleware.logging_middleware import RequestLoggingMiddleware
        assert RequestLoggingMiddleware is not None

    def test_import_rate_limit(self):
        from app.middleware.rate_limit import RateLimitMiddleware
        assert RateLimitMiddleware is not None

    def test_import_request_id(self):
        from app.middleware.request_id import RequestIdMiddleware, REQUEST_ID_HEADER
        assert RequestIdMiddleware is not None
        assert REQUEST_ID_HEADER == "X-Request-ID"

    def test_import_metrics_middleware(self):
        from app.middleware.metrics import MetricsMiddleware
        assert MetricsMiddleware is not None

    def test_import_monitoring_middleware_from_metrics(self):
        from app.middleware.metrics import MonitoringMiddleware
        assert MonitoringMiddleware is not None

    def test_import_prometheus_metrics(self):
        from app.middleware.prometheus_metrics import (
            API_REQUESTS_TOTAL,
            API_REQUEST_DURATION_SECONDS,
            API_REQUESTS_IN_PROGRESS,
            AGENT_EXECUTIONS_TOTAL,
            AGENT_EXECUTION_DURATION_SECONDS,
            AGENT_RUNNING_TASKS,
            LLM_REQUESTS_TOTAL,
            LLM_REQUEST_DURATION_SECONDS,
            LLM_TOKENS_TOTAL,
            LLM_COST_ESTIMATED,
            BRAND_COUNT,
            QUERY_COUNT_TOTAL,
            CONTENT_GENERATED_TOTAL,
            CITATION_DETECTED_TOTAL,
            SERVICE_INFO,
        )
        assert API_REQUESTS_TOTAL is not None
        assert SERVICE_INFO is not None

    def test_import_agent_hooks(self):
        from app.middleware.agent_hooks import agent_execution_context, record_agent_execution
        assert agent_execution_context is not None
        assert record_agent_execution is not None

    def test_import_llm_metrics(self):
        from app.middleware.llm_metrics import get_llm_metrics, LLMMetricsWrapper
        assert get_llm_metrics is not None
        assert LLMMetricsWrapper is not None

    def test_import_excluded_paths(self):
        from app.middleware.metrics import _SKIP_PATHS
        assert isinstance(_SKIP_PATHS, set)
        assert "/health" in _SKIP_PATHS
