测试指南
环境设置
Python SDK
cd py
# 安装依赖 + 开发工具(pytest、pytest-asyncio、pytest-httpx、ruff、mypy)pip install -e ".[dev]"创建 py/.env(仅集成测试需要):
IMBRACE_API_KEY=api_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxIMBRACE_GATEWAY_URL=https://app-gatewayv2.imbrace.coIMBRACE_ORGANIZATION_ID=org_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxTypeScript SDK
cd tsnpm installPython — 运行与测试
单元测试(无需 API Key)
cd py
# 运行所有单元测试pytest tests/unit -v
# 运行特定文件pytest tests/unit/test_http.py -vpytest tests/unit/resources/test_channel.py -v
# 运行特定测试用例pytest tests/unit/test_http.py::test_401_raises_auth_error -v
# 按关键字运行pytest tests/unit -k "channel" -vpytest tests/unit -k "boards" -v集成测试(需要真实 API Key)
集成测试执行对 API 网关的真实调用。
cd py
# 选项 1:直接在命令中设置密钥IMBRACE_API_KEY=api_xxx pytest tests/integration -v -m integration
# 选项 2:使用 .env(conftest.py 通过 load_dotenv 自动加载)pytest tests/integration -v -m integration运行全部(单元 + 集成)
pytest tests/ -v覆盖率报告
pytest-cov默认不包含。单独安装:pip install pytest-cov
pytest tests/unit --cov=src/imbrace --cov-report=term-missingTypeScript — 运行与测试
构建
cd ts
# 单次构建npm run build
# 监视模式构建(更改时自动重新构建)npm run dev
# 清理 dist/npm run clean单元测试(无需 API Key)
cd ts
# 运行所有单元测试npm test
# 运行特定文件npx vitest run tests/unit/http.test.tsnpx vitest run tests/unit/resources/contacts.test.ts
# 监视模式(代码更改时自动运行)npm run test:watch运行全部(单元 + 本地测试)
npm run test:all这会在整个项目中运行 vitest(单元 + 任何匹配测试模式的本地文件)。TypeScript 集成测试尚未可用 — 请参见 py/tests/integration/ 获取实时 API 检查,或 ts/tests/local/ 获取手动实时测试脚本。
代码检查与类型检查
Python
cd py
# 检查代码风格ruff check src/ tests/
# 自动修复可修复的 ruff 错误ruff check src/ tests/ --fix
# 检查类型注解mypy src/imbraceTypeScript
cd ts
# 类型检查npm run typecheck
# 代码检查npm run lint