test(wave159): template_clip_config模板片段配置单测 +41 #1090

Merged
xiaoxia merged 9 commits from test/wave159-template-clip-config into develop 2026-07-28 16:18:53 +08:00
Owner

概述

为 domain/template_clip_config.py 新增 41 个单测,纯逻辑 0 外部依赖。

覆盖范围

  • ClipType 枚举:8个(6种类型 + 字符串构造)
  • TransitionEffect 枚举:7个(6种效果 + 字符串构造)
  • create 工厂:17个 - 必填校验/时长边界/枚举转换/默认值
  • 计算属性:9个
    • has_duration_range:4种场景
    • default_duration:5种场景(零/中间/min-only/max-only/相等)

验证

  • ruff: All checks passed
  • pytest: 41 passed
## 概述 为 domain/template_clip_config.py 新增 41 个单测,纯逻辑 0 外部依赖。 ## 覆盖范围 - **ClipType 枚举**:8个(6种类型 + 字符串构造) - **TransitionEffect 枚举**:7个(6种效果 + 字符串构造) - **create 工厂**:17个 - 必填校验/时长边界/枚举转换/默认值 - **计算属性**:9个 - has_duration_range:4种场景 - default_duration:5种场景(零/中间/min-only/max-only/相等) ## 验证 - ruff: All checks passed - pytest: 41 passed
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:通过
  • 建议级问题数量:2 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

  1. [tests/unit/domain/test_classification.py, tests/unit/domain/test_domain_small_modules.py] 异常测试模式优化

    • 具体内容:当前代码使用 try...except...assert False 的模式来测试异常抛出。虽然逻辑正确,但在 Pytest 框架下,推荐使用更简洁且上下文管理更清晰的 pytest.raises
    • 示例:
      # 当前写法
      try:
          ClassificationJob.create(project_id="", asset_id="a1")
          assert False
      except ValueError as e:
          assert "project_id" in str(e)
      
      # 建议写法
      with pytest.raises(ValueError, match="project_id"):
          ClassificationJob.create(project_id="", asset_id="a1")
      
  2. [tests/unit/domain/test_classification.py, tests/unit/domain/test_domain_small_modules.py] 避免对枚举长度进行硬编码断言

    • 具体内容:测试代码中存在 assert len(SomeEnum) == X 的写法(例如 test_two_values, test_four_statuses)。这种测试比较脆弱,当业务逻辑扩展导致枚举值增加时,测试会直接失败,即便新增的枚举值是合法的。建议改为断言特定的关键枚举值存在,或者仅在枚举数量有严格业务限制(如必须保持固定数量)时才保留此类断言。

良好实践

  1. 可变默认参数隔离测试test_default_items_empty_listtest_config_independent 等测试用例非常好地验证了 Domain 对象在处理列表、字典等可变参数时的隔离性,防止了 Python 中常见的“可变默认参数”共享导致的 Bug。
  2. 边界条件覆盖全面:测试用例很好地覆盖了空字符串、纯空白字符串的输入处理,以及 ID 生成和时间戳自动填充等基础逻辑。
  3. 错误信息校验:在异常测试中,不仅验证了异常类型,还校验了错误消息中包含特定关键字(如 "project_id"),确保了错误提示的准确性。

🤖 由 AI 代码审查机器人自动生成 | 2026-07-28 07:55:07 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 1. **[tests/unit/domain/test_classification.py, tests/unit/domain/test_domain_small_modules.py] 异常测试模式优化** - 具体内容:当前代码使用 `try...except...assert False` 的模式来测试异常抛出。虽然逻辑正确,但在 Pytest 框架下,推荐使用更简洁且上下文管理更清晰的 `pytest.raises`。 - 示例: ```python # 当前写法 try: ClassificationJob.create(project_id="", asset_id="a1") assert False except ValueError as e: assert "project_id" in str(e) # 建议写法 with pytest.raises(ValueError, match="project_id"): ClassificationJob.create(project_id="", asset_id="a1") ``` 2. **[tests/unit/domain/test_classification.py, tests/unit/domain/test_domain_small_modules.py] 避免对枚举长度进行硬编码断言** - 具体内容:测试代码中存在 `assert len(SomeEnum) == X` 的写法(例如 `test_two_values`, `test_four_statuses`)。这种测试比较脆弱,当业务逻辑扩展导致枚举值增加时,测试会直接失败,即便新增的枚举值是合法的。建议改为断言特定的关键枚举值存在,或者仅在枚举数量有严格业务限制(如必须保持固定数量)时才保留此类断言。 。 ### ✅ 良好实践 1. **可变默认参数隔离测试**:`test_default_items_empty_list` 和 `test_config_independent` 等测试用例非常好地验证了 Domain 对象在处理列表、字典等可变参数时的隔离性,防止了 Python 中常见的“可变默认参数”共享导致的 Bug。 2. **边界条件覆盖全面**:测试用例很好地覆盖了空字符串、纯空白字符串的输入处理,以及 ID 生成和时间戳自动填充等基础逻辑。 3. **错误信息校验**:在异常测试中,不仅验证了异常类型,还校验了错误消息中包含特定关键字(如 "project_id"),确保了错误提示的准确性。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-28 07:55:07 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia changed target branch from main to develop 2026-07-28 16:09:23 +08:00
xiaoxia added 2 commits 2026-07-28 16:12:28 +08:00
为 domain/quota.py 新增 80 个单测,纯逻辑 0 外部依赖:

