"""测试 PD 分离功能

验证 CPUEngine 的 prefill() 和 decode() 方法是否正常工作。

NOTE: 这些测试使用旧的 create_engine 工厂，在新的 LLMEngine 架构中
已被废弃。PD 分离功能将在后续版本中通过 LLMEngine 的扩展接口支持。
"""

from __future__ import annotations

import logging

import pytest


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


# 跳过原因：create_engine 工厂已废弃，PD 分离需要使用新的 LLMEngine 扩展
SKIP_REASON = (
    "PD separation tests use deprecated create_engine factory. Use LLMEngine for new code."
)


@pytest.mark.skip(reason=SKIP_REASON)
@pytest.mark.asyncio
async def test_cpu_engine_prefill():
    """测试 CPUEngine 的 prefill 方法"""
    pass  # 测试已被跳过


@pytest.mark.skip(reason=SKIP_REASON)
@pytest.mark.asyncio
async def test_cpu_engine_decode_skipped():
    """测试 CPUEngine 的 decode 方法"""
    pass  # 测试已被跳过


@pytest.mark.skip(reason=SKIP_REASON)
@pytest.mark.asyncio
async def test_pd_executor_hybrid_skipped():
    """测试 PDSeparatedExecutor 的 Hybrid 模式"""
    pass  # 测试已被跳过


@pytest.mark.skip(reason=SKIP_REASON)
@pytest.mark.asyncio
async def test_pd_executor_prefill_only_skipped():
    """测试 PDSeparatedExecutor 的 Prefill-Only 模式"""
    pass  # 测试已被跳过


# ═════════════════════════════════════════════════════════════════════════════
# 以下为旧代码，保留供参考（已被上面的 skipped 测试替代）
# ═════════════════════════════════════════════════════════════════════════════


# 旧测试代码（废弃）
# @pytest.mark.asyncio
# async def test_cpu_engine_prefill_old():
#     backend_cfg = BackendConfig(kind="cpu", device="cpu")
#     backend = create_backend(backend_cfg)
#     config = EngineConfig(kind="cpu", model="sshleifer/tiny-gpt2", device="cpu")
#     engine = create_engine(config, backend)
#
#     try:
#         await engine.start()
#
#         # 创建请求
#         request = Request(
#             request_id="req-prefill-001",
#             trace_id="trace-001",
#             model="sshleifer/tiny-gpt2",
#             prompt="Hello, how are you?",
#             max_tokens=10,
#             stream=False,
#         )
#
#         # 执行 Prefill
#         result = await engine.prefill(request)
#
#         # 验证结果
#         assert "kv_handle" in result
#         assert "num_tokens" in result
#         assert result["num_tokens"] > 0
#         assert "first_token_id" in result
#
#         logger.info(f"✓ Prefill completed: {result['num_tokens']} tokens processed")
#
#     finally:
#         await engine.stop()


# test_cpu_engine_decode 已移至上方的 skipped 版本


# test_pd_executor_hybrid 已移至上方的 skipped 版本


# test_pd_executor_prefill_only 已移至上方的 skipped 版本


if __name__ == "__main__":
    print("\n⚠️ PD separation tests are skipped (deprecated create_engine factory).")
    print("Use LLMEngine for new implementations.")
