SuperAPI AI 工具集

prowler-test-mcp

测试与质量

查看项目

更新于 10-16 04:35

技能介绍

用途:为 Prowler MCP Server 编写测试,覆盖工具、模型与契约三层。

主要能力与规则:工具必须通过内存客户端驱动,即 async with Client(mcp_root_server);工具参数使用 pydantic Field(default=...),只有 FastMCP 包装器会解析默认值,直接调用工具方法必须传全部参数。不要在 fixture 内打开 fastmcp.Client,应在测试内联打开。始终使用 mock_api_client fixture,不要自行构造 ProwlerAPIClient;不要清空 SingletonMeta.instances;不要移除 PROWLER_API_KEY。ProwlerAppAuth 需显式传 mode= 与 base_url=。不要断言精确工具数量,应断言 result.data 而非 result.content[0].text。测试文件用 test*.py 前缀,每个 tests/ 子目录需要 init.py,异步测试无需标记(asyncio_mode = "auto"),凭据只用 tests.helpers.tokens 中的假值。

布局:在包根下镜像源码树,去掉 prowler_mcp_server/ 层级。

Fixture:_pinned_environment、_no_real_network、_singleton_registry_guard 为 autouse;mock_router、api_client、mock_api_client、isolated_api_client、mcp_root_server、health_client、http_request_headers、hub_router、docs_router 按需使用。MockRouter 支持 add、request_for、query_params、paths,重复注册路由可返回序列。

命令:在 mcp_server/ 下运行 uv run pytest、uv run pytest tests/prowler_app/models、uv run pytest --cov=./prowler_mcp_server;仓库根运行 make test-mcp。

限制:覆盖率有虚高下限,模型模块多为导入期执行的 Field 声明,应对比仅导入下限而非零。helpers/ 保持与功能无关,功能属性字典放在使用它的测试模块中。