本目录包含 LangGraph 代码助手的所有测试代码和脚本。
test/
├── __init__.py # Python 包初始化文件
├── README.md # 本文件
├── run_tests.py # 主测试运行器
├── test_real_llm.py # 真实 LLM (Kimi API) 测试
├── test_with_buggy_llm.py # Buggy LLM 错误处理测试
├── test_error_handling.py # 错误处理能力测试
├── test_simple.py # 简单单元测试(不依赖外部服务)
├── test_main_integration.py # 完整集成测试
├── test_tool_simple.py # Tool 服务简单测试
└── test_tool_direct.py # Tool 服务直接 HTTP 测试
在项目根目录运行:
# 使用真实 LLM (Kimi API)
./start_all_services.sh
# 使用模拟 LLM(不调用 API)
./start_all_services.sh --mock
# 使用 Buggy LLM(测试错误处理)
./start_all_services.sh --buggy服务启动后,运行测试:
# 端到端测试(真实 LLM)
python test/test_real_llm.py --mode e2e
# 单个服务测试
python test/test_real_llm.py --mode single
# Buggy LLM 测试
python test/test_with_buggy_llm.py
# 错误处理测试
python test/test_error_handling.py# 进入 test 目录
cd test
# 运行 mock 测试(不需要外部服务)
python run_tests.py --mode mock
# 运行端到端测试(需要先启动服务)
python run_tests.py --mode e2e
# 运行 pytest 测试
python run_tests.py --mode pytest# 从项目根目录运行
python test/test_simple.py
python test/test_tool_direct.py
python test/test_tool_simple.py- test_simple.py: 不依赖外部服务的纯单元测试
- test_tool_direct.py: 通过 HTTP 直接测试 Tool 服务
- test_real_llm.py: 使用真实 Moonshot Kimi API
- test_with_buggy_llm.py: 使用故意出错的 LLM 测试错误恢复
- test_error_handling.py: 测试各种错误场景(除零、文件不存在等)
- test_main_integration.py: 完整的端到端集成测试
- test_tool_simple.py: Tool 节点的消息队列集成测试
- test_tool_direct.py: Tool 服务的 REST API 测试
# 激活 conda 环境
conda activate transfer_queue
# 确保 Redis 运行中
redis-cli ping # 应该返回 PONG测试使用三种不同的 LLM 服务器:
-
real_llm_server.py: 调用 Moonshot Kimi API
- API Key: sk-4VF7qW5HsuXjgOwiCl4boalx8HzY5U2HBSF8mIFPD8Hz8SLM
- Base URL: https://api.moonshot.cn/v1
- Model: moonshot-v1-auto
-
simple_llm_server.py: 模拟 LLM,返回预定义响应
- 不调用外部 API
- 快速且免费
-
buggy_llm_server.py: 故意返回错误代码
- 用于测试调试和检查循环
- 第一次返回有语法错误的代码
- 第二次返回可执行但验证失败的代码
- 第三次返回正确代码
测试日志位于 logs/ 目录(在项目根目录):
# 查看所有日志
ls -lh logs/
# 实时查看某个服务日志
tail -f logs/coder.log
tail -f logs/debugger.log
tail -f logs/checker.log
tail -f logs/tool.log
tail -f logs/llm_server.log在项目根目录运行:
./stop_all_services.sh- 首次运行: 建议先使用
--mock模式确保所有组件正常工作 - 调试: 查看
logs/*.log文件了解详细执行过程 - 清理: 定期清理日志文件释放空间
- 性能: Mock LLM 比真实 API 快得多,适合快速迭代测试
如果遇到导入错误,确保:
- 从项目根目录运行测试:
python test/test_xxx.py - 或者测试文件已正确设置
sys.path
# 检查 Redis 是否运行
redis-cli ping
# 启动 Redis
redis-server
# 或使用 Docker
docker run -d -p 6379:6379 redis:latest# 查看占用端口的进程
lsof -i :8000-8004
# 停止所有服务
./stop_all_services.sh- 检查网络连接
- 验证 API Key 是否有效
- 查看
logs/llm_server.log了解详情 - 或使用
--mock模式运行