#!/usr/bin/env python3
"""
测试 onmyoji_gacha Web API 路由是否正确注册
"""
import sys
import os

# 添加项目路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'danding_bot'))

# 设置环境变量
os.environ.setdefault("ENVIRONMENT", "dev")

try:
    # 模拟 NoneBot 环境
    from nonebot import get_driver
    from nonebot import init
    
    # 初始化 NoneBot
    init()
    
    # 尝试获取驱动
    driver = get_driver()
    print(f"✅ 成功获取驱动: {type(driver)}")
    
    # 检查是否有 server_app 属性
    if hasattr(driver, 'server_app'):
        print(f"✅ 找到 server_app: {type(driver.server_app)}")
        
        # 检查路由是否已注册
        app = driver.server_app
        routes = app.routes
        print(f"✅ 当前注册的路由数量: {len(routes)}")
        
        # 查找我们的路由
        onmyoji_routes = [route for route in routes if hasattr(route, 'path') and '/onmyoji_gacha' in str(route.path)]
        print(f"✅ 找到 onmyoji_gacha 路由: {len(onmyoji_routes)} 个")
        
        for route in onmyoji_routes:
            print(f"  - {route.path} ({route.methods if hasattr(route, 'methods') else 'N/A'})")
    else:
        print("❌ 驱动没有 server_app 属性")
        
except Exception as e:
    print(f"❌ 测试失败: {e}")
    import traceback
    traceback.print_exc()