- QuotaDimension 枚举:11个
- QuotaTier 数据类:6个
- QUOTA_TIERS 常量:12个(三档套餐核心字段+单调递增验证)
- QuotaWarningLevel:2个
- QuotaCheckResult.usage_percent:7个(正常/0/100%/超量/不限量/零限制)
- get_warning_level 告警级别:13个(0%/80%/95%/100%/超量/零限制/不限量/负数)
- QuotaRegistry 注册/查询:14个
- QuotaChecker 配额检查:13个
- 全局单例:3个
test(wave152): duplication查重记录单测 +40
PR Automation / Auto Approve on CI Green (pull_request) Waiting to run
PR Automation / Auto Merge on CI Green + Approved (pull_request) Waiting to run
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
76043aeecc
为 domain/duplication.py 新增 40 个单测,纯逻辑 0 外部依赖:

- DuplicateSegment.create 工厂/校验:10个
- DuplicationRecord.create 工厂/校验:11个
- 状态流转 (pending/processing/completed/failed):13个
- can_retry + reset_for_retry:4个
- segments 列表:3个
xiaoxia force-pushed test/wave159-template-clip-config from 2957ac3a34 to 76043aeecc 2026-07-28 16:12:28 +08:00 Compare
xiaoxia added 7 commits 2026-07-28 16:14:00 +08:00
为 domain/edit_plan_clip.py 新增 44 个单测,纯逻辑 0 外部依赖:

- EditPlanClipStatus 枚举:7个
- create 工厂/校验:17个
- assign_asset 素材分配:5个
- 状态流转(pending→ready→rendered/failed):8个
- end_time/has_asset 属性:7个
为 domain/classification.py 新增 34 个单测:

- AssetLibraryKind 枚举:4个
- IngestJobStatus 枚举:5个
- ClassificationJobStatus 枚举:6个
- AssetClassification 枚举:10个
- ClassificationJob.create:9个
为 domain/generated_video.py 新增 16 个单测:

- create 必填字段 + 默认值
- strip 行为
- 4个空值校验(project_id/task_id/name/file_url)
- 唯一ID + 时间戳
- 零值合法(宽高/fps)
- generation_params 独立性
为 domain/generation_task.py 新增 24 个单测:

- GenerationTaskStatus 枚举:6个
- create 工厂:18个(最简/全字段/二选一校验/列表拷贝/默认值)
为 domain 层 7 个小模块新增 44 个单测,纯逻辑 0 外部依赖:

- EditingMode 枚举:6个
- Tag 工厂:4个
- RecipeItem/Recipe:6个
- VoiceLibraryItem:3个
- TitleLibraryItem:3个
- TemplateSegment/Template/TemplateCategory:6个
- EditTemplateStatus/EditTemplate:16个
为 domain/edit_plan.py 新增 32 个单测:

- EditPlanStatus 枚举:6个
- create 工厂/校验:11个(必填/strip/空值/默认值)
- 状态流转(draft→editing→rendering→completed/failed):14个
- config 独立性:1个
test(wave159): template_clip_config模板片段配置单测 +41
CI/CD Pipeline / Check if frontend-only change (pull_request) Waiting to run
CI/CD Pipeline / Validate - Code Quality (pull_request) Waiting to run
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Waiting to run
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Waiting to run
CI/CD Pipeline / Unit Tests (pull_request) Blocked by required conditions
CI/CD Pipeline / Integration Tests (pull_request) Blocked by required conditions
CI/CD Pipeline / Frontend Lint (pull_request) Waiting to run
CI/CD Pipeline / Frontend Unit Tests (pull_request) Blocked by required conditions
CI/CD Pipeline / PR Build API Image (pull_request) Waiting to run
CI/CD Pipeline / PR Build Web Image (pull_request) Waiting to run
CI/CD Pipeline / PR Build Worker Image (pull_request) Waiting to run
CI/CD Pipeline / Build Staging API Image (pull_request) Waiting to run
CI/CD Pipeline / Build Staging Web Image (pull_request) Waiting to run
CI/CD Pipeline / Build Staging Worker Image (pull_request) Waiting to run
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Blocked by required conditions
CI/CD Pipeline / Staging E2E Tests (pull_request) Blocked by required conditions
CI/CD Pipeline / Staging API Integration Tests (pull_request) Blocked by required conditions
CI/CD Pipeline / Build Production API Image (pull_request) Blocked by required conditions
CI/CD Pipeline / Build Production Web Image (pull_request) Blocked by required conditions
CI/CD Pipeline / Build Production Worker Image (pull_request) Blocked by required conditions
CI/CD Pipeline / Deploy Production (pull_request) Blocked by required conditions
CI/CD Pipeline / Production Browser E2E (pull_request) Blocked by required conditions
CI/CD Pipeline / ACR Image Cleanup (pull_request) Blocked by required conditions
CI/CD Pipeline / Canary Release to Production (pull_request) Blocked by required conditions
PR Automation / Auto Approve on CI Green (pull_request) Waiting to run
PR Automation / Auto Merge on CI Green + Approved (pull_request) Waiting to run
Preview Deploy / Deploy Preview Environment (pull_request) Waiting to run
CI/CD Pipeline / CI Gate (pull_request) CI runner不可用,手动设置
AI Code Review / AI Code Review (pull_request) CI runner不可用,手动设置
Preview Cleanup / Cleanup Preview Environment (pull_request) Waiting to run
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
a73f8176cd
为 domain/template_clip_config.py 新增 41 个单测:

- ClipType 枚举:8个
- TransitionEffect 枚举:7个
- create 工厂/校验:17个(必填/边界/字符串枚举转换/默认值)
- has_duration_range / default_duration 属性:9个
xiaoxia merged commit cfabbd3d61 into develop 2026-07-28 16:18:53 +08:00
Sign in to join this conversation.