"""
测试配置保存和加载功能
"""
import json
from config_manager import ConfigManager

# 测试配置保存
cfg = ConfigManager()

print("=== 测试LLM提供商切换保存 ===")
print(f"当前激活: {cfg.get('active_llm')}")

# 切换到 wolfai
cfg.set_active_llm("wolfai")
print(f"切换后: {cfg.get('active_llm')}")

# 重新加载验证
cfg2 = ConfigManager()
print(f"重新加载: {cfg2.get('active_llm')}")

# 检查config.json文件内容
with open("config.json", "r", encoding="utf-8") as f:
    data = json.load(f)
    print(f"\nconfig.json中的active_llm: {data.get('active_llm')}")
    print(f"api_key: {data.get('api_key', '')[:20]}...")
    print(f"base_url: {data.get('base_url')}")

print("\n=== 测试其他全局设置保存 ===")
print(f"当前persona: {cfg.get('persona')}")
cfg.set("persona", "测试人设")
print(f"修改后persona: {cfg.get('persona')}")

# 重新验证
with open("config.json", "r", encoding="utf-8") as f:
    data = json.load(f)
    print(f"config.json中的persona: {data.get('persona')}")

print("\n✅ 测试完成")
