2026-07-08 11:19
✅ 所有测试通过!
test_rate_limiter.py (5 测试)test_security.py (15 测试)test_request_context.py (14 测试)test_scoped_auth_client.py (6 测试)test_scoped_api_client.py (9 测试)test_gateway_session_store_unit.py (8 测试)test_public_gateway_unit.py (12 测试)test_public_server_integration.py (10 测试)test_run_coverage.py (2 测试)集成测试中成功验证了审计日志:
[AUDIT] bind_auth_code: session_hash=85ee69407122, auth_code_provided=True
[AUDIT] bind_success: session_hash=85ee69407122, admin_id=123, company_id=100
[AUDIT] tool_call: session_hash=8069b9a33c6d, admin_id=456, company_id=200, tool=query_order, request_id=rq_http_1
[AUDIT] tool_success: session_hash=8069b9a33c6d, tool=query_order, request_id=rq_http_1, code=0
[HTTP] request: ip=127.0.0.1, method=tools/call, id=1
# 运行所有测试
python -m unittest discover -s tests -p "test_*.py" -v
# 运行特定模块
python -m unittest tests.test_rate_limiter -v
python -m unittest tests.test_security -v
python -m unittest tests.test_public_server_integration -v
所有新增功能均有对应的单元测试和集成测试,确保:
pip install coveragepython run_coverage.py --open| 模块 | 语句数 | 未覆盖 | 分支数 | 部分覆盖 | 覆盖率 |
|---|---|---|---|---|---|
| 新增模块(100% 覆盖) | |||||
constants.py |
1 | 0 | 0 | 0 | 100% ✅ |
public_gateway.py |
54 | 0 | 10 | 0 | 100% ✅ |
services/api_client.py |
18 | 0 | 0 | 0 | 100% ✅ |
services/auth_client.py |
31 | 0 | 6 | 0 | 100% ✅ |
services/gateway_session_store.py |
23 | 0 | 4 | 0 | 100% ✅ |
services/request_context.py |
28 | 0 | 10 | 0 | 100% ✅ |
services/scoped_api_client.py |
13 | 0 | 2 | 0 | 100% ✅ |
services/scoped_auth_client.py |
19 | 0 | 2 | 0 | 100% ✅ |
tools/query_track.py |
23 | 0 | 12 | 0 | 100% ✅ |
utils/rate_limiter.py |
29 | 0 | 8 | 0 | 100% ✅ |
utils/security.py |
12 | 0 | 2 | 0 | 100% ✅ |
| 新增模块(90%+ 覆盖) | |||||
config.py |
94 | 4 | 38 | 5 | 93.18% ✅ |
| 现有模块 | |||||
public_server.py |
95 | 12 | 26 | 6 | 83.47% |
tools/query_order.py |
17 | 2 | 4 | 2 | 80.95% |
mcp_protocol.py |
147 | 20 | 66 | 18 | 80.28% |
tools/bind_auth_code.py |
18 | 3 | 6 | 3 | 75.00% |
app.py |
129 | 25 | 48 | 16 | 74.58% |
services/token_store.py |
158 | 63 | 50 | 10 | 52.40% |
| 总计 | 909 | 129 | 294 | 60 | 81.30% |
✅ 11 个新增核心模块达到 100% 覆盖率
✅ 1 个新增模块达到 90%+ 覆盖率
✅ 总体覆盖率 81.30%
# 生成所有报告
python run_coverage.py --open
# 或手动生成
coverage html
# 然后在浏览器中打开 htmlcov/index.html