test: P3-1 第34波单元测试(title_library/recipe) #812

Merged
xiaoxia merged 1 commits from test/unit-test-wave34 into develop 2026-07-24 16:44:33 +08:00
Owner

变更内容

P3-1 第34波单元测试补充,合计 +48 个测试。

测试文件

  1. test_title_library_use_cases.py (25个) - 标题库UseCase

    • ListTitleLibraryUseCase:正常/分类过滤/分页/空列表
    • GetTitleLibraryUseCase:存在/不存在
    • CreateTitleLibraryUseCase:成功/配额超限/带tags和metadata
    • UpdateTitleLibraryUseCase:改名称/多字段/不存在
    • DeleteTitleLibraryUseCase:成功/不存在
    • IncrementTitleUsageUseCase:正增量/零/负/大增量
    • PickTitleUseCase:多选/空/分类/排除ID/排除全部fallback/单个/倾向少用
  2. test_recipe_use_cases.py (23个) - 配方UseCase

    • ListRecipesUseCase:正常/分页/空列表
    • GetRecipeUseCase:存在/不存在
    • CreateRecipeUseCase:无items/带items/默认值
    • UpdateRecipeUseCase:改名称/多字段/替换items/空items/不存在
    • DeleteRecipeUseCase:成功/不存在
    • UseRecipeUseCase:premium/basic启用/功能禁用/不存在
    • Commands:字段/默认值/dataclass

测试结果

4428 passed, 8 skipped
## 变更内容 P3-1 第34波单元测试补充,合计 +48 个测试。 ### 测试文件 1. **test_title_library_use_cases.py** (25个) - 标题库UseCase - ListTitleLibraryUseCase:正常/分类过滤/分页/空列表 - GetTitleLibraryUseCase:存在/不存在 - CreateTitleLibraryUseCase:成功/配额超限/带tags和metadata - UpdateTitleLibraryUseCase:改名称/多字段/不存在 - DeleteTitleLibraryUseCase:成功/不存在 - IncrementTitleUsageUseCase:正增量/零/负/大增量 - PickTitleUseCase:多选/空/分类/排除ID/排除全部fallback/单个/倾向少用 2. **test_recipe_use_cases.py** (23个) - 配方UseCase - ListRecipesUseCase:正常/分页/空列表 - GetRecipeUseCase:存在/不存在 - CreateRecipeUseCase:无items/带items/默认值 - UpdateRecipeUseCase:改名称/多字段/替换items/空items/不存在 - DeleteRecipeUseCase:成功/不存在 - UseRecipeUseCase:premium/basic启用/功能禁用/不存在 - Commands:字段/默认值/dataclass ### 测试结果 ``` 4428 passed, 8 skipped ```
xiaoxia added this to the 代码质量清理专项 milestone 2026-07-24 10:54:18 +08:00
xiaoxia added 1 commit 2026-07-24 10:54:18 +08:00
test: P3-1 第34波单元测试
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 15s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m17s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m16s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m45s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 35s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 37s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 2m55s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m16s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 9s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 37s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m1s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 9m59s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m58s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m18s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 18s
5b709ff0dc
- title_library use case: 25个测试(列表/获取/创建/更新/删除/使用次数递增/智能选标题)
- recipe use case: 23个测试(列表/获取/创建/更新/删除/使用配方/命令对象)

合计+48
Collaborator

代码审查结果 - PR #812

⚠️ 问题(0个需要修改)

💡 建议(3个可选)

  1. tests/unit/test_recipe_use_cases.py 第273, 311, 324行:异常断言中使用了 match="..." 参数来精确匹配错误信息字符串(如 "not found" 或 "仅对基础版和高级版")。这使得测试对错误文案的修改(如拼写修正、国际化)非常脆弱,建议仅断言异常类型 NotFoundErrorFeatureDisabledError,以确保逻辑正确性而不依赖具体文本。
  2. tests/unit/test_recipe_use_cases.py TestUpdateRecipeUseCase类:在 test_update_items_replaces_oldtest_update_empty_items_list 测试中,由于 Command 对象已显式包含 items 字段,UseCase 理论上不应再调用 list_items 去数据库加载旧数据。建议增加 mock_repo.list_items.assert_not_called() 断言,以验证逻辑分支的正确性并确保性能(避免不必要的查询)。
  3. tests/unit/test/test_recipe_use_cases.py 文件权限:diff 显示文件模式从 100644 变更为 100755(添加可执行权限)。Python 测试文件通常通过 pytest 调用,不需要可读执行权限。建议保持默认的 100644 权限,以符合项目规范并避免 Git 仓库中的权限噪音。

格式检查通过 | 逻辑审查通过 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-07-24 03:19:46 | 模型:

## 代码审查结果 - PR #812 ### ⚠️ 问题(0个需要修改) ### 💡 建议(3个可选) 1. **tests/unit/test_recipe_use_cases.py 第273, 311, 324行**:异常断言中使用了 `match="..."` 参数来精确匹配错误信息字符串(如 "not found" 或 "仅对基础版和高级版")。这使得测试对错误文案的修改(如拼写修正、国际化)非常脆弱,建议仅断言异常类型 `NotFoundError` 和 `FeatureDisabledError`,以确保逻辑正确性而不依赖具体文本。 2. **tests/unit/test_recipe_use_cases.py TestUpdateRecipeUseCase类**:在 `test_update_items_replaces_old` 和 `test_update_empty_items_list` 测试中,由于 Command 对象已显式包含 `items` 字段,UseCase 理论上不应再调用 `list_items` 去数据库加载旧数据。建议增加 `mock_repo.list_items.assert_not_called()` 断言,以验证逻辑分支的正确性并确保性能(避免不必要的查询)。 3. **tests/unit/test/test_recipe_use_cases.py 文件权限**:diff 显示文件模式从 `100644` 变更为 `100755`(添加可执行权限)。Python 测试文件通常通过 pytest 调用,不需要可读执行权限。建议保持默认的 `100644` 权限,以符合项目规范并避免 Git 仓库中的权限噪音。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-24 03:19:46 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 862fe038aa into develop 2026-07-24 16:44:33 +08:00
xiaoxia deleted branch test/unit-test-wave34 2026-07-24 16:44:33 +08:00

🗑️ 预览环境已清理

PR #812 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #812 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